use of org.hl7.elm.r1.DateTime in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluatorTest method in_initial_population_when_engine_run_in_utc__engine_defaults_to_utc.
@Test
public void in_initial_population_when_engine_run_in_utc__engine_defaults_to_utc() throws Exception {
CapabilityStatement metadata = getCapabilityStatement();
mockFhirResourceRetrieval("/metadata?_format=json", metadata);
Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
mockFhirResourceRetrieval(patient);
// Test CQL written to pass when engine run with a timezone of UTC
// and should fail otherwise
Library library = mockLibraryRetrieval("TestDatetimeDefaultTimezones", DEFAULT_VERSION, "cql/fhir-measure/test-datetime-default-timezones.cql", "text/cql");
Measure measure = getCohortMeasure("CohortMeasureName", library, INITIAL_POPULATION);
mockFhirResourceRetrieval(measure);
MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), null, new MeasureEvidenceOptions(false, DefineReturnOptions.BOOLEAN));
assertNotNull(report);
report.getExtension().stream().filter(x -> x.getUrl().equals(CDMConstants.EVIDENCE_URL)).forEach(x -> validateBooleanEvidence(x, true));
}
use of org.hl7.elm.r1.DateTime in project quality-measure-and-cohort-service by Alvearie.
the class CQLToFHIRMeasureReportHelper method getFhirTypeForInterval.
private static IBaseDatatype getFhirTypeForInterval(Interval interval) {
Object low = interval.getLow();
Object high = interval.getHigh();
if (low instanceof DateTime) {
// Handle DateTime conversion to force UTC timezone
Period period = new Period();
period.setStartElement(createDateTimeType((DateTime) low));
period.setEndElement(createDateTimeType((DateTime) high));
return period;
} else if (low instanceof Quantity) {
return converter.toFhirRange(interval);
} else {
logger.warn("Support not implemented for Interval parameters of type {} on a MeasureReport", low.getClass());
return null;
}
}
use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.
the class Questionnaire10_50 method convertQuestionnaireQuestionType.
public static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType> convertQuestionnaireQuestionType(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat> src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemTypeEnumFactory());
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
tgt.addExtension(VersionConvertorConstants.EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL, new CodeType(src.getValueAsString()));
switch(src.getValue()) {
case BOOLEAN:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.BOOLEAN);
break;
case DECIMAL:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DECIMAL);
break;
case INTEGER:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.INTEGER);
break;
case DATE:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DATE);
break;
case DATETIME:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DATETIME);
break;
case INSTANT:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DATETIME);
break;
case TIME:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.TIME);
break;
case STRING:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.STRING);
break;
case TEXT:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.TEXT);
break;
case URL:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.URL);
break;
case CHOICE:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.CODING);
break;
case OPENCHOICE:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.CODING);
break;
case ATTACHMENT:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.ATTACHMENT);
break;
case REFERENCE:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.REFERENCE);
break;
case QUANTITY:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.QUANTITY);
break;
default:
tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.NULL);
break;
}
return tgt;
}
use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method opLessOrEqual.
private List<Base> opLessOrEqual(List<Base> left, List<Base> right) throws PathEngineException {
if (left.size() == 1 && right.size() == 1 && left.get(0).isPrimitive() && right.get(0).isPrimitive()) {
Base l = left.get(0);
Base r = right.get(0);
if (l.hasType("string") && r.hasType("string"))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) <= 0);
else if ((l.hasType("integer", "decimal")) && (r.hasType("integer", "decimal")))
return makeBoolean(new Double(l.primitiveValue()) <= new Double(r.primitiveValue()));
else if ((l.hasType("date", "dateTime", "instant")) && (r.hasType("date", "dateTime", "instant")))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) <= 0);
else if ((l.hasType("time")) && (r.hasType("time")))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) <= 0);
} else if (left.size() == 1 && right.size() == 1 && left.get(0).fhirType().equals("Quantity") && right.get(0).fhirType().equals("Quantity")) {
List<Base> lUnits = left.get(0).listChildrenByName("unit");
String lunit = lUnits.size() == 1 ? lUnits.get(0).primitiveValue() : null;
List<Base> rUnits = right.get(0).listChildrenByName("unit");
String runit = rUnits.size() == 1 ? rUnits.get(0).primitiveValue() : null;
if ((lunit == null && runit == null) || lunit.equals(runit)) {
return opLessOrEqual(left.get(0).listChildrenByName("value"), right.get(0).listChildrenByName("value"));
} else {
throw new PathEngineException("Canonical Comparison isn't done yet");
}
}
return new ArrayList<Base>();
}
use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method opGreater.
private List<Base> opGreater(List<Base> left, List<Base> right) throws PathEngineException {
if (left.size() == 1 && right.size() == 1 && left.get(0).isPrimitive() && right.get(0).isPrimitive()) {
Base l = left.get(0);
Base r = right.get(0);
if (l.hasType("string") && r.hasType("string"))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) > 0);
else if ((l.hasType("integer", "decimal")) && (r.hasType("integer", "decimal")))
return makeBoolean(new Double(l.primitiveValue()) > new Double(r.primitiveValue()));
else if ((l.hasType("date", "dateTime", "instant")) && (r.hasType("date", "dateTime", "instant")))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) > 0);
else if ((l.hasType("time")) && (r.hasType("time")))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) > 0);
} else if (left.size() == 1 && right.size() == 1 && left.get(0).fhirType().equals("Quantity") && right.get(0).fhirType().equals("Quantity")) {
List<Base> lUnit = left.get(0).listChildrenByName("unit");
List<Base> rUnit = right.get(0).listChildrenByName("unit");
if (Base.compareDeep(lUnit, rUnit, true)) {
return opGreater(left.get(0).listChildrenByName("value"), right.get(0).listChildrenByName("value"));
} else {
throw new PathEngineException("Canonical Comparison isn't done yet");
}
}
return new ArrayList<Base>();
}
Aggregations