correctly handle query for token with system but no code.
This commit is contained in:
parent
f3b1c7e283
commit
595541f3a0
|
@ -417,12 +417,8 @@ func ProcessSearchParameterValue(searchParameter SearchParameter, searchValueWit
|
|||
}
|
||||
} else if len(searchParameterValueParts) == 2 {
|
||||
//if theres 2 parts, first is always system, second is always the code. Either one may be emty. If both are emty this is invalid.
|
||||
if len(searchParameterValueParts[0]) > 0 {
|
||||
searchParameterValue.SecondaryValues[searchParameter.Name+"System"] = searchParameterValueParts[0]
|
||||
}
|
||||
if len(searchParameterValueParts[1]) > 0 {
|
||||
searchParameterValue.Value = searchParameterValueParts[1]
|
||||
}
|
||||
searchParameterValue.SecondaryValues[searchParameter.Name+"System"] = searchParameterValueParts[0]
|
||||
searchParameterValue.Value = searchParameterValueParts[1]
|
||||
if len(searchParameterValueParts[0]) == 0 && len(searchParameterValueParts[1]) == 0 {
|
||||
return searchParameterValue, fmt.Errorf("invalid search parameter value: (%s=%s)", searchParameter.Name, searchParameterValue.Value)
|
||||
}
|
||||
|
@ -571,7 +567,10 @@ func SearchCodeToWhereClause(searchParam SearchParameter, searchParamValue Searc
|
|||
//TODO: support ":text" modifier
|
||||
|
||||
//setup the clause
|
||||
clause := fmt.Sprintf("%sJson.value ->> '$.code' = @%s", searchParam.Name, NamedParameterWithSuffix(searchParam.Name, namedParameterSuffix))
|
||||
clause := []string{}
|
||||
if searchParamValue.Value.(string) != "" {
|
||||
clause = append(clause, fmt.Sprintf("%sJson.value ->> '$.code' = @%s", searchParam.Name, NamedParameterWithSuffix(searchParam.Name, namedParameterSuffix)))
|
||||
}
|
||||
|
||||
//append the code and/or system clauses (if required)
|
||||
//this looks like unnecessary code, however its required to ensure consistent tests
|
||||
|
@ -580,10 +579,10 @@ func SearchCodeToWhereClause(searchParam SearchParameter, searchParamValue Searc
|
|||
for _, k := range allowedSecondaryKeys {
|
||||
namedParameterKey := fmt.Sprintf("%s%s", searchParam.Name, strings.Title(k))
|
||||
if _, ok := searchParamValue.SecondaryValues[namedParameterKey]; ok {
|
||||
clause += fmt.Sprintf(` AND %sJson.value ->> '$.%s' = @%s`, searchParam.Name, k, NamedParameterWithSuffix(namedParameterKey, namedParameterSuffix))
|
||||
clause = append(clause, fmt.Sprintf(`%sJson.value ->> '$.%s' = @%s`, searchParam.Name, k, NamedParameterWithSuffix(namedParameterKey, namedParameterSuffix)))
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("(%s)", clause), searchClauseNamedParams, nil
|
||||
return fmt.Sprintf("(%s)", strings.Join(clause, " AND ")), searchClauseNamedParams, nil
|
||||
|
||||
case SearchParameterTypeKeyword:
|
||||
//setup the clause
|
||||
|
|
|
@ -103,6 +103,8 @@ func TestProcessSearchParameterValue(t *testing.T) {
|
|||
{SearchParameter{Type: "token", Name: "identifier", Modifier: "otype"}, "http://terminology.hl7.org/CodeSystem/v2-0203|MR|446053", SearchParameterValue{Value: "MR|446053", Prefix: "", SecondaryValues: map[string]interface{}{"identifierSystem": "http://terminology.hl7.org/CodeSystem/v2-0203"}}, false},
|
||||
{SearchParameter{Type: "token", Name: "code", Modifier: ""}, "|", SearchParameterValue{}, true}, //empty value should throw an error
|
||||
{SearchParameter{Type: "token", Name: "code", Modifier: ""}, "", SearchParameterValue{}, true}, //empty value should throw an error
|
||||
{SearchParameter{Type: "token", Name: "code", Modifier: ""}, "http://acme.org/conditions/codes|", SearchParameterValue{Value: "", Prefix: "", SecondaryValues: map[string]interface{}{"codeSystem": "http://acme.org/conditions/codes"}}, false},
|
||||
{SearchParameter{Type: "token", Name: "code", Modifier: ""}, "|807-1", SearchParameterValue{Value: "807-1", Prefix: "", SecondaryValues: map[string]interface{}{"codeSystem": ""}}, false},
|
||||
|
||||
{SearchParameter{Type: "quantity", Name: "valueQuantity", Modifier: ""}, "5.4|http://unitsofmeasure.org|mg", SearchParameterValue{Value: float64(5.4), Prefix: "", SecondaryValues: map[string]interface{}{"valueQuantitySystem": "http://unitsofmeasure.org", "valueQuantityCode": "mg"}}, false},
|
||||
{SearchParameter{Type: "quantity", Name: "valueQuantity", Modifier: ""}, "5.40e-3|http://unitsofmeasure.org|g", SearchParameterValue{Value: float64(0.0054), Prefix: "", SecondaryValues: map[string]interface{}{"valueQuantitySystem": "http://unitsofmeasure.org", "valueQuantityCode": "g"}}, false},
|
||||
|
|
|
@ -39,9 +39,11 @@ export class ReportLabsComponent implements OnInit {
|
|||
})
|
||||
|
||||
this.fastenApi.queryResources({
|
||||
select: ["*"],
|
||||
select: [],
|
||||
from: "Observation",
|
||||
where: {},
|
||||
where: {
|
||||
"code": "http://loinc.org|,urn:oid:2.16.840.1.113883.6.1|",
|
||||
},
|
||||
aggregations: {
|
||||
order_by: {
|
||||
field: "sort_date",
|
||||
|
|
Loading…
Reference in New Issue