Skip to content

Commit

Permalink
Allow declaration of empty Concepts.
Browse files Browse the repository at this point in the history
Concepts codes field is still required in the parser.

PiperOrigin-RevId: 650370250
  • Loading branch information
evan-gordon authored and copybara-github committed Jul 8, 2024
1 parent 33faab5 commit a5ad863
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
6 changes: 3 additions & 3 deletions interpreter/literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ func (i *interpreter) evalInstance(in *model.Instance) (result.Value, error) {
if err != nil {
return result.Value{}, err
}
var codes []result.Code
for _, codeObj := range codeObjs {
codes := make([]result.Code, len(codeObjs))
for i, codeObj := range codeObjs {
code, err := result.ToCode(codeObj)
if err != nil {
return result.Value{}, err
}
codes = append(codes, code)
codes[i] = code
}
cv.Codes = codes
}
Expand Down
6 changes: 6 additions & 0 deletions parser/expressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func TestParserExpressions_Errors(t *testing.T) {
errContains: []string{"unsupported type for maximumString"},
errCount: 1,
},
{
name: "Concept Instance codes not specified",
cql: "Concept{ }",
errContains: []string{"no viable alternative at input 'Concept{ }'"},
errCount: 1,
},
}

for _, test := range tests {
Expand Down
4 changes: 2 additions & 2 deletions result/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ func New(val any) (Value, error) {
}
return Value{runtimeType: types.CodeSystem, goValue: v}, nil
case Concept:
if len(v.Codes) == 0 {
return Value{}, fmt.Errorf("%v must have at least one %v", types.Concept, types.Code)
if v.Codes == nil {
return Value{}, fmt.Errorf("%v must specify the codes field", types.Concept)
}
return Value{runtimeType: types.Concept, goValue: v}, nil
case ValueSet:
Expand Down
4 changes: 2 additions & 2 deletions result/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,9 @@ func TestNew_Error(t *testing.T) {
wantErr: "System.CodeSystem must have an ID",
},
{
name: "Concept must have one code",
name: "Concept must specify codes",
input: Concept{},
wantErr: "System.Concept must have at least one System.Code",
wantErr: "System.Concept must specify the codes field",
},
{
name: "ValueSet missing ID",
Expand Down
7 changes: 7 additions & 0 deletions tests/enginetests/literal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,13 @@ func TestTupleAndInstanceSelector(t *testing.T) {
cql: "CodeSystem{id: 'id', version: '1.0' }",
wantResult: newOrFatal(t, result.CodeSystem{ID: "id", Version: "1.0"}),
},
{
name: "Concept Instance no codes",
cql: "Concept{codes: {} }",
wantResult: newOrFatal(t, result.Concept{
Codes: []result.Code{},
}),
},
{
name: "Concept Instance",
cql: "Concept{codes: {Code{code: 'foo', system: 'bar', version: '1.0' }}, display: 'display' }",
Expand Down
3 changes: 2 additions & 1 deletion tests/enginetests/operator_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,10 @@ func TestToConcept_Error(t *testing.T) {
wantError string
}{
{
// TODO: b/301606416 - This shouldn't be an error once we support null values in concepts.
name: "Concept must have a Code",
cql: "ToConcept(List<Code>{null})",
wantError: "System.Concept must have at least one System.Code",
wantError: "System.Concept must specify the codes field",
},
}

Expand Down

0 comments on commit a5ad863

Please sign in to comment.