Search in sources :

Example 31 with ValueSetExpansionComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetRenderer method generateContentModeNotice.

private void generateContentModeNotice(XhtmlNode x, ValueSetExpansionComponent expansion, String mode, String text) {
    Multimap<String, String> versions = HashMultimap.create();
    for (ValueSetExpansionParameterComponent p : expansion.getParameter()) {
        if (p.getName().equals(mode)) {
            String[] parts = ((PrimitiveType) p.getValue()).asStringValue().split("\\|");
            if (parts.length == 2)
                versions.put(parts[0], parts[1]);
        }
    }
    if (versions.size() > 0) {
        XhtmlNode div = null;
        XhtmlNode ul = null;
        boolean first = true;
        for (String s : versions.keySet()) {
            if (versions.size() == 1 && versions.get(s).size() == 1) {
                for (String v : versions.get(s)) {
                    // though there'll only be one
                    XhtmlNode p = x.para().style("border: black 1px dotted; background-color: #ffcccc; padding: 8px; margin-bottom: 8px");
                    p.tx(text + " ");
                    expRef(p, s, v);
                }
            } else {
                for (String v : versions.get(s)) {
                    if (first) {
                        div = x.div().style("border: black 1px dotted; background-color: #EEEEEE; padding: 8px; margin-bottom: 8px");
                        div.para().tx(text + "s: ");
                        ul = div.ul();
                        first = false;
                    }
                    expRef(ul.li(), s, v);
                }
            }
        }
    }
}
Also used : ValueSetExpansionParameterComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 32 with ValueSetExpansionComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetRenderer method generateVersionNotice.

@SuppressWarnings("rawtypes")
private void generateVersionNotice(XhtmlNode x, ValueSetExpansionComponent expansion) {
    Multimap<String, String> versions = HashMultimap.create();
    for (ValueSetExpansionParameterComponent p : expansion.getParameter()) {
        if (p.getName().equals("version")) {
            String[] parts = ((PrimitiveType) p.getValue()).asStringValue().split("\\|");
            if (parts.length == 2)
                versions.put(parts[0], parts[1]);
        }
    }
    if (versions.size() > 0) {
        XhtmlNode div = null;
        XhtmlNode ul = null;
        boolean first = true;
        for (String s : versions.keySet()) {
            if (versions.size() == 1 && versions.get(s).size() == 1) {
                for (String v : versions.get(s)) {
                    // though there'll only be one
                    XhtmlNode p = x.para().style("border: black 1px dotted; background-color: #EEEEEE; padding: 8px; margin-bottom: 8px");
                    p.tx("Expansion based on ");
                    expRef(p, s, v);
                }
            } else {
                for (String v : versions.get(s)) {
                    if (first) {
                        div = x.div().style("border: black 1px dotted; background-color: #EEEEEE; padding: 8px; margin-bottom: 8px");
                        div.para().tx("Expansion based on: ");
                        ul = div.ul();
                        first = false;
                    }
                    expRef(ul.li(), s, v);
                }
            }
        }
    }
}
Also used : ValueSetExpansionParameterComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 33 with ValueSetExpansionComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetRenderer method getConceptsForCodes.

private Map<String, ConceptDefinitionComponent> getConceptsForCodes(CodeSystem e, ConceptSetComponent inc) {
    if (e == null) {
        e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
    }
    ValueSetExpansionComponent vse = null;
    if (!context.isNoSlowLookup() && !getContext().getWorker().hasCache()) {
        try {
            ValueSetExpansionOutcome vso = getContext().getWorker().expandVS(inc, false, false);
            ValueSet valueset = vso.getValueset();
            if (valueset == null)
                throw new TerminologyServiceException("Error Expanding ValueSet: " + vso.getError());
            vse = valueset.getExpansion();
        } catch (TerminologyServiceException e1) {
            return null;
        }
    }
    Map<String, ConceptDefinitionComponent> results = new HashMap<>();
    List<CodingValidationRequest> serverList = new ArrayList<>();
    // 1st pass, anything we can resolve internally
    for (ConceptReferenceComponent cc : inc.getConcept()) {
        String code = cc.getCode();
        ConceptDefinitionComponent v = null;
        if (e != null) {
            v = getConceptForCode(e.getConcept(), code);
        }
        if (v == null && vse != null) {
            v = getConceptForCodeFromExpansion(vse.getContains(), code);
        }
        if (v != null) {
            results.put(code, v);
        } else {
            serverList.add(new CodingValidationRequest(new Coding(inc.getSystem(), code, null)));
        }
    }
    if (!context.isNoSlowLookup() && !serverList.isEmpty()) {
        getContext().getWorker().validateCodeBatch(getContext().getTerminologyServiceOptions(), serverList, null);
        for (CodingValidationRequest vr : serverList) {
            ConceptDefinitionComponent v = vr.getResult().asConceptDefinition();
            if (v != null) {
                results.put(vr.getCoding().getCode(), v);
            }
        }
    }
    return results;
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) Coding(org.hl7.fhir.r5.model.Coding) ValueSetExpansionOutcome(org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.r5.model.ValueSet) CodingValidationRequest(org.hl7.fhir.r5.context.IWorkerContext.CodingValidationRequest)

Example 34 with ValueSetExpansionComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent 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.getName());
    vs.setStatus(PublicationStatus.ACTIVE);
    vs.setExpansion(new ValueSetExpansionComponent());
    vs.getExpansion().setIdentifier(Factory.createUUID());
    vs.getExpansion().setTimestampElement(DateTimeType.now());
    for (TypeRefComponent t : types) {
        ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
        if (t.getCode().equals("Reference") && (t.hasTargetProfile() && t.getTargetProfile().startsWith("http://hl7.org/fhir/StructureDefinition/"))) {
            cc.setCode(t.getTargetProfile().substring(40));
            cc.setSystem("http://hl7.org/fhir/resource-types");
            cc.setDisplay(cc.getCode());
        } else {
            ProfileUtilities pu = new ProfileUtilities(context, null, null);
            StructureDefinition ps = null;
            if (t.hasTargetProfile())
                ps = pu.getProfile(profile, t.getTargetProfile());
            else if (t.hasProfile())
                ps = pu.getProfile(profile, t.getProfile());
            if (ps != null) {
                cc.setCode(t.getTargetProfile());
                cc.setDisplay(ps.getType());
                cc.setSystem("http://hl7.org/fhir/resource-types");
            } else {
                cc.setCode(t.getCode());
                cc.setDisplay(t.getCode());
                cc.setSystem("http://hl7.org/fhir/data-types");
            }
        }
        t.setUserData("text", cc.getCode());
    }
    return vs;
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent) ProfileUtilities(org.hl7.fhir.dstu3.conformance.ProfileUtilities) ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Example 35 with ValueSetExpansionComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method getConceptForCode.

private ConceptDefinitionComponent getConceptForCode(CodeSystem e, String code, ConceptSetComponent inc) {
    // first, look in the code systems
    if (e == null)
        e = context.fetchCodeSystem(inc.getSystem());
    if (e != null) {
        ConceptDefinitionComponent v = getConceptForCode(e.getConcept(), code);
        if (v != null)
            return v;
    }
    if (!context.hasCache()) {
        ValueSetExpansionComponent vse;
        try {
            ValueSetExpansionOutcome vso = context.expandVS(inc, false);
            ValueSet valueset = vso.getValueset();
            if (valueset == null)
                throw new TerminologyServiceException("Error Expanding ValueSet: " + vso.getError());
            vse = valueset.getExpansion();
        } catch (TerminologyServiceException e1) {
            return null;
        }
        if (vse != null) {
            ConceptDefinitionComponent v = getConceptForCodeFromExpansion(vse.getContains(), code);
            if (v != null)
                return v;
        }
    }
    return context.validateCode(terminologyServiceOptions, inc.getSystem(), code, null).asConceptDefinition();
}
Also used : ValueSetExpansionOutcome(org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.r4.model.ValueSet)

Aggregations

UriType (org.hl7.fhir.r4b.model.UriType)7 ValueSetExpansionParameterComponent (org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionParameterComponent)7 UriType (org.hl7.fhir.r5.model.UriType)7 ValueSetExpansionParameterComponent (org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent)7 ArrayList (java.util.ArrayList)6 ValueSet (org.hl7.fhir.r4.model.ValueSet)5 ValueSetExpansionComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent)5 ValueSetExpansionContainsComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent)5 ValueSet (org.hl7.fhir.r4b.model.ValueSet)5 ValueSet (org.hl7.fhir.r5.model.ValueSet)5 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)4 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)4 HashMap (java.util.HashMap)3 List (java.util.List)2 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)2 ValueSet (org.hl7.fhir.dstu2016may.model.ValueSet)2 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)2 CodeSystem (org.hl7.fhir.r4b.model.CodeSystem)2 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)2 Extension (org.hl7.fhir.r4b.model.Extension)2