|
3 | 3 | import static org.cqframework.cql.cql2elm.TestUtils.visitFile;
|
4 | 4 | import static org.cqframework.cql.cql2elm.TestUtils.visitFileLibrary;
|
5 | 5 | import static org.cqframework.cql.cql2elm.matchers.QuickDataType.quickDataType;
|
| 6 | +import static org.hamcrest.CoreMatchers.notNullValue; |
6 | 7 | import static org.hamcrest.MatcherAssert.assertThat;
|
7 | 8 | import static org.hamcrest.Matchers.*;
|
8 | 9 |
|
|
16 | 17 | import org.cqframework.cql.cql2elm.LibraryBuilder;
|
17 | 18 | import org.cqframework.cql.cql2elm.TestUtils;
|
18 | 19 | import org.cqframework.cql.cql2elm.model.CompiledLibrary;
|
19 |
| -import org.hl7.cql.model.ChoiceType; |
20 |
| -import org.hl7.cql.model.ClassType; |
21 |
| -import org.hl7.cql.model.DataType; |
22 |
| -import org.hl7.cql.model.NamespaceInfo; |
| 20 | +import org.hl7.cql.model.*; |
23 | 21 | import org.hl7.elm.r1.*;
|
24 | 22 | import org.junit.jupiter.api.Test;
|
25 | 23 |
|
@@ -907,4 +905,105 @@ void overloadForwardOutput() throws IOException {
|
907 | 905 | String.format(
|
908 | 906 | "You used a string literal: [Encounter] here that matches an identifier in scope: [Encounter]. Did you mean to use the identifier instead?")));
|
909 | 907 | }
|
| 908 | + |
| 909 | + @Test |
| 910 | + void medicationRequest() throws IOException { |
| 911 | + CqlTranslator translator = TestUtils.runSemanticTest("fhir/r401/TestMedicationRequest.cql", 0); |
| 912 | + Library library = translator.toELM(); |
| 913 | + Map<String, ExpressionDef> defs = new HashMap<>(); |
| 914 | + |
| 915 | + if (library.getStatements() != null) { |
| 916 | + for (ExpressionDef def : library.getStatements().getDef()) { |
| 917 | + defs.put(def.getName(), def); |
| 918 | + } |
| 919 | + } |
| 920 | + |
| 921 | + ExpressionDef def = defs.get("Antithrombotic Therapy at Discharge"); |
| 922 | + assertThat(def, notNullValue()); |
| 923 | + assertThat(def.getExpression(), instanceOf(Query.class)); |
| 924 | + Query q = (Query) def.getExpression(); |
| 925 | + assertThat(q.getSource().size(), is(1)); |
| 926 | + assertThat(q.getSource().get(0).getExpression(), instanceOf(Retrieve.class)); |
| 927 | + Retrieve r = (Retrieve) q.getSource().get(0).getExpression(); |
| 928 | + assertThat(r.getTemplateId(), is("http://hl7.org/fhir/StructureDefinition/MedicationRequest")); |
| 929 | + assertThat(r.getCodeProperty(), is("medication")); |
| 930 | + assertThat(r.getCodeComparator(), is("in")); |
| 931 | + assertThat(r.getCodes(), instanceOf(ValueSetRef.class)); |
| 932 | + ValueSetRef vsr = (ValueSetRef) r.getCodes(); |
| 933 | + assertThat(vsr.getName(), is("Antithrombotic Therapy")); |
| 934 | + |
| 935 | + def = defs.get("Antithrombotic Therapy at Discharge (2)"); |
| 936 | + assertThat(def, notNullValue()); |
| 937 | + assertThat(def.getExpression(), instanceOf(Union.class)); |
| 938 | + Union u = (Union) def.getExpression(); |
| 939 | + assertThat(u.getOperand().size(), is(2)); |
| 940 | + assertThat(u.getOperand().get(0), instanceOf(Retrieve.class)); |
| 941 | + r = (Retrieve) u.getOperand().get(0); |
| 942 | + assertThat(r.getTemplateId(), is("http://hl7.org/fhir/StructureDefinition/MedicationRequest")); |
| 943 | + assertThat(r.getCodeProperty(), is("medication")); |
| 944 | + assertThat(r.getCodeComparator(), is("in")); |
| 945 | + assertThat(r.getCodes(), instanceOf(ValueSetRef.class)); |
| 946 | + vsr = (ValueSetRef) r.getCodes(); |
| 947 | + assertThat(vsr.getName(), is("Antithrombotic Therapy")); |
| 948 | + |
| 949 | + assertThat(u.getOperand().get(1), instanceOf(Query.class)); |
| 950 | + q = (Query) u.getOperand().get(1); |
| 951 | + assertThat(q.getSource().size(), is(1)); |
| 952 | + assertThat(q.getSource().get(0).getExpression(), instanceOf(Retrieve.class)); |
| 953 | + r = (Retrieve) q.getSource().get(0).getExpression(); |
| 954 | + assertThat(r.getTemplateId(), is("http://hl7.org/fhir/StructureDefinition/MedicationRequest")); |
| 955 | + assertThat(r.getCodeProperty() == null, is(true)); |
| 956 | + assertThat(r.getCodes() == null, is(true)); |
| 957 | + assertThat(q.getRelationship(), notNullValue()); |
| 958 | + assertThat(q.getRelationship().size(), is(1)); |
| 959 | + assertThat(q.getRelationship().get(0), instanceOf(With.class)); |
| 960 | + With w = (With) q.getRelationship().get(0); |
| 961 | + assertThat(w.getExpression(), instanceOf(Retrieve.class)); |
| 962 | + r = (Retrieve) w.getExpression(); |
| 963 | + assertThat(r.getTemplateId(), is("http://hl7.org/fhir/StructureDefinition/Medication")); |
| 964 | + assertThat(r.getCodeProperty() == null, is(true)); |
| 965 | + assertThat(r.getCodes() == null, is(true)); |
| 966 | + assertThat(r.getResultType(), instanceOf(ListType.class)); |
| 967 | + assertThat(((ListType) r.getResultType()).getElementType(), instanceOf(ClassType.class)); |
| 968 | + assertThat(((ClassType) ((ListType) r.getResultType()).getElementType()).getName(), is("FHIR.Medication")); |
| 969 | + assertThat(w.getSuchThat(), instanceOf(And.class)); |
| 970 | + And a = (And) w.getSuchThat(); |
| 971 | + assertThat(a.getOperand().get(0), instanceOf(Equal.class)); |
| 972 | + Equal eq = (Equal) a.getOperand().get(0); |
| 973 | + assertThat(eq.getOperand().get(0), instanceOf(FunctionRef.class)); |
| 974 | + FunctionRef fr = (FunctionRef) eq.getOperand().get(0); |
| 975 | + assertThat(fr.getLibraryName(), is("FHIRHelpers")); |
| 976 | + assertThat(fr.getName(), is("ToString")); |
| 977 | + assertThat(fr.getOperand().size(), is(1)); |
| 978 | + assertThat(fr.getOperand().get(0), instanceOf(Property.class)); |
| 979 | + Property p = (Property) fr.getOperand().get(0); |
| 980 | + assertThat(p.getScope(), is("M")); |
| 981 | + assertThat(p.getPath(), is("id")); |
| 982 | + assertThat(eq.getOperand().get(1), instanceOf(Last.class)); |
| 983 | + Last l = (Last) eq.getOperand().get(1); |
| 984 | + assertThat(l.getSource(), instanceOf(Split.class)); |
| 985 | + Split s = (Split) l.getSource(); |
| 986 | + assertThat(s.getStringToSplit(), instanceOf(FunctionRef.class)); |
| 987 | + fr = (FunctionRef) s.getStringToSplit(); |
| 988 | + assertThat(fr.getLibraryName(), is("FHIRHelpers")); |
| 989 | + assertThat(fr.getName(), is("ToString")); |
| 990 | + assertThat(fr.getOperand().size(), is(1)); |
| 991 | + assertThat(fr.getOperand().get(0), instanceOf(Property.class)); |
| 992 | + p = (Property) fr.getOperand().get(0); |
| 993 | + assertThat(p.getScope(), is("MR")); |
| 994 | + assertThat(p.getPath(), is("medication.reference")); |
| 995 | + // assertThat(s.getSeparator(), is("/")); |
| 996 | + assertThat(a.getOperand().get(1), instanceOf(InValueSet.class)); |
| 997 | + InValueSet ivs = (InValueSet) a.getOperand().get(1); |
| 998 | + assertThat(ivs.getValueset().getName(), is("Antithrombotic Therapy")); |
| 999 | + assertThat(ivs.getCode(), instanceOf(FunctionRef.class)); |
| 1000 | + fr = (FunctionRef) ivs.getCode(); |
| 1001 | + assertThat(fr.getLibraryName(), is("FHIRHelpers")); |
| 1002 | + assertThat(fr.getName(), is("ToConcept")); |
| 1003 | + assertThat(fr.getOperand().size(), is(1)); |
| 1004 | + assertThat(fr.getOperand().get(0), instanceOf(Property.class)); |
| 1005 | + p = (Property) fr.getOperand().get(0); |
| 1006 | + assertThat(p.getScope(), is("M")); |
| 1007 | + assertThat(p.getPath(), is("code")); |
| 1008 | + } |
910 | 1009 | }
|
0 commit comments