use of org.hl7.fhir.r5.model.Expression in project quality-measure-and-cohort-service by Alvearie.
the class CqlTemporalTests method confirmCanFindEventWithExistenceOfThirdEvent.
@Test
public void confirmCanFindEventWithExistenceOfThirdEvent() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
Observation observation = new Observation();
DateTimeType observationEffective = new DateTimeType(new Date());
observationEffective.setYear(2015);
observationEffective.setMonth(0);
observationEffective.setDay(5);
observation.setEffective(observationEffective);
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_1, fhirConfig);
mockFhirResourceRetrieval("/Observation?subject=Patient%2F123&_format=json", getFhirParser(), observation, fhirConfig);
CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
String expression = "ObservationWithin30DaysOfCondition";
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test2", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
Map<String, Object> expected = new HashMap<>();
expected.put(expression, true);
Assert.assertEquals(expected, actual.getExpressionResults());
}
use of org.hl7.fhir.r5.model.Expression in project quality-measure-and-cohort-service by Alvearie.
the class CqlTemporalTests method anEventDoesFollow.
@Test
public void anEventDoesFollow() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_1, fhirConfig);
mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
String expression = "NotFollowedByCondition";
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test4", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
Map<String, Object> expected = new HashMap<>();
expected.put(expression, false);
Assert.assertEquals(expected, actual.getExpressionResults());
}
use of org.hl7.fhir.r5.model.Expression in project quality-measure-and-cohort-service by Alvearie.
the class PathCaptureContext method reportProperty.
public void reportProperty(Property elm) {
// Log guarding to prevent some of the parameter resolution logic from getting called unnecessarily
if (LOG.isTraceEnabled()) {
LOG.trace("Property {} source {}", elm.getPath(), elm.getSource() != null ? elm.getSource().getClass().getSimpleName() : null);
}
Set<QName> modelTypeNames = null;
if (elm.getScope() != null || elm.getSource() instanceof AliasRef) {
String aliasName = (elm.getScope() != null) ? elm.getScope() : ((AliasRef) elm.getSource()).getName();
QueryAliasContext aliasContext = getCurrentQueryContext().resolveAlias(aliasName);
if (aliasContext == null) {
aliasContext = getCurrentExpressionContext().resolveAlias(aliasName);
}
modelTypeNames = ElmUtils.getModelTypeNames(aliasContext.getAliasedQuerySource().getExpression());
} else if (elm.getSource() instanceof QueryLetRef) {
String letName = ((QueryLetRef) elm.getSource()).getName();
QueryLetContext letContext = getCurrentQueryContext().resolveLet(letName);
if (letContext == null) {
letContext = getCurrentExpressionContext().resolveLet(letName);
}
modelTypeNames = ElmUtils.getModelTypeNames(letContext.getLetClause().getExpression());
} else {
// There are times when the scope is null. I've noticed this particularly when referencing properties
// of another expression result
modelTypeNames = ElmUtils.getModelTypeNames(elm.getSource());
}
LOG.trace("ModelTypeNames {}", modelTypeNames);
if (modelTypeNames != null) {
for (QName qname : modelTypeNames) {
pathsByQName.computeIfAbsent(qname, key -> new HashSet<>()).add(elm.getPath());
}
}
}
use of org.hl7.fhir.r5.model.Expression in project org.hl7.fhir.core by hapifhir.
the class Expression50Test method testAdvisorExpressionConversion50_10.
@Test
@DisplayName("Test Advisor is used in Expression R5 -> DSTU3 conversion.")
public void testAdvisorExpressionConversion50_10() throws IOException {
InputStream r5_stream = this.getClass().getResourceAsStream("/questionnaire_with_expression_50.json");
org.hl7.fhir.r5.model.Questionnaire r5_input = (org.hl7.fhir.r5.model.Questionnaire) new org.hl7.fhir.r5.formats.JsonParser().parse(r5_stream);
InputStream r2_stream = this.getClass().getResourceAsStream("/questionnaire_with_converted_expression_40_10.json");
org.hl7.fhir.dstu2.model.Questionnaire r2_expected_output = (org.hl7.fhir.dstu2.model.Questionnaire) new org.hl7.fhir.dstu2.formats.JsonParser().parse(r2_stream);
org.hl7.fhir.dstu2.model.Questionnaire convertedDstu2Questionnaire = (org.hl7.fhir.dstu2.model.Questionnaire) VersionConvertorFactory_10_50.convertResource(r5_input, new ExpressionAdvisor50());
org.hl7.fhir.dstu2.formats.JsonParser dstu2_parser = new org.hl7.fhir.dstu2.formats.JsonParser();
String composeString1 = dstu2_parser.composeString(convertedDstu2Questionnaire);
String composeString2 = dstu2_parser.composeString(r2_expected_output);
System.out.println("Expected out ->\n" + composeString2 + "\n\nActual out ->\n" + composeString1);
Assertions.assertTrue(r2_expected_output.equalsDeep(convertedDstu2Questionnaire));
}
use of org.hl7.fhir.r5.model.Expression in project org.hl7.fhir.core by hapifhir.
the class ExpressionAdvisor50 method handleExtension.
public void handleExtension(@Nonnull String path, @Nonnull org.hl7.fhir.r5.model.Extension src, @Nonnull org.hl7.fhir.dstu2.model.Extension tgt) {
if (src.getValue() instanceof org.hl7.fhir.r5.model.Expression) {
StringType type = new StringType();
if (src.getValue() == null) {
throw new NullPointerException("null cannot be cast to non-null type org.hl7.fhir.r5.model.Expression");
} else {
type.setValueAsString(((Expression) src.getValue()).getExpression());
tgt.setValue(type);
if (src.hasUrlElement()) {
tgt.setUrlElement(Uri10_50.convertUri(src.getUrlElement()));
}
}
} else {
throw new FHIRException("Unknown extension type passed in to custom convertor method.");
}
}
Aggregations