Search in sources :

Example 71 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project Gravity-SDOH-Exchange-RI by FHIR.

the class PatientSocialRiskTaskBundleFactory method createTask.

protected Task createTask() {
    Task task = super.createTask();
    task.getCode().addCoding(PatientTaskCode.COMPLETE_QUESTIONNAIRE.toCoding());
    Task.ParameterComponent input = task.addInput();
    input.getType().addCoding(new Coding(SDCTemporaryCode.SYSTEM, SDCTemporaryCode.QUESTIONNAIRE.getCode(), SDCTemporaryCode.QUESTIONNAIRE.getDisplay()));
    input.setValue(new CanonicalType(questionniare.getUrl()));
    Task.ParameterComponent input2 = task.addInput();
    input2.getType().addCoding(new Coding(SDOHTemporaryCode.SYSTEM, SDOHTemporaryCode.QUESTIONNAIRE_CATEGORY.getCode(), SDOHTemporaryCode.QUESTIONNAIRE_CATEGORY.getDisplay()));
    input2.setValue(new CodeableConcept().addCoding(new Coding(SDOHTemporaryCode.SYSTEM, SDOHTemporaryCode.RISK_QUESTIONNAIRE.getCode(), SDOHTemporaryCode.RISK_QUESTIONNAIRE.getDisplay())));
    return task;
}
Also used : Task(org.hl7.fhir.r4.model.Task) Coding(org.hl7.fhir.r4.model.Coding) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 72 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project pathling by aehrc.

the class ConformanceProvider method buildOperations.

@Nonnull
private List<CapabilityStatementRestResourceOperationComponent> buildOperations() {
    final List<CapabilityStatementRestResourceOperationComponent> operations = new ArrayList<>();
    for (final String name : SYSTEM_LEVEL_OPERATIONS) {
        final CanonicalType operationUri = new CanonicalType(getOperationUri(name));
        final CapabilityStatementRestResourceOperationComponent operation = new CapabilityStatementRestResourceOperationComponent(new StringType(name), operationUri);
        operations.add(operation);
    }
    return operations;
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) ArrayList(java.util.ArrayList) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) CapabilityStatementRestResourceOperationComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceOperationComponent) Nonnull(javax.annotation.Nonnull)

Example 73 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project quality-measure-and-cohort-service by Alvearie.

the class MeasureSupplementalDataEvaluationTest method testProcessAccumulators_multiplePatients.

@Test
public void testProcessAccumulators_multiplePatients() {
    Map<String, Map<String, Integer>> initialAccumulators = new HashMap<>();
    Map<String, Integer> initialMale = new HashMap<>();
    initialMale.put(MALE_CODE, 1);
    initialAccumulators.put(MeasureSupplementalDataEvaluation.SDE_SEX, initialMale);
    Map<String, Map<String, Integer>> sdeAccumulators = getSexSDEAccumulatorsWithInitialAccumulators(initialAccumulators);
    MeasureReport report = new MeasureReport();
    MeasureSupplementalDataEvaluation.processAccumulators(report, sdeAccumulators, false, new ArrayList<>());
    assertNotNull(report);
    // EvaluatedResource should contain a reference to an observation record created for supplemental data
    assertEquals(1, report.getEvaluatedResource().size());
    // The observation record mentioned previously should exist within the contained resources of the measure report
    assertEquals(1, report.getContained().size());
    assertTrue(report.getContained().get(0) instanceof Observation);
    Observation obs = (Observation) report.getContained().get(0);
    // For a multiple patients, the code of the observation should be the supplemental data text
    assertEquals(MALE_CODE, obs.getCode().getCoding().get(0).getCode());
    // For a multiple patients, the value of the observation should be the result of the appropriate define
    assertTrue(obs.getValue() instanceof IntegerType);
    assertEquals("2", ((IntegerType) obs.getValue()).getValueAsString());
    // Within the observation, there should be 1 extension, with two further nested extensions
    Extension obsExt = obs.getExtensionByUrl(MeasureSupplementalDataEvaluation.CQF_MEASUREINFO_URL);
    assertNotNull(obsExt);
    assertEquals(2, obsExt.getExtension().size());
    Extension measureNestedExt = obsExt.getExtensionByUrl(MeasureSupplementalDataEvaluation.MEASURE);
    assertTrue(measureNestedExt.getValue() instanceof CanonicalType);
    assertEquals(MeasureSupplementalDataEvaluation.CQFMEASURES_URL + report.getMeasure(), ((CanonicalType) measureNestedExt.getValue()).asStringValue());
    Extension populationNestedExt = obsExt.getExtensionByUrl(MeasureSupplementalDataEvaluation.POPULATION_ID);
    assertEquals(MeasureSupplementalDataEvaluation.SDE_SEX, ((StringType) populationNestedExt.getValue()).asStringValue());
}
Also used : IntegerType(org.hl7.fhir.r4.model.IntegerType) Extension(org.hl7.fhir.r4.model.Extension) HashMap(java.util.HashMap) Observation(org.hl7.fhir.r4.model.Observation) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) HashMap(java.util.HashMap) Map(java.util.Map) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.Test)

Example 74 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project quality-measure-and-cohort-service by Alvearie.

the class R4LibraryDependencyGatherer method gatherForMeasure.

public List<Library> gatherForMeasure(Measure measure) {
    List<Library> retVal = new ArrayList<>();
    Set<String> loadedCanonicalUrls = new HashSet<>();
    for (CanonicalType ref : measure.getLibrary()) {
        Library library = resolveLibrary(ref.getValue());
        if (library != null) {
            retVal.addAll(recurse(library, loadedCanonicalUrls));
        }
    }
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) Library(org.hl7.fhir.r4.model.Library) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) HashSet(java.util.HashSet)

Example 75 with CanonicalType

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

the class ProfileGenerator method defineElement.

/**
 * note: snapshot implies that we are generating a resource or a data type; for other profiles, the snapshot is generated elsewhere
 * @param isInterface
 */
private ElementDefinition defineElement(Profile ap, StructureDefinition p, List<ElementDefinition> elements, ElementDefn e, String path, Set<String> slices, List<SliceHandle> parentSlices, SnapShotMode snapshot, boolean root, String defType, String inheritedType, boolean defaults) throws Exception {
    boolean handleDiscriminator = true;
    if (!Utilities.noString(e.getProfileName()) && !e.getDiscriminator().isEmpty() && !slices.contains(path)) {
        handleDiscriminator = false;
        // hey, we jumped straight into the slices with setting up the slicing (allowed in the spreadsheets, but not otherwise)
        ElementDefinition slicer = new ElementDefinition();
        elements.add(slicer);
        slicer.setId(path);
        slicer.setPath(path);
        processDiscriminator(e, path, slicer);
        if (e.getMaxCardinality() != null)
            slicer.setMax(e.getMaxCardinality() == Integer.MAX_VALUE ? "*" : e.getMaxCardinality().toString());
        slices.add(path);
    }
    // todo for task 12259
    // if (ap != null) {
    // String base = isImplicitTypeConstraint(path);
    // if (base != null) {
    // ElementDefinition typeConstrainer = new ElementDefinition(ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    // elements.add(typeConstrainer);
    // typeConstrainer.setId(base);
    // typeConstrainer.setPath(base);
    // String type = path.substring(base.length()-3);
    // if (definitions.hasPrimitiveType(Utilities.uncapitalize(type)))
    // type = Utilities.uncapitalize(type);
    // typeConstrainer.addType().setCode(type);
    // }
    // }
    ElementDefinition ce = new ElementDefinition(defaults, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    elements.add(ce);
    if (e.getStandardsStatus() != null)
        ToolingExtensions.setStandardsStatus(ce, e.getStandardsStatus(), e.getNormativeVersion());
    ce.setId(path);
    ce.setPath(path);
    if (e.isXmlAttribute())
        ce.addRepresentation(PropertyRepresentation.XMLATTR);
    List<SliceHandle> myParents = new ArrayList<ProfileGenerator.SliceHandle>();
    myParents.addAll(parentSlices);
    // which holds Slicing information)
    if (e.hasDescriminator() || !Utilities.noString(e.getProfileName())) {
        if (e.getDiscriminator().size() > 0 && !slices.contains(path) && handleDiscriminator) {
            processDiscriminator(e, path, ce);
            slices.add(path);
        }
        if (!Utilities.noString(e.getProfileName())) {
            SliceHandle hnd = new SliceHandle();
            // though this it not used?
            hnd.name = path;
            myParents.add(hnd);
            if (path.contains(".")) {
                // We don't want a slice name on the root
                ce.setSliceName(e.getProfileName());
                ce.setId(ce.getId() + ":" + e.getProfileName());
            }
        }
    }
    if (e.isTranslatable()) {
        ce.addExtension(BuildExtensions.EXT_TRANSLATABLE, new BooleanType(true));
    }
    if (Utilities.existsInList(ce.getPath(), "Element.extension", "DomainResource.extension", "DomainResource.modifierExtension") && !ce.hasSlicing() && !ce.hasSliceName()) {
        ce.getSlicing().setDescription("Extensions are always sliced by (at least) url").setRules(SlicingRules.OPEN).addDiscriminator().setType(DiscriminatorType.VALUE).setPath("url");
    }
    if (!Utilities.noString(inheritedType) && snapshot != SnapShotMode.None) {
        ElementDefn inh = definitions.getElementDefn(inheritedType);
        buildDefinitionFromElement(path, ce, inh, ap, p, inheritedType, definitions.getBaseResources().containsKey(inheritedType) && definitions.getBaseResources().get(inheritedType).isInterface());
    } else if (path.contains(".") && Utilities.noString(e.typeCode()) && snapshot != SnapShotMode.None) {
        addElementConstraints(defType, ce);
    }
    buildDefinitionFromElement(path, ce, e, ap, p, null, false);
    if (!Utilities.noString(e.getStatedType())) {
        ToolingExtensions.addStringExtension(ce, "http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name", e.getStatedType());
    }
    if (e.isNoBindingAllowed()) {
        ToolingExtensions.addBooleanExtension(ce, BuildExtensions.EXT_NO_BINDING, true);
    }
    if (!root) {
        if (e.typeCode().startsWith("@")) {
            ce.setContentReference("#" + getIdForPath(elements, e.typeCode().substring(1)));
        } else if (Utilities.existsInList(path, "Element.id", "Extension.url") || path.endsWith(".id")) {
            TypeRefComponent tr = ce.addType();
            tr.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (j)");
            tr.setCode(Constants.NS_SYSTEM_TYPE + "String");
            if (path.equals("Extension.url")) {
                ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "uri");
            } else if (p.getKind() == StructureDefinitionKind.RESOURCE) {
                ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "id");
            } else {
                ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "string");
            }
        } else {
            List<TypeRef> expandedTypes = new ArrayList<TypeRef>();
            for (TypeRef t : e.getTypes()) {
                // Expand any Resource(A|B|C) references
                if (t.hasParams() && !Utilities.existsInList(t.getName(), "Reference", "canonical", "CodeableReference")) {
                    throw new Exception("Only resource types can specify parameters.  Path " + path + " in profile " + p.getName());
                }
                if (t.getParams().size() > 1) {
                    if (t.getProfile() != null && t.getParams().size() != 1) {
                        throw new Exception("Cannot declare profile on a resource reference declaring multiple resource types.  Path " + path + " in profile " + p.getName());
                    }
                    for (String param : t.getParams()) {
                        if (definitions.hasLogicalModel(param)) {
                            for (String pn : definitions.getLogicalModel(param).getImplementations()) {
                                TypeRef childType = new TypeRef(t.getName());
                                childType.getParams().add(pn);
                                childType.getAggregations().addAll(t.getAggregations());
                                expandedTypes.add(childType);
                            }
                        } else {
                            TypeRef childType = new TypeRef(t.getName());
                            childType.getParams().add(param);
                            childType.getAggregations().addAll(t.getAggregations());
                            expandedTypes.add(childType);
                        }
                    }
                } else if (t.isWildcardType()) {
                    // this list is filled out manually because it may be running before the types referred to have been loaded
                    for (String n : TypesUtilities.wildcardTypes(version.toString())) expandedTypes.add(new TypeRef(n));
                } else if (!t.getName().startsWith("=")) {
                    if (definitions.isLoaded() && (!definitions.hasResource(t.getName()) && !definitions.hasType(t.getName()) && !definitions.hasElementDefn(t.getName()) && !definitions.getBaseResources().containsKey(t.getName()) && !t.getName().equals("xhtml"))) {
                        throw new Exception("Bad Type '" + t.getName() + "' at " + path + " in profile " + p.getUrl());
                    }
                    expandedTypes.add(t);
                }
            }
            if (expandedTypes.isEmpty()) {
                if (defType != null)
                    ce.addType().setCode(defType);
            } else
                for (TypeRef t : expandedTypes) {
                    String profile = null;
                    String tc = null;
                    if (definitions.getConstraints().containsKey(t.getName())) {
                        ProfiledType pt = definitions.getConstraints().get(t.getName());
                        tc = pt.getBaseType();
                        profile = "http://hl7.org/fhir/StructureDefinition/" + pt.getName();
                    } else {
                        tc = t.getName();
                        profile = t.getProfile();
                    }
                    TypeRefComponent type = ce.getType(tc);
                    if (profile == null && t.hasParams()) {
                        profile = t.getParams().get(0);
                    }
                    if (t.getPatterns() != null) {
                        for (String s : t.getPatterns()) {
                            type.addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-pattern", new CanonicalType("http://hl7.org/fhir/StructureDefinition/" + s));
                        }
                    }
                    if (profile != null) {
                        if (type.getWorkingCode().equals("Extension")) {
                            // check that the extension is being used correctly:
                            StructureDefinition ext = context.getExtensionStructure(null, profile);
                            if (ext == null) {
                                throw new Exception("Unable to resolve extension definition: " + profile);
                            }
                            boolean srcMod = ext.getSnapshot().getElement().get(0).getIsModifier();
                            boolean tgtMod = e.isModifier();
                            if (srcMod && !tgtMod)
                                throw new Exception("The extension '" + profile + "' is a modifier extension, but is being used as if it is not a modifier extension");
                            if (!srcMod && tgtMod)
                                throw new Exception("The extension '" + profile + "' is not a modifier extension, but is being used as if it is a modifier extension");
                        }
                        List<String> pr = new ArrayList<>();
                        if (profile.startsWith("http:") || profile.startsWith("#")) {
                            pr.add(profile);
                        } else if (definitions.hasLogicalModel(profile)) {
                            for (String pn : definitions.getLogicalModel(profile).getImplementations()) pr.add("http://hl7.org/fhir/StructureDefinition/" + pn);
                        } else
                            pr.add("http://hl7.org/fhir/StructureDefinition/" + (profile.equals("Any") ? "Resource" : profile));
                        if (type.getWorkingCode().equals("Reference") || type.getWorkingCode().equals("canonical") || type.getWorkingCode().equals("CodeableReference")) {
                            for (String pn : pr) {
                                type.addTargetProfile(pn);
                                if (e.hasHierarchy())
                                    ToolingExtensions.addBooleanExtension(type, ToolingExtensions.EXT_HIERARCHY, e.getHierarchy());
                            }
                        } else
                            for (String pn : pr) {
                                type.addProfile(pn);
                            }
                    }
                    for (String aggregation : t.getAggregations()) {
                        type.addAggregation(AggregationMode.fromCode(aggregation));
                    }
                }
        }
    }
    String w5 = translateW5(e.getW5());
    if (w5 != null)
        addMapping(p, ce, "http://hl7.org/fhir/fivews", w5, ap);
    if (e.isTranslatable())
        ce.addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-translatable", new BooleanType(true));
    if (!Utilities.noString(e.getOrderMeaning()))
        ce.setOrderMeaning(e.getOrderMeaning());
    if (e.hasBinding()) {
        ce.setBinding(generateBinding(e.getBinding()));
    }
    if (snapshot != SnapShotMode.None && !e.getElements().isEmpty()) {
    // makeExtensionSlice("extension", p, c, e, path);
    // if (snapshot == SnapShotMode.Resource) {
    // makeExtensionSlice("modifierExtension", p, c, e, path);
    // if (!path.contains(".")) {
    // c.getElement().add(createBaseDefinition(p, path, definitions.getBaseResources().get("Resource").getRoot().getElementByName("language")));
    // c.getElement().add(createBaseDefinition(p, path, definitions.getBaseResources().get("DomainResource").getRoot().getElementByName("text")));
    // c.getElement().add(createBaseDefinition(p, path, definitions.getBaseResources().get("DomainResource").getRoot().getElementByName("contained")));
    // }
    // }
    }
    if (defaults)
        ce.makeBase();
    Set<String> containedSlices = new HashSet<String>();
    if (snapshot != SnapShotMode.None) {
        if (!root && Utilities.noString(e.typeCode())) {
            if (snapshot == SnapShotMode.Resource)
                defineAncestorElements("BackboneElement", path, snapshot, containedSlices, p, elements, defType, defaults);
            else
                defineAncestorElements("Element", path, snapshot, containedSlices, p, elements, defType, defaults);
        } else if (root && !Utilities.noString(e.typeCode()))
            defineAncestorElements(e.typeCode(), path, snapshot, containedSlices, p, elements, defType, defaults);
    }
    for (ElementDefn child : e.getElements()) defineElement(ap, p, elements, child, path + "." + child.getName(), containedSlices, myParents, snapshot, false, defType, null, defaults);
    return ce;
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r5.model.BooleanType) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) List(java.util.List) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) HashSet(java.util.HashSet)

Aggregations

CanonicalType (org.hl7.fhir.r4.model.CanonicalType)45 CanonicalType (org.hl7.fhir.r5.model.CanonicalType)37 ArrayList (java.util.ArrayList)27 CanonicalType (org.hl7.fhir.r4b.model.CanonicalType)19 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)14 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)12 Test (org.junit.jupiter.api.Test)12 List (java.util.List)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Extension (org.hl7.fhir.r4.model.Extension)7 Library (org.hl7.fhir.r4.model.Library)7 StringType (org.hl7.fhir.r4.model.StringType)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)5 Bundle (org.hl7.fhir.r4.model.Bundle)5 IdType (org.hl7.fhir.r4.model.IdType)5