Search in sources :

Example 91 with UriType

use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method makeTypeList.

private ValueSet makeTypeList(StructureDefinition profile, List<TypeRefComponent> types, String path) {
    ValueSet vs = new ValueSet();
    vs.setName("Type options for " + path);
    vs.setDescription(vs.present());
    vs.setStatus(PublicationStatus.ACTIVE);
    vs.setExpansion(new ValueSetExpansionComponent());
    vs.getExpansion().setIdentifier(Factory.createUUID());
    vs.getExpansion().setTimestampElement(DateTimeType.now());
    for (TypeRefComponent t : types) {
        if (t.hasTarget()) {
            for (UriType u : t.getTargetProfile()) {
                if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                    ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
                    cc.setCode(u.getValue().substring(40));
                    cc.setSystem("http://hl7.org/fhir/resource-types");
                    cc.setDisplay(cc.getCode());
                }
            }
        } else if (!t.hasProfile()) {
            ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
            cc.setCode(t.getWorkingCode());
            cc.setDisplay(t.getWorkingCode());
            cc.setSystem("http://hl7.org/fhir/data-types");
        } else
            for (UriType u : t.getProfile()) {
                ProfileUtilities pu = new ProfileUtilities(context, null, null);
                StructureDefinition ps = pu.getProfile(profile, u.getValue());
                if (ps != null) {
                    ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
                    cc.setCode(u.getValue());
                    cc.setDisplay(ps.getType());
                    cc.setSystem("http://hl7.org/fhir/resource-types");
                }
            }
    }
    return vs;
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ValueSet(org.hl7.fhir.r5.model.ValueSet) UriType(org.hl7.fhir.r5.model.UriType)

Example 92 with UriType

use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method addReferenceQuestions.

// Special Types ---------------------------------------------------------------
private void addReferenceQuestions(QuestionnaireItemComponent group, ElementDefinition element, String path, List<CanonicalType> profileURL, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups) throws FHIRException {
    // var
    // rn : String;
    // i : integer;
    // q : TFhirQuestionnaireGroupQuestion;
    ToolingExtensions.addFhirType(group, "Reference");
    QuestionnaireItemComponent q = addQuestion(group, QuestionnaireItemType.REFERENCE, null, path, "value", group.getText(), answerGroups);
    group.setText(null);
    CommaSeparatedStringBuilder rn = new CommaSeparatedStringBuilder();
    for (UriType u : profileURL) if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/"))
        rn.append(u.getValue().substring(40));
    if (rn.length() == 0)
        ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
    else {
        ToolingExtensions.addAllowedResource(q, rn.toString());
        ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
    }
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups) ag.setText(null);
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) QuestionnaireResponse(org.hl7.fhir.r5.model.QuestionnaireResponse) UriType(org.hl7.fhir.r5.model.UriType)

Example 93 with UriType

use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.

the class R3R4ConversionTests method checkLoad.

/*
   * Supporting multiple versions at once is a little tricky. We're going to have
   * 2 contexts: - an R3 context which is used to read/write R3 instances - an R4
   * context which is used to perform the transforms
   *
   * R3 structure definitions are cloned into R3 context with a modified URL (as
   * 3.0/)
   *
   */
private void checkLoad() throws IOException, FHIRException, Exception {
    if (contextR3 != null)
        return;
    pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    R3ToR4Loader ldr = (R3ToR4Loader) new R3ToR4Loader().setPatchUrls(true).setKillPrimitives(true);
    System.out.println("loading R3");
    contextR3 = new SimpleWorkerContext();
    contextR3.setAllowLoadingDuplicates(true);
    contextR3.setOverrideVersionNs("http://hl7.org/fhir/3.0/StructureDefinition");
    contextR3.loadFromPackage(pcm.loadPackage("hl7.fhir.core", "3.0.1"), ldr, new String[] {});
    System.out.println("loading R4");
    contextR4 = new SimpleWorkerContext();
    contextR4 = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.0"));
    contextR4.setCanRunWithoutTerminology(true);
    for (StructureDefinition sd : contextR3.allStructures()) {
        StructureDefinition sdn = sd.copy();
        sdn.getExtension().clear();
        contextR4.cacheResource(sdn);
    }
    for (StructureDefinition sd : contextR4.allStructures()) {
        if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
            contextR3.cacheResource(sd);
            StructureDefinition sdn = sd.copy();
            sdn.setUrl(sdn.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/3.0/"));
            sdn.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
            contextR3.cacheResource(sdn);
            contextR4.cacheResource(sdn);
        }
    }
    contextR3.setExpansionProfile(new org.hl7.fhir.r4.model.Parameters());
    contextR4.setExpansionProfile(new org.hl7.fhir.r4.model.Parameters());
    contextR3.setName("R3");
    contextR4.setName("R4");
    // contextR4.setValidatorFactory(new InstanceValidatorFactory());
    // TODO: this has to be R% now...    contextR4.setValidatorFactory(new InstanceValidatorFactory());
    System.out.println("loading Maps");
    loadLib(Utilities.path(TestingUtilities.home(), "implementations", "r3maps", "R4toR3"));
    loadLib(Utilities.path(TestingUtilities.home(), "implementations", "r3maps", "R3toR4"));
    System.out.println("loaded");
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) SimpleWorkerContext(org.hl7.fhir.r4.context.SimpleWorkerContext) R3ToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R3ToR4Loader) UriType(org.hl7.fhir.r4.model.UriType)

Example 94 with UriType

use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.

the class InstanceValidator method validateContains.

private void validateContains(ValidatorHostContext hostContext, List<ValidationMessage> errors, String path, ElementDefinition child, ElementDefinition context, Element resource, Element element, NodeStack stack, IdStatus idstatus, StructureDefinition parentProfile) throws FHIRException {
    SpecialElement special = element.getSpecial();
    ContainedReferenceValidationPolicy containedValidationPolicy = getPolicyAdvisor() == null ? ContainedReferenceValidationPolicy.CHECK_VALID : getPolicyAdvisor().policyForContained(this, hostContext, context.fhirType(), context.getId(), special, path, parentProfile.getUrl());
    if (containedValidationPolicy.ignore()) {
        return;
    }
    String resourceName = element.getType();
    TypeRefComponent typeForResource = null;
    CommaSeparatedStringBuilder bt = new CommaSeparatedStringBuilder();
    // Iterate through all possible types
    for (TypeRefComponent type : child.getType()) {
        bt.append(type.getCode());
        if (type.getCode().equals("Resource") || type.getCode().equals(resourceName)) {
            typeForResource = type;
            break;
        }
    }
    stack.qualifyPath(".ofType(" + resourceName + ")");
    if (typeForResource == null) {
        rule(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_BUNDLE_ENTRY_TYPE, resourceName, bt.toString());
    } else if (isValidResourceType(resourceName, typeForResource)) {
        if (containedValidationPolicy.checkValid()) {
            // special case: resource wrapper is reset if we're crossing a bundle boundary, but not otherwise
            ValidatorHostContext hc = null;
            if (special == SpecialElement.BUNDLE_ENTRY || special == SpecialElement.BUNDLE_OUTCOME || special == SpecialElement.PARAMETER) {
                resource = element;
                assert Utilities.existsInList(hostContext.getRootResource().fhirType(), "Bundle", "Parameters") : "Resource is " + hostContext.getRootResource().fhirType() + ", expected Bundle or Parameters";
                // root becomes the grouping resource (should be either bundle or parameters)
                hc = hostContext.forEntry(element, hostContext.getRootResource());
            } else {
                hc = hostContext.forContained(element);
            }
            stack.resetIds();
            if (special != null) {
                switch(special) {
                    case BUNDLE_ENTRY:
                    case BUNDLE_OUTCOME:
                    case PARAMETER:
                        idstatus = IdStatus.OPTIONAL;
                        break;
                    case CONTAINED:
                        stack.setContained(true);
                        idstatus = IdStatus.REQUIRED;
                        break;
                    default:
                        break;
                }
            }
            if (typeForResource.getProfile().size() == 1) {
                long t = System.nanoTime();
                StructureDefinition profile = this.context.fetchResource(StructureDefinition.class, typeForResource.getProfile().get(0).asStringValue());
                timeTracker.sd(t);
                trackUsage(profile, hostContext, element);
                if (rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), profile != null, I18nConstants.BUNDLE_BUNDLE_ENTRY_NOPROFILE_EXPL, special.toHuman(), resourceName, typeForResource.getProfile().get(0).asStringValue())) {
                    validateResource(hc, errors, resource, element, profile, idstatus, stack);
                }
            } else if (typeForResource.getProfile().isEmpty()) {
                long t = System.nanoTime();
                StructureDefinition profile = this.context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + resourceName);
                timeTracker.sd(t);
                trackUsage(profile, hostContext, element);
                if (rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), profile != null, I18nConstants.BUNDLE_BUNDLE_ENTRY_NOPROFILE_TYPE, special == null ? "??" : special.toHuman(), resourceName)) {
                    validateResource(hc, errors, resource, element, profile, idstatus, stack);
                }
            } else {
                CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
                for (CanonicalType u : typeForResource.getProfile()) {
                    b.append(u.asStringValue());
                }
                rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_BUNDLE_ENTRY_MULTIPLE_PROFILES, special.toHuman(), typeForResource.getCode(), b.toString());
            }
        }
    } else {
        List<String> types = new ArrayList<>();
        for (UriType u : typeForResource.getProfile()) {
            StructureDefinition sd = this.context.fetchResource(StructureDefinition.class, u.getValue());
            if (sd != null && !types.contains(sd.getType())) {
                types.add(sd.getType());
            }
        }
        if (types.size() == 1) {
            rule(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_BUNDLE_ENTRY_TYPE2, resourceName, types.get(0));
        } else {
            rule(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_BUNDLE_ENTRY_TYPE3, resourceName, types);
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ValidatorHostContext(org.hl7.fhir.validation.instance.utils.ValidatorHostContext) SpecialElement(org.hl7.fhir.r5.elementmodel.Element.SpecialElement) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ArrayList(java.util.ArrayList) List(java.util.List) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) UriType(org.hl7.fhir.r5.model.UriType)

Example 95 with UriType

use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generate.

public boolean generate(ResourceContext rcontext, ConceptMap cm) throws FHIRFormatError, DefinitionException, IOException {
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.h2().addText(cm.getName() + " (" + cm.getUrl() + ")");
    XhtmlNode p = x.para();
    if (cm.hasSource() || cm.hasTarget())
        p.tx("Mapping from ");
    if (!cm.hasSource())
        p.tx("(unspecified)");
    else
        AddVsRef(rcontext, cm.getSource() instanceof Reference ? ((Reference) cm.getSource()).getReference() : ((UriType) cm.getSource()).asStringValue(), p);
    p.tx(" to ");
    if (!cm.hasTarget())
        p.tx("(unspecified)");
    else
        AddVsRef(rcontext, cm.getTarget() instanceof Reference ? ((Reference) cm.getTarget()).getReference() : ((UriType) cm.getTarget()).asStringValue(), p);
    p = x.para();
    if (cm.getExperimental())
        p.addText(Utilities.capitalize(cm.getStatus().toString()) + " (not intended for production usage). ");
    else
        p.addText(Utilities.capitalize(cm.getStatus().toString()) + ". ");
    p.tx("Published on " + (cm.hasDate() ? cm.getDateElement().toHumanDisplay() : "??") + " by " + cm.getPublisher());
    if (!cm.getContact().isEmpty()) {
        p.tx(" (");
        boolean firsti = true;
        for (ContactDetail ci : cm.getContact()) {
            if (firsti)
                firsti = false;
            else
                p.tx(", ");
            if (ci.hasName())
                p.addText(ci.getName() + ": ");
            boolean first = true;
            for (ContactPoint c : ci.getTelecom()) {
                if (first)
                    first = false;
                else
                    p.tx(", ");
                addTelecom(p, c);
            }
        }
        p.tx(")");
    }
    p.tx(". ");
    p.addText(cm.getCopyright());
    if (!Utilities.noString(cm.getDescription()))
        addMarkdown(x, cm.getDescription());
    x.br();
    for (ConceptMapGroupComponent grp : cm.getGroup()) {
        String src = grp.getSource();
        boolean comment = false;
        boolean ok = true;
        Map<String, HashSet<String>> sources = new HashMap<String, HashSet<String>>();
        Map<String, HashSet<String>> targets = new HashMap<String, HashSet<String>>();
        sources.put("code", new HashSet<String>());
        targets.put("code", new HashSet<String>());
        SourceElementComponent cc = grp.getElement().get(0);
        String dst = grp.getTarget();
        sources.get("code").add(grp.getSource());
        targets.get("code").add(grp.getTarget());
        for (SourceElementComponent ccl : grp.getElement()) {
            ok = ok && ccl.getTarget().size() == 1 && ccl.getTarget().get(0).getDependsOn().isEmpty() && ccl.getTarget().get(0).getProduct().isEmpty();
            for (TargetElementComponent ccm : ccl.getTarget()) {
                comment = comment || !Utilities.noString(ccm.getComment());
                for (OtherElementComponent d : ccm.getDependsOn()) {
                    if (!sources.containsKey(d.getProperty()))
                        sources.put(d.getProperty(), new HashSet<String>());
                    sources.get(d.getProperty()).add(d.getSystem());
                }
                for (OtherElementComponent d : ccm.getProduct()) {
                    if (!targets.containsKey(d.getProperty()))
                        targets.put(d.getProperty(), new HashSet<String>());
                    targets.get(d.getProperty()).add(d.getSystem());
                }
            }
        }
        String display;
        if (ok) {
            // simple
            XhtmlNode tbl = x.table("grid");
            XhtmlNode tr = tbl.tr();
            tr.td().b().tx("Source Code");
            tr.td().b().tx("Equivalence");
            tr.td().b().tx("Destination Code");
            if (comment)
                tr.td().b().tx("Comment");
            for (SourceElementComponent ccl : grp.getElement()) {
                tr = tbl.tr();
                XhtmlNode td = tr.td();
                td.addText(ccl.getCode());
                display = getDisplayForConcept(grp.getSource(), ccl.getCode());
                if (display != null)
                    td.tx(" (" + display + ")");
                TargetElementComponent ccm = ccl.getTarget().get(0);
                tr.td().addText(!ccm.hasEquivalence() ? "" : ccm.getEquivalence().toCode());
                td = tr.td();
                td.addText(ccm.getCode());
                display = getDisplayForConcept(grp.getTarget(), ccm.getCode());
                if (display != null)
                    td.tx(" (" + display + ")");
                if (comment)
                    tr.td().addText(ccm.getComment());
            }
        } else {
            XhtmlNode tbl = x.table("grid");
            XhtmlNode tr = tbl.tr();
            XhtmlNode td;
            tr.td().colspan(Integer.toString(sources.size())).b().tx("Source Concept");
            tr.td().b().tx("Equivalence");
            tr.td().colspan(Integer.toString(targets.size())).b().tx("Destination Concept");
            if (comment)
                tr.td().b().tx("Comment");
            tr = tbl.tr();
            if (sources.get("code").size() == 1)
                tr.td().b().tx("Code " + sources.get("code").toString() + "");
            else
                tr.td().b().tx("Code");
            for (String s : sources.keySet()) {
                if (!s.equals("code")) {
                    if (sources.get(s).size() == 1)
                        tr.td().b().addText(getDescForConcept(s) + " " + sources.get(s).toString());
                    else
                        tr.td().b().addText(getDescForConcept(s));
                }
            }
            tr.td();
            if (targets.get("code").size() == 1)
                tr.td().b().tx("Code " + targets.get("code").toString());
            else
                tr.td().b().tx("Code");
            for (String s : targets.keySet()) {
                if (!s.equals("code")) {
                    if (targets.get(s).size() == 1)
                        tr.td().b().addText(getDescForConcept(s) + " " + targets.get(s).toString() + "");
                    else
                        tr.td().b().addText(getDescForConcept(s));
                }
            }
            if (comment)
                tr.td();
            for (SourceElementComponent ccl : grp.getElement()) {
                tr = tbl.tr();
                td = tr.td();
                if (sources.get("code").size() == 1)
                    td.addText(ccl.getCode());
                else
                    td.addText(grp.getSource() + " / " + ccl.getCode());
                display = getDisplayForConcept(grp.getSource(), ccl.getCode());
                if (display != null)
                    td.tx(" (" + display + ")");
                TargetElementComponent ccm = ccl.getTarget().get(0);
                for (String s : sources.keySet()) {
                    if (!s.equals("code")) {
                        td = tr.td();
                        td.addText(getCode(ccm.getDependsOn(), s, sources.get(s).size() != 1));
                        display = getDisplay(ccm.getDependsOn(), s);
                        if (display != null)
                            td.tx(" (" + display + ")");
                    }
                }
                if (!ccm.hasEquivalence())
                    tr.td().tx(":" + "(" + ConceptMapEquivalence.EQUIVALENT.toCode() + ")");
                else
                    tr.td().tx(":" + ccm.getEquivalence().toCode());
                td = tr.td();
                if (targets.get("code").size() == 1)
                    td.addText(ccm.getCode());
                else
                    td.addText(grp.getTarget() + " / " + ccm.getCode());
                display = getDisplayForConcept(grp.getTarget(), ccm.getCode());
                if (display != null)
                    td.tx(" (" + display + ")");
                for (String s : targets.keySet()) {
                    if (!s.equals("code")) {
                        td = tr.td();
                        td.addText(getCode(ccm.getProduct(), s, targets.get(s).size() != 1));
                        display = getDisplay(ccm.getProduct(), s);
                        if (display != null)
                            td.tx(" (" + display + ")");
                    }
                }
                if (comment)
                    tr.td().addText(ccm.getComment());
            }
        }
    }
    inject(cm, x, NarrativeStatus.GENERATED);
    return true;
}
Also used : HashMap(java.util.HashMap) Reference(org.hl7.fhir.dstu3.model.Reference) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) ContactDetail(org.hl7.fhir.dstu3.model.ContactDetail) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) OtherElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.OtherElementComponent) TargetElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent) HashSet(java.util.HashSet)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)60 UriType (org.hl7.fhir.r5.model.UriType)45 ArrayList (java.util.ArrayList)42 UriType (org.hl7.fhir.r4.model.UriType)41 UriType (org.hl7.fhir.r4b.model.UriType)29 UriType (org.hl7.fhir.dstu3.model.UriType)26 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)24 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)22 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)19 List (java.util.List)17 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 NotImplementedException (org.apache.commons.lang3.NotImplementedException)15 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)14 UriType (org.hl7.fhir.dstu2016may.model.UriType)12 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)12 Coding (org.hl7.fhir.r4.model.Coding)12 IOException (java.io.IOException)11 StringType (org.hl7.fhir.r4.model.StringType)10 org.hl7.fhir.r5.model (org.hl7.fhir.r5.model)10 StringType (org.hl7.fhir.r5.model.StringType)10