Search in sources :

Example 1 with Measure

use of org.hl7.fhir.r4.model.Measure in project kindling by HL7.

the class SpreadSheetReloader method parseType.

private void parseType(ElementDefinition ed, String value, String hierarchy) throws Exception {
    ed.getType().clear();
    ed.setContentReferenceElement(null);
    if (ed.getPath().equals("Resource.id")) {
        ed.addType().setCode("http://hl7.org/fhirpath/System.String").addExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type", new UriType("id"));
    } else {
        if (Utilities.noString(value)) {
            if (ed.getPath().contains(".")) {
                ed.addType().setCode("BackboneElement");
            }
        } else if (value.startsWith("#")) {
            ed.setContentReference(value);
        } else {
            List<TypeRef> tl = new TypeParser(version).parse(value, false, null, context, false);
            for (TypeRef tr : tl) {
                TypeRefComponent t = ed.addType().setCode(tr.getName());
                if ("SimpleQuantity".equals(t.getCode())) {
                    t.setCode("Quantity");
                    t.addProfile("http://hl7.org/fhir/StructureDefinition/SimpleQuantity");
                }
                for (String p : tr.getParams()) {
                    if (p.equals("Definition")) {
                        t.addExtension(BuildExtensions.EXT_PATTERN, new CanonicalType("http://hl7.org/fhir/StructureDefinition/Definition"));
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/ActivityDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EventDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EvidenceVariable");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Measure");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/OperationDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/PlanDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Questionnaire");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/SubscriptionTopic");
                    } else {
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
                    }
                }
                if (Utilities.existsInList(tr.getName(), "canonical", "Reference") && !Utilities.noString(hierarchy)) {
                    t.addExtension(BuildExtensions.EXT_HIERARCHY, new BooleanType(Utilities.existsInList(hierarchy, "true", "True", "TRUE", "1", "y", "Y")));
                }
            }
        }
    }
}
Also used : TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) BooleanType(org.hl7.fhir.r5.model.BooleanType) List(java.util.List) ArrayList(java.util.ArrayList) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) UriType(org.hl7.fhir.r5.model.UriType)

Example 2 with Measure

use of org.hl7.fhir.r4.model.Measure in project kindling by HL7.

the class ResourceParser method parseED.

private void parseED(ProfileUtilities pu, ElementDefn ed, ElementDefinition focus, StructureDefinition sd, String parentName) throws IOException {
    ed.setMinCardinality(focus.getMin());
    ed.setMaxCardinality("*".equals(focus.getMax()) ? Integer.MAX_VALUE : Integer.parseInt(focus.getMax()));
    ed.setIsModifier(focus.getIsModifier());
    ed.setModifierReason(focus.getIsModifierReason());
    ed.setMustSupport(focus.getMustSupport());
    ed.setSummaryItem(focus.getIsSummary());
    ed.setRegex(ToolingExtensions.readStringExtension(focus, ToolingExtensions.EXT_REGEX));
    ed.setXmlAttribute(focus.hasRepresentation(PropertyRepresentation.XMLATTR));
    if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_DIR)) {
        ed.setUmlDir(ToolingExtensions.readStringExtension(focus, BuildExtensions.EXT_UML_DIR));
    }
    if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_BREAK)) {
        ed.setUmlBreak(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_UML_BREAK));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_SVG)) {
        String svg = BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_SVG);
        if (svg.contains("w=")) {
            ed.setSvgWidth(Integer.parseInt(svg.substring(svg.indexOf("w=") + 2)));
            svg = svg.substring(0, svg.indexOf(";"));
        }
        ed.setSvgLeft(Integer.parseInt(svg.substring(0, svg.indexOf(","))));
        ed.setSvgTop(Integer.parseInt(svg.substring(svg.indexOf(",") + 1)));
    }
    ed.setName(tail(focus.getPath()));
    ed.setShortDefn(focus.getShort());
    ed.setDefinition(focus.getDefinition());
    ed.setRequirements(focus.getRequirements());
    ed.setComments(focus.getComment());
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_TODO)) {
        ed.setTodo(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_TODO));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES)) {
        ed.setCommitteeNotes(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_HINT)) {
        ed.setDisplayHint(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_HINT));
    }
    if (focus.hasExtension(BuildExtensions.EXT_NO_BINDING)) {
        ed.setNoBindingAllowed(focus.getExtensionString(BuildExtensions.EXT_NO_BINDING).equals("true"));
    }
    for (StringType t : focus.getAlias()) {
        ed.getAliases().add(t.getValue());
    }
    if (focus.hasMaxLength()) {
        ed.setMaxLength(Integer.toString(focus.getMaxLength()));
    }
    ed.setExample(focus.getExampleFirstRep().getValue());
    ed.setMeaningWhenMissing(focus.getMeaningWhenMissing());
    if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_TRANSLATABLE)) {
        ed.setTranslatable(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_TRANSLATABLE));
    }
    ed.setOrderMeaning(focus.getOrderMeaning());
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)) {
        ed.setStandardsStatus(StandardsStatus.fromCode(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION)) {
        ed.setNormativeVersion(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION));
    }
    for (ElementDefinitionConstraintComponent cst : focus.getConstraint()) {
        Invariant inv = new Invariant();
        inv.setContext(focus.getPath());
        inv.setEnglish(cst.getHuman());
        if (cst.hasExtension(BuildExtensions.EXT_OCL)) {
            inv.setOcl(cst.getExtensionString(BuildExtensions.EXT_OCL));
        }
        inv.setXpath(cst.getXpath());
        inv.setId(cst.getKey());
        if (cst.hasExtension(BuildExtensions.EXT_FIXED_NAME)) {
            inv.setFixedName(cst.getExtensionString(BuildExtensions.EXT_FIXED_NAME));
        }
        inv.setSeverity(cst.getSeverity().toCode());
        if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE)) {
            inv.setSeverity("best-practice");
        }
        if (cst.hasExtension(BuildExtensions.EXT_TURTLE)) {
            inv.setTurtle(cst.getExtensionString(BuildExtensions.EXT_TURTLE));
        }
        inv.setRequirements(cst.getRequirements());
        inv.setExpression(cst.getExpression());
        if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION)) {
            inv.setExplanation(cst.getExtensionString(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION));
        }
        ed.getInvariants().put(inv.getId(), inv);
        invariants.put(inv.getId(), inv);
    }
    for (IdType cnd : focus.getCondition()) {
        Invariant inv = invariants.get(cnd.primitiveValue());
        if (inv == null) {
            System.out.println("Unable to find invariant " + cnd.primitiveValue());
        } else {
            ed.getStatedInvariants().add(inv);
        }
    }
    for (ElementDefinitionMappingComponent map : focus.getMapping()) {
        String uri = getMappingUri(sd, map.getIdentity());
        if ("http://hl7.org/fhir/fivews".equals(uri)) {
            ed.setW5(reverseW5(map.getMap()));
        } else {
            ed.getMappings().put(uri, map.getMap());
        }
    }
    if (focus.hasContentReference()) {
        ed.getTypes().add(new TypeRef("@" + focus.getContentReference().substring(1)));
    } else {
        for (TypeRefComponent tr : focus.getType()) {
            if (!Utilities.existsInList(tr.getCode(), "Element", "BackboneElement")) {
                TypeRef t = new TypeRef();
                ed.getTypes().add(t);
                if (tr.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")) {
                    t.setName(tr.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type"));
                } else {
                    t.setName(tr.getCode());
                }
                if (ToolingExtensions.hasExtension(tr, BuildExtensions.EXT_HIERARCHY)) {
                    ed.setHierarchy(ToolingExtensions.readBoolExtension(tr, BuildExtensions.EXT_HIERARCHY));
                }
                for (CanonicalType u : tr.getProfile()) {
                    t.setProfile(u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", ""));
                }
                for (CanonicalType u : tr.getTargetProfile()) {
                    String s = u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", "");
                    if ("Resource".equals(s)) {
                        t.getParams().add("Any");
                    } else {
                        t.getParams().add(s);
                    }
                }
                if (t.getName().equals("Quantity") && "SimpleQuantity".equals(t.getProfile())) {
                    t.setName("SimpleQuantity");
                    t.setProfile(null);
                }
                if ("Resource".equals(t.getProfile())) {
                    t.setProfile("Any");
                }
                if (t.getParams().toString().equals("[ActivityDefinition, EventDefinition, EvidenceVariable, Measure, OperationDefinition, PlanDefinition, Questionnaire, SubscriptionTopic]")) {
                    t.getParams().clear();
                    t.getParams().add("Definition");
                }
            }
        }
        if (ed.getTypes().size() == STAR_TYPES_COUNT) {
            ed.getTypes().clear();
            ed.getTypes().add(new TypeRef("*"));
        }
    }
    String name = parentName + Utilities.capitalize(ed.getName());
    if (focus.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
        ed.setStatedType(focus.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name"));
        ed.setDeclaredTypeName(ed.getStatedType());
    } else if (ed.getTypes().isEmpty() && !focus.hasContentReference()) {
        ed.setDeclaredTypeName(name + "Component");
    }
    if (focus.hasBinding()) {
        ed.setBinding(parseBinding(focus.getBinding()));
    }
    for (ElementDefinition child : pu.getChildList(sd, focus, true, false)) {
        ElementDefn c = new ElementDefn();
        ed.getElements().add(c);
        parseED(pu, c, child, sd, name);
    }
// todo:
// private ElementDefinition derivation;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) StringType(org.hl7.fhir.r5.model.StringType) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) ElementDefinitionMappingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) IdType(org.hl7.fhir.r5.model.IdType)

Example 3 with Measure

use of org.hl7.fhir.r4.model.Measure in project cqf-ruler by DBCG.

the class SubmitDataProviderIT method testSubmitData.

@Test
public void testSubmitData() {
    // Create a MR and a resource
    MeasureReport mr = newResource(MeasureReport.class, "test-mr");
    Observation obs = newResource(Observation.class, "test-obs");
    // Submit it
    mySubmitDataProvider.submitData(new SystemRequestDetails(), new IdType("Measure", "test-m"), mr, Lists.newArrayList(obs));
    // Check if they made it to the db
    Observation savedObs = read(obs.getIdElement());
    assertNotNull(savedObs);
    MeasureReport savedMr = read(mr.getIdElement());
    assertNotNull(savedMr);
}
Also used : SystemRequestDetails(ca.uhn.fhir.jpa.partition.SystemRequestDetails) Observation(org.hl7.fhir.r4.model.Observation) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.jupiter.api.Test) DaoIntegrationTest(org.opencds.cqf.ruler.test.DaoIntegrationTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Measure

use of org.hl7.fhir.r4.model.Measure in project cqf-ruler by DBCG.

the class CollectDataProviderIT method testCollectData.

@Test
public void testCollectData() {
    // Create test Measure
    String cql = CqlBuilder.newCqlLibrary("4.0.1").addExpression("Initial Population", "exists([Observation])").build();
    Library lib = Libraries.library(cql);
    Measure m = MeasureBuilder.newCohortMeasure(lib).build();
    this.update(lib);
    this.update(m);
    // Create test data
    Patient john = Patients.john_doe();
    this.create(john);
    Observation obs = newResource(Observation.class).setSubject(new Reference(john));
    this.create(obs);
    Encounter enc = newResource(Encounter.class).setSubject(new Reference(john));
    this.create(enc);
    // Submit it
    Parameters results = collectDataProvider.collectData(new SystemRequestDetails(), m.getIdElement(), "2019-01-01", "2019-12-31", Ids.simple(john), null, null);
    List<ParametersParameterComponent> resources = org.opencds.cqf.ruler.utility.r4.Parameters.getPartsByName(results, "resource");
    assertEquals(1, resources.size());
    assertEquals("Observation", resources.get(0).getResource().fhirType());
    List<ParametersParameterComponent> reports = org.opencds.cqf.ruler.utility.r4.Parameters.getPartsByName(results, "measureReport");
    assertEquals(1, reports.size());
    assertEquals("MeasureReport", reports.get(0).getResource().fhirType());
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) SystemRequestDetails(ca.uhn.fhir.jpa.partition.SystemRequestDetails) Reference(org.hl7.fhir.r4.model.Reference) Measure(org.hl7.fhir.r4.model.Measure) Observation(org.hl7.fhir.r4.model.Observation) Patient(org.hl7.fhir.r4.model.Patient) Encounter(org.hl7.fhir.r4.model.Encounter) Library(org.hl7.fhir.r4.model.Library) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent) Test(org.junit.jupiter.api.Test) DaoIntegrationTest(org.opencds.cqf.ruler.test.DaoIntegrationTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Measure

use of org.hl7.fhir.r4.model.Measure in project cqf-ruler by DBCG.

the class DataOperationProviderIT method testR4MeasureDataRequirementsOperation.

@Test
public void testR4MeasureDataRequirementsOperation() throws IOException {
    String bundleAsText = stringFromResource("Exm104FhirR4MeasureBundle.json");
    Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText);
    getClient().transaction().withBundle(bundle).execute();
    Parameters params = new Parameters();
    params.addParameter().setName("startPeriod").setValue(new StringType("2019-01-01"));
    params.addParameter().setName("endPeriod").setValue(new StringType("2020-01-01"));
    Library returnLibrary = getClient().operation().onInstance(new IdType("Measure", "measure-EXM104-8.2.000")).named("$data-requirements").withParameters(params).returnResourceType(Library.class).execute();
    assertNotNull(returnLibrary);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) Bundle(org.hl7.fhir.r4.model.Bundle) Library(org.hl7.fhir.r4.model.Library) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Aggregations

Measure (org.hl7.fhir.r4.model.Measure)119 Test (org.junit.Test)97 Library (org.hl7.fhir.r4.model.Library)61 Patient (org.hl7.fhir.r4.model.Patient)45 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)44 HashMap (java.util.HashMap)24 ArrayList (java.util.ArrayList)23 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)22 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)22 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)22 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)20 CapabilityStatement (org.hl7.fhir.r4.model.CapabilityStatement)20 Test (org.junit.jupiter.api.Test)18 Extension (org.hl7.fhir.r4.model.Extension)15 StringType (org.hl7.fhir.r4.model.StringType)15 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)14 CanonicalType (org.hl7.fhir.r4.model.CanonicalType)14 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)14