Search in sources :

Example 1 with ValueSetComposeComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ValueSetComposeComponent in project gpconnect-demonstrator by nhsconnect.

the class ValueSetValidator method validateCode.

public Boolean validateCode(Coding code) {
    String systemUrl = code.getSystem();
    ValueSet valSet = loadValueSet(systemUrl);
    // Check Code System
    @SuppressWarnings("unused") ValueSetComposeComponent codeSys = valSet.getCompose();
    @SuppressWarnings("unused") List<ValueSet.ConceptReferenceComponent> concepts;
    return true;
}
Also used : ValueSet(org.hl7.fhir.dstu3.model.ValueSet) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent)

Example 2 with ValueSetComposeComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ValueSetComposeComponent in project bunsen by cerner.

the class ValueSets method expandValuesIterator.

private static Iterator<Value> expandValuesIterator(ValueSet valueSet) {
    List<Value> values = new ArrayList<>();
    ValueSetComposeComponent compose = valueSet.getCompose();
    for (ConceptSetComponent inclusion : compose.getInclude()) {
        for (ConceptReferenceComponent concept : inclusion.getConcept()) {
            Value value = new Value();
            value.setValueSetUri(valueSet.getUrl());
            value.setValueSetVersion(valueSet.getVersion());
            value.setSystem(inclusion.getSystem());
            value.setVersion(inclusion.getVersion());
            value.setValue(concept.getCode());
            values.add(value);
        }
    }
    return values.iterator();
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ArrayList(java.util.ArrayList) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Example 3 with ValueSetComposeComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ValueSetComposeComponent in project bunsen by cerner.

the class ValueSets method addToValueSet.

/**
 * Adds the given values to the given value set instance.
 */
private void addToValueSet(ValueSet valueSet, Dataset<Value> values) {
    ValueSetComposeComponent composeComponent = valueSet.getCompose();
    ConceptSetComponent currentInclusion = null;
    ConceptReferenceComponent concept = null;
    List<Value> sortedValues = values.sort("system", "version", "value").collectAsList();
    // Workaround for the decoder producing an immutable array by replacing it with a mutable one
    composeComponent.setInclude(new ArrayList<>(composeComponent.getInclude()));
    for (Value value : sortedValues) {
        if (currentInclusion == null || !value.getSystem().equals(currentInclusion.getSystem()) || !value.getVersion().equals(currentInclusion.getVersion())) {
            // Find a matching inclusion
            for (ConceptSetComponent candidate : composeComponent.getInclude()) {
                if (value.getSystem().equals(candidate.getSystem()) && value.getVersion().equals(candidate.getVersion())) {
                    currentInclusion = candidate;
                    // Workaround for the decoder producing an immutable array by replacing it with a
                    // mutable one
                    currentInclusion.setConcept(new ArrayList<>(currentInclusion.getConcept()));
                }
            }
            // No matching inclusion found, so add one
            if (currentInclusion == null) {
                currentInclusion = composeComponent.addInclude();
                currentInclusion.setSystem(value.getSystem());
                currentInclusion.setVersion(value.getVersion());
                concept = null;
            }
        }
        // Create concept if not exists
        if (concept == null || !value.getValue().equals(concept.getCode())) {
            concept = currentInclusion.addConcept();
            concept.setCode(value.getValue());
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Example 4 with ValueSetComposeComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ValueSetComposeComponent in project kindling by HL7.

the class ValueSetGenerator method genAbstractTypes.

private void genAbstractTypes(ValueSet vs) {
    if (!vs.hasCompose())
        vs.setCompose(new ValueSetComposeComponent());
    vs.getCompose().addInclude().setSystem("http://hl7.org/fhir/abstract-types");
    vs.setUserData("filename", "valueset-" + vs.getId());
    if (!vs.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
        vs.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType("fhir"));
    } else {
        String ec = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP);
        if (!ec.equals("fhir"))
            System.out.println("ValueSet " + vs.getUrl() + " WG mismatch 8: is " + ec + ", want to set to " + "fhir");
    }
    vs.setUserData("path", "valueset-" + vs.getId() + ".html");
    CodeSystem cs = new CodeSystem();
    cs.setUserData("filename", vs.getUserString("filename").replace("valueset-", "codesystem-"));
    cs.setUserData("path", vs.getUserString("path").replace("valueset-", "codesystem-"));
    CodeSystemConvertor.populate(cs, vs);
    cs.setUrl("http://hl7.org/fhir/abstract-types");
    cs.setVersion(version);
    cs.setCaseSensitive(true);
    cs.setContent(CodeSystemContentMode.COMPLETE);
    definitions.getCodeSystems().see(cs, packageInfo);
    cs.addConcept().setCode("Type").setDisplay("Type").setDefinition("A place holder that means any kind of data type");
    cs.addConcept().setCode("Any").setDisplay("Any").setDefinition("A place holder that means any kind of resource");
    markSpecialStatus(vs, cs, true);
}
Also used : CodeType(org.hl7.fhir.r5.model.CodeType) ValueSetComposeComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent) CodeSystem(org.hl7.fhir.r5.model.CodeSystem)

Example 5 with ValueSetComposeComponent

use of org.hl7.fhir.dstu2.model.ValueSet.ValueSetComposeComponent in project kindling by HL7.

the class ValueSetGenerator method genResourceTypes.

private void genResourceTypes(ValueSet vs) {
    if (!vs.hasCompose())
        vs.setCompose(new ValueSetComposeComponent());
    vs.getCompose().addInclude().setSystem("http://hl7.org/fhir/resource-types");
    vs.setUserData("filename", "valueset-" + vs.getId());
    if (!vs.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
        vs.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType("fhir"));
    } else {
        String ec = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP);
        if (!ec.equals("fhir"))
            System.out.println("ValueSet " + vs.getUrl() + " WG mismatch 7: is " + ec + ", want to set to " + "fhir");
    }
    vs.setUserData("path", "valueset-" + vs.getId() + ".html");
    CodeSystem cs = new CodeSystem();
    CodeSystemConvertor.populate(cs, vs);
    cs.setUrl("http://hl7.org/fhir/resource-types");
    cs.setVersion(version);
    cs.setCaseSensitive(true);
    cs.setContent(CodeSystemContentMode.COMPLETE);
    definitions.getCodeSystems().see(cs, packageInfo);
    List<String> codes = new ArrayList<String>();
    codes.addAll(definitions.getBaseResources().keySet());
    codes.addAll(definitions.getKnownResources().keySet());
    Collections.sort(codes);
    for (String s : codes) {
        DefinedCode rd = definitions.getKnownResources().get(s);
        ConceptDefinitionComponent c = cs.addConcept();
        Map<String, String> t;
        if (rd == null) {
            t = translator.translations(s);
            c.setCode(s);
            c.setDisplay(definitions.getBaseResources().get(s).getName());
            c.setDefinition((definitions.getBaseResources().get(s).isAbstract() ? "--- Abstract Type! ---" : "") + definitions.getBaseResources().get(s).getDefinition());
        } else {
            t = translator.translations(rd.getCode());
            c.setCode(rd.getCode());
            c.setDisplay(rd.getCode());
            c.setDefinition(rd.getDefinition());
        }
        if (t != null) {
            for (String l : t.keySet()) c.addDesignation().setLanguage(l).setValue(t.get(l)).getUse().setSystem("http://terminology.hl7.org/CodeSystem/designation-usage").setCode("display");
        }
    }
    markSpecialStatus(vs, cs, true);
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ArrayList(java.util.ArrayList) CodeType(org.hl7.fhir.r5.model.CodeType) ValueSetComposeComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent) CodeSystem(org.hl7.fhir.r5.model.CodeSystem)

Aggregations

ArrayList (java.util.ArrayList)8 ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)8 ValueSetComposeComponent (org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent)8 ValueSetComposeComponent (org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent)6 ValueSetComposeComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent)6 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)6 CodeType (org.hl7.fhir.r5.model.CodeType)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)5 HashMap (java.util.HashMap)4 ConceptReferenceComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)4 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)4 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)4 ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)3 ConceptReferenceComponent (org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)3 ConceptSetComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent)3