use of org.hl7.fhir.r4b.model.DataRequirement in project org.hl7.fhir.core by hapifhir.
the class ProfileDrivenRenderer method renderLeaf.
private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode parent, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path, int indent) throws FHIRException, UnsupportedEncodingException, IOException, EOperationOutcome {
if (ew == null)
return;
Base e = ew.getBase();
if (e instanceof StringType)
x.addText(((StringType) e).getValue());
else if (e instanceof CodeType)
x.addText(((CodeType) e).getValue());
else if (e instanceof IdType)
x.addText(((IdType) e).getValue());
else if (e instanceof Extension)
return;
else if (e instanceof InstantType)
x.addText(((InstantType) e).toHumanDisplay());
else if (e instanceof DateTimeType) {
renderDateTime(x, e);
} else if (e instanceof Base64BinaryType)
x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
else if (e instanceof org.hl7.fhir.r5.model.DateType) {
org.hl7.fhir.r5.model.DateType dt = ((org.hl7.fhir.r5.model.DateType) e);
renderDate(x, dt);
} else if (e instanceof Enumeration) {
Object ev = ((Enumeration<?>) e).getValue();
// todo: look up a display name if there is one
x.addText(ev == null ? "" : ev.toString());
} else if (e instanceof BooleanType) {
x.addText(((BooleanType) e).getValue().toString());
} else if (e instanceof CodeableConcept) {
renderCodeableConcept(x, (CodeableConcept) e, showCodeDetails);
} else if (e instanceof Coding) {
renderCoding(x, (Coding) e, showCodeDetails);
} else if (e instanceof CodeableReference) {
renderCodeableReference(x, (CodeableReference) e, showCodeDetails);
} else if (e instanceof Annotation) {
renderAnnotation(x, (Annotation) e);
} else if (e instanceof Identifier) {
renderIdentifier(x, (Identifier) e);
} else if (e instanceof org.hl7.fhir.r5.model.IntegerType) {
if (((org.hl7.fhir.r5.model.IntegerType) e).hasValue()) {
x.addText(Integer.toString(((org.hl7.fhir.r5.model.IntegerType) e).getValue()));
} else {
x.addText("??");
}
} else if (e instanceof org.hl7.fhir.r5.model.Integer64Type) {
if (((org.hl7.fhir.r5.model.Integer64Type) e).hasValue()) {
x.addText(Long.toString(((org.hl7.fhir.r5.model.Integer64Type) e).getValue()));
} else {
x.addText("??");
}
} else if (e instanceof org.hl7.fhir.r5.model.DecimalType) {
x.addText(((org.hl7.fhir.r5.model.DecimalType) e).getValue().toString());
} else if (e instanceof HumanName) {
renderHumanName(x, (HumanName) e);
} else if (e instanceof SampledData) {
renderSampledData(x, (SampledData) e);
} else if (e instanceof Address) {
renderAddress(x, (Address) e);
} else if (e instanceof ContactPoint) {
renderContactPoint(x, (ContactPoint) e);
} else if (e instanceof Expression) {
renderExpression(x, (Expression) e);
} else if (e instanceof Money) {
renderMoney(x, (Money) e);
} else if (e instanceof ContactDetail) {
ContactDetail cd = (ContactDetail) e;
if (cd.hasName()) {
x.tx(cd.getName() + ": ");
}
boolean first = true;
for (ContactPoint c : cd.getTelecom()) {
if (first)
first = false;
else
x.tx(",");
renderContactPoint(x, c);
}
} else if (e instanceof UriType) {
renderUri(x, (UriType) e, defn.getPath(), rcontext != null && rcontext.getResourceResource() != null ? rcontext.getResourceResource().getId() : null);
} else if (e instanceof Timing) {
renderTiming(x, (Timing) e);
} else if (e instanceof Range) {
renderRange(x, (Range) e);
} else if (e instanceof Quantity) {
renderQuantity(x, (Quantity) e, showCodeDetails);
} else if (e instanceof Ratio) {
renderQuantity(x, ((Ratio) e).getNumerator(), showCodeDetails);
x.tx("/");
renderQuantity(x, ((Ratio) e).getDenominator(), showCodeDetails);
} else if (e instanceof Period) {
Period p = (Period) e;
renderPeriod(x, p);
} else if (e instanceof Reference) {
Reference r = (Reference) e;
if (r.getReference() != null && r.getReference().contains("#")) {
if (containedIds.contains(r.getReference().substring(1))) {
x.ah(r.getReference()).tx("See " + r.getReference());
} else {
// in this case, we render the resource in line
ResourceWrapper rw = null;
for (ResourceWrapper t : res.getContained()) {
if (r.getReference().substring(1).equals(t.getId())) {
rw = t;
}
}
if (rw == null) {
renderReference(res, x, r);
} else {
x.an(rw.getId());
ResourceRenderer rr = RendererFactory.factory(rw, context.copy().setAddGeneratedNarrativeHeader(false));
rr.render(parent.blockquote(), rw);
}
}
} else {
renderReference(res, x, r);
}
} else if (e instanceof Resource) {
return;
} else if (e instanceof DataRequirement) {
DataRequirement p = (DataRequirement) e;
renderDataRequirement(x, p);
} else if (e instanceof PrimitiveType) {
x.tx(((PrimitiveType) e).primitiveValue());
} else if (e instanceof ElementDefinition) {
x.tx("todo-bundle");
} else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
throw new NotImplementedException("type " + e.getClass().getName() + " not handled - should not be here");
}
}
use of org.hl7.fhir.r4b.model.DataRequirement in project eCRNow by drajer-health.
the class PlanDefinitionProcessor method processTriggerDefinitions.
private void processTriggerDefinitions(List<TriggerDefinition> tdlist, AbstractAction act) {
if (tdlist != null && !tdlist.isEmpty()) {
for (TriggerDefinition triggerDefinition : tdlist) {
if (triggerDefinition.getType() != TriggerType.NAMEDEVENT && triggerDefinition.getType() != TriggerType.PERIODIC && triggerDefinition.hasData()) {
logger.info(" Identified Data Trigger for Act {}", act.getActionId());
List<DataRequirement> dr = triggerDefinition.getData();
for (DataRequirement d : dr) {
// Create ActionData object
ActionData ad = new ActionData();
ad.setTriggerType(triggerDefinition.getType());
ad.setFhirDataType(FHIRAllTypes.valueOf(d.getType().toUpperCase()));
if (d.hasProfile())
ad.setProfiles(d.getProfile());
if (d.hasCodeFilter()) {
DataRequirementCodeFilterComponent cf = d.getCodeFilterFirstRep();
if (cf.hasPath()) {
ad.setPath(d.getType() + "." + cf.getPath());
logger.info(" Evaluation Path = {}", ad.getPath());
}
if (cf.hasValueSet())
ad.setValueSet(cf.getValueSetElement());
}
act.addActionData(ad);
}
} else if (triggerDefinition.getType() == TriggerType.PERIODIC) {
if (triggerDefinition.hasTimingTiming()) {
Timing t = triggerDefinition.getTimingTiming();
if (t.hasRepeat()) {
TimingSchedule ts = getTimingSchedule(t, triggerDefinition.getType());
if (ts != null) {
act.addTimingData(ts);
}
}
} else {
// Not handling the others for eCR
}
} else {
// Ignore other types for eCR
}
}
}
}
use of org.hl7.fhir.r4b.model.DataRequirement in project clinical_quality_language by cqframework.
the class DataRequirementsProcessorTest method TestDataRequirementsProcessorWithExpressions.
@Test
public void TestDataRequirementsProcessorWithExpressions() {
CqlTranslatorOptions cqlTranslatorOptions = new CqlTranslatorOptions();
cqlTranslatorOptions.getFormats().add(CqlTranslator.Format.JSON);
try {
Set<String> expressions = new HashSet<>();
// TODO - add expressions to expressions
// Active Ambulatory Opioid Rx");
expressions.add("Conditions Indicating End of Life or With Limited Life Expectancy");
CqlTranslator translator = createTranslator("OpioidCDS/cql/OpioidCDSCommon.cql", cqlTranslatorOptions);
translator.toELM();
assertTrue(translator.getErrors().isEmpty());
libraryManager.cacheLibrary(translator.getTranslatedLibrary());
DataRequirementsProcessor dqReqTrans = new DataRequirementsProcessor();
org.hl7.fhir.r5.model.Library moduleDefinitionLibrary = dqReqTrans.gatherDataRequirements(libraryManager, translator.getTranslatedLibrary(), cqlTranslatorOptions, expressions, false);
assertTrue(moduleDefinitionLibrary.getType().getCode("http://terminology.hl7.org/CodeSystem/library-type").equalsIgnoreCase("module-definition"));
List<Extension> directReferenceCodes = moduleDefinitionLibrary.getExtensionsByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-directReferenceCode");
assertTrue(directReferenceCodes.size() == 4);
Extension directReferenceCode = directReferenceCodes.get(0);
Coding coding = directReferenceCode.getValueCoding();
assertEquals("http://hl7.org/fhir/condition-category", coding.getSystem());
assertEquals("encounter-diagnosis", coding.getCode());
assertEquals("Encounter Diagnosis", coding.getDisplay());
assertTrue(moduleDefinitionLibrary.getRelatedArtifact().size() == 6);
RelatedArtifact conditionCategoryCodes = null;
for (RelatedArtifact relatedArtifact : moduleDefinitionLibrary.getRelatedArtifact()) {
if (relatedArtifact.getType() == RelatedArtifact.RelatedArtifactType.DEPENDSON && relatedArtifact.getResource() != null && relatedArtifact.getResource().equals("http://hl7.org/fhir/condition-category")) {
conditionCategoryCodes = relatedArtifact;
break;
}
}
assertTrue(conditionCategoryCodes != null);
assertTrue(moduleDefinitionLibrary.getParameter().size() == 1);
ParameterDefinition conditionsIndicatingEndOfLife = null;
for (ParameterDefinition parameter : moduleDefinitionLibrary.getParameter()) {
if (parameter.getName().equals("Conditions Indicating End of Life or With Limited Life Expectancy")) {
conditionsIndicatingEndOfLife = parameter;
break;
}
}
assertTrue(conditionsIndicatingEndOfLife != null);
assertTrue(moduleDefinitionLibrary.getDataRequirement().size() == 3);
DataRequirement diagnosisRequirement = null;
for (DataRequirement requirement : moduleDefinitionLibrary.getDataRequirement()) {
if (requirement.getType() == Enumerations.FHIRAllTypes.CONDITION && requirement.getCodeFilter().size() == 1) {
DataRequirement.DataRequirementCodeFilterComponent cfc = requirement.getCodeFilterFirstRep();
if (cfc.hasPath() && cfc.getPath().equals("category") && cfc.getCode().size() == 1 && cfc.getCodeFirstRep().hasCode() && cfc.getCodeFirstRep().getCode().equals("encounter-diagnosis")) {
diagnosisRequirement = requirement;
break;
}
}
}
assertTrue(diagnosisRequirement != null);
FhirContext context = getFhirContext();
IParser parser = context.newJsonParser();
String moduleDefString = parser.setPrettyPrint(true).encodeResourceToString(moduleDefinitionLibrary);
logger.debug(moduleDefString);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
use of org.hl7.fhir.r4b.model.DataRequirement in project clinical_quality_language by cqframework.
the class DataRequirementsProcessorTest method TestLibraryDataRequirements.
@Test
public void TestLibraryDataRequirements() {
CqlTranslatorOptions cqlTranslatorOptions = new CqlTranslatorOptions();
cqlTranslatorOptions.getFormats().add(CqlTranslator.Format.JSON);
try {
// CqlTranslator translator = createTranslator("/ecqm/resources/library-EXM506-2.2.000.json", cqlTranslatorOptions);
CqlTranslator translator = createTranslator("CompositeMeasures/cql/BCSComponent.cql", cqlTranslatorOptions);
translator.toELM();
assertTrue(translator.getErrors().isEmpty());
libraryManager.cacheLibrary(translator.getTranslatedLibrary());
DataRequirementsProcessor dqReqTrans = new DataRequirementsProcessor();
org.hl7.fhir.r5.model.Library moduleDefinitionLibrary = dqReqTrans.gatherDataRequirements(libraryManager, translator.getTranslatedLibrary(), cqlTranslatorOptions, null, false);
assertTrue(moduleDefinitionLibrary.getType().getCode("http://terminology.hl7.org/CodeSystem/library-type").equalsIgnoreCase("module-definition"));
List<Extension> directReferenceCodes = moduleDefinitionLibrary.getExtensionsByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-directReferenceCode");
assertTrue(directReferenceCodes.size() == 5);
Extension directReferenceCode = directReferenceCodes.get(0);
Coding coding = directReferenceCode.getValueCoding();
assertEquals("http://loinc.org", coding.getSystem());
assertEquals("21112-8", coding.getCode());
assertEquals("Birth date", coding.getDisplay());
assertTrue(moduleDefinitionLibrary.getRelatedArtifact().size() >= 45);
RelatedArtifact loincCodeSystem = null;
for (RelatedArtifact relatedArtifact : moduleDefinitionLibrary.getRelatedArtifact()) {
if (relatedArtifact.getType() == RelatedArtifact.RelatedArtifactType.DEPENDSON && relatedArtifact.getResource() != null && relatedArtifact.getResource().equals("http://loinc.org")) {
loincCodeSystem = relatedArtifact;
break;
}
}
assertTrue(loincCodeSystem != null);
assertTrue(moduleDefinitionLibrary.getParameter().size() >= 16);
ParameterDefinition measurementPeriod = null;
for (ParameterDefinition parameter : moduleDefinitionLibrary.getParameter()) {
if (parameter.getName().equals("Measurement Period")) {
measurementPeriod = parameter;
break;
}
}
assertTrue(measurementPeriod != null);
assertTrue(moduleDefinitionLibrary.getDataRequirement().size() >= 15);
DataRequirement diagnosisRequirement = null;
for (DataRequirement requirement : moduleDefinitionLibrary.getDataRequirement()) {
if (requirement.getType() == Enumerations.FHIRAllTypes.CONDITION && requirement.getCodeFilter().size() == 1) {
DataRequirement.DataRequirementCodeFilterComponent cfc = requirement.getCodeFilterFirstRep();
if (cfc.hasPath() && cfc.getPath().equals("code") && cfc.hasValueSet() && cfc.getValueSet().equals("http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.198.12.1071")) {
diagnosisRequirement = requirement;
break;
}
}
}
assertTrue(diagnosisRequirement != null);
FhirContext context = getFhirContext();
IParser parser = context.newJsonParser();
String moduleDefString = parser.setPrettyPrint(true).encodeResourceToString(moduleDefinitionLibrary);
logger.debug(moduleDefString);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
use of org.hl7.fhir.r4b.model.DataRequirement in project clinical_quality_language by cqframework.
the class DataRequirementsProcessorTest method TestDataRequirementsAnalysisCase10a.
@Test
public void TestDataRequirementsAnalysisCase10a() throws IOException {
CqlTranslatorOptions translatorOptions = getTranslatorOptions();
CqlTranslator translator = setupDataRequirementsAnalysis("TestCases/TestCase10a.cql", translatorOptions);
org.hl7.fhir.r5.model.Library moduleDefinitionLibrary = getModuleDefinitionLibrary(translator, translatorOptions);
/*
Element that is a dateTime, referenced in a date comparison
define "ESRD Observations":
[Observation: "ESRD Diagnosis"] O
where O.instant same day or after @2022-02-15
{
type: Observation
mustSupport: [ 'code', 'issued' ]
codeFilter: {
path: 'code',
valueSet: 'http://fakeurl.com/ersd-diagnosis'
},
dateFilter: {
path: 'issued',
valuePeriod: {
low: @2022-02-15
}
}
}
*/
// Validate the ELM is correct
ExpressionDef ed = translator.getTranslatedLibrary().resolveExpressionRef("ESRD Observations");
assertTrue(ed.getExpression() instanceof Query);
Query q = (Query) ed.getExpression();
assertTrue(q.getSource() != null && q.getSource().size() == 1);
AliasedQuerySource source = q.getSource().get(0);
assertTrue(source.getExpression() instanceof Retrieve);
Retrieve r = (Retrieve) source.getExpression();
assertTrue(r.getDataType().getLocalPart().equals("Observation"));
// Validate the data requirement is reported in the module definition library
DataRequirement expectedDataRequirement = null;
for (DataRequirement dr : moduleDefinitionLibrary.getDataRequirement()) {
if (dr.getType() == Enumerations.FHIRAllTypes.OBSERVATION) {
expectedDataRequirement = dr;
}
}
assertTrue(expectedDataRequirement != null);
assertTrue(expectedDataRequirement.getMustSupport().size() == 2);
boolean hasCode = false;
assertTrue(expectedDataRequirement.getMustSupport().stream().filter(s -> s.getValue().equals("code")).count() == 1);
assertTrue(expectedDataRequirement.getMustSupport().stream().filter(s -> s.getValue().equals("issued")).count() == 1);
assertTrue(expectedDataRequirement.getCodeFilter().size() == 1);
DataRequirement.DataRequirementCodeFilterComponent drcfc = expectedDataRequirement.getCodeFilter().get(0);
assertTrue(drcfc.getPath().equals("code"));
assertTrue(drcfc.getValueSet().equals("http://fakeurl.com/ersd-diagnosis"));
assertTrue(expectedDataRequirement.getDateFilter().size() == 1);
DataRequirement.DataRequirementDateFilterComponent drdfc = expectedDataRequirement.getDateFilter().get(0);
LocalDate ld = LocalDate.of(2022, 2, 15);
assertTrue(drdfc.getValuePeriod().getStart().compareTo(Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant())) == 0);
// outputModuleDefinitionLibrary(moduleDefinitionLibrary);
}
Aggregations