Java Code Examples for org.opencds.cqf.cql.execution.Context#enterContext()

The following examples show how to use org.opencds.cqf.cql.execution.Context#enterContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpressionDefEvaluator.java    From cql_engine with Apache License 2.0 7 votes vote down vote up
@Override
protected Object internalEvaluate(Context context) {
    if (this.getContext() != null) {
        context.enterContext(this.getContext());
    }
    try {
        if (context.isExpressionCachingEnabled() && context.isExpressionInCache(this.getName())) {
            return context.getExpressionResultFromCache(this.getName());
        }

        Object result = this.getExpression().evaluate(context);

        if (context.isExpressionCachingEnabled() && !context.isExpressionInCache(this.getName())) {
            context.addExpressionToCache(this.getName(), result);
        }

        return result;
    }
    finally {
        if (this.getContext() != null) {
            context.exitContext();
        }
    }
}
 
Example 2
Source File: TestFhirDataProviderDstu3.java    From cql_engine with Apache License 2.0 4 votes vote down vote up
public void testContained()
  {
      String patient = "{  \n" +
              "        \"resourceType\":\"Patient\",\n" +
              "        \"id\":\"81ee6581-02b9-44de-b026-7401bf36643a\",\n" +
              "        \"meta\":{  \n" +
              "          \"profile\":[  \n" +
              "            \"http://hl7.org/fhir/profiles/Patient\"\n" +
              "          ]\n" +
              "        },\n" +
              "        \"birthDate\":\"2012-01-01\"\n" +
              "      }";

      fhirClient.update().resource(patient).withId("81ee6581-02b9-44de-b026-7401bf36643a").execute();

      String condition = "{  \n" +
              "        \"resourceType\":\"Condition\",\n" +
              "        \"id\":\"77d90968-1965-4574-aa34-19d7d1483d8a\",\n" +
              "        \"contained\":[  \n" +
              "          {  \n" +
              "            \"resourceType\":\"Provenance\",\n" +
              "            \"id\":\"c76ceb3b-ff93-4d4a-ae1f-83b78ce39228\",\n" +
              "            \"target\":[  \n" +
              "              {  \n" +
              "                \"reference\":\"Condition/77d90968-1965-4574-aa34-19d7d1483d8a\"\n" +
              "              }\n" +
              "            ],\n" +
              "            \"entity\":[  \n" +
              "              {  \n" +
              "                \"role\":\"source\",\n" +
              "                \"whatReference\":{  \n" +
              "                  \"reference\":\"Claim/920013f1-da9b-42ec-89ec-b50069a7aa5c\"\n" +
              "                }\n" +
              "              }\n" +
              "            ]\n" +
              "          }\n" +
              "        ],\n" +
              "        \"clinicalStatus\":\"active\",\n" +
              "        \"verificationStatus\":\"confirmed\",\n" +
              "        \"code\":{  \n" +
              "          \"coding\":[  \n" +
              "            {  \n" +
              "              \"system\":\"ICD-10-CM\",\n" +
              "              \"code\":\"Z00.00\",\n" +
              "              \"display\":\"HEDIS2019_Ambulatory_Visits_ValueSets\"\n" +
              "            }\n" +
              "          ]\n" +
              "        },\n" +
              "        \"subject\":{  \n" +
              "          \"reference\":\"Patient/81ee6581-02b9-44de-b026-7401bf36643a\"\n" +
              "        },\n" +
              "        \"onsetDateTime\":\"2018-01-01\", \n" +
              "        \"evidence\":[   \n" +
              "            {  \n" +
              "               \"detail\":{   \n" +
              "                  \"reference\": \"#c76ceb3b-ff93-4d4a-ae1f-83b78ce39228\"   \n" +
              "               }  \n" +
              "            }  \n" +
              "         ]  \n" +
              "      }";

      fhirClient.update().resource(condition).withId("77d90968-1965-4574-aa34-19d7d1483d8a").execute();

      Context context = new Context(library);

dstu3RetrieveProvider.setTerminologyProvider(new Dstu3FhirTerminologyProvider().setEndpoint("http://measure.eval.kanvix.com/cqf-ruler/baseDstu3", false));
      //dstu3Provider.setTerminologyProvider(new FhirTerminologyProvider().setEndpoint("http://measure.eval.kanvix.com/cqf-ruler/baseDstu3", false));
      context.registerDataProvider("http://hl7.org/fhir", dstu3Provider);
      context.enterContext("Patient");
      context.setContextValue("Patient", "81ee6581-02b9-44de-b026-7401bf36643a");

      Object result = context.resolveExpressionRef("GetProvenance").getExpression().evaluate(context);
      Assert.assertTrue(result instanceof List && ((List) result).size() == 1);
  }