Search in sources :

Example 31 with ValueSet

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

the class ValueSetGenerator method loadOperationOutcomeValueSet.

public void loadOperationOutcomeValueSet(BindingSpecification cd) throws Exception {
    ValueSet vs = new ValueSet();
    cd.setValueSet(vs);
    cd.setBindingMethod(BindingMethod.ValueSet);
    vs.setId("operation-outcome");
    vs.setUrl("http://hl7.org/fhir/ValueSet/" + vs.getId());
    vs.setName("OperationOutcomeCodes");
    vs.setTitle("Operation Outcome Codes");
    vs.setPublisher("HL7 (FHIR Project)");
    vs.setVersion(version);
    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 11: is " + ec + ", want to set to " + "fhir");
    }
    vs.setUserData("path", "valueset-" + vs.getId() + ".html");
    ContactDetail c = vs.addContact();
    c.addTelecom().setSystem(ContactPointSystem.URL).setValue("http://hl7.org/fhir");
    c.addTelecom().setSystem(ContactPointSystem.EMAIL).setValue("fhir@lists.hl7.org");
    vs.setDescription("Operation Outcome codes used by FHIR test servers (see Implementation file translations.xml)");
    vs.setStatus(PublicationStatus.DRAFT);
    if (!vs.hasCompose())
        vs.setCompose(new ValueSetComposeComponent());
    vs.getCompose().addInclude().setSystem("http://terminology.hl7.org/CodeSystem/operation-outcome");
    CodeSystem cs = new CodeSystem();
    cs.setHierarchyMeaning(CodeSystemHierarchyMeaning.ISA);
    Set<String> codes = translator.listTranslations("ecode");
    for (String s : sorted(codes)) {
        Map<String, String> langs = translator.translations(s);
        ConceptDefinitionComponent cv = cs.addConcept();
        cv.setCode(s);
        cv.setDisplay(langs.get("en"));
        for (String lang : langs.keySet()) {
            if (!lang.equals("en")) {
                String value = langs.get(lang);
                ConceptDefinitionDesignationComponent dc = cv.addDesignation();
                dc.setLanguage(lang);
                dc.setValue(value);
                dc.getUse().setSystem("http://terminology.hl7.org/CodeSystem/designation-usage").setCode("display");
            }
        }
    }
    CodeSystemConvertor.populate(cs, vs);
    cs.setUrl("http://terminology.hl7.org/CodeSystem/operation-outcome");
    cs.setVersion(version);
    cs.setCaseSensitive(true);
    cs.setContent(CodeSystemContentMode.COMPLETE);
    definitions.getCodeSystems().see(cs, packageInfo);
}
Also used : ContactDetail(org.hl7.fhir.r5.model.ContactDetail) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) ConceptDefinitionDesignationComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionDesignationComponent) CodeType(org.hl7.fhir.r5.model.CodeType) ValueSet(org.hl7.fhir.r5.model.ValueSet) ValueSetComposeComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent) CodeSystem(org.hl7.fhir.r5.model.CodeSystem)

Example 32 with ValueSet

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

the class BindingsParser method loadValueSet.

private ValueSet loadValueSet(String ref, String committee) throws Exception {
    String folder = new File(filename).getParent();
    String srcName;
    IParser p;
    if (new File(Utilities.path(folder, ref + ".xml")).exists()) {
        p = new XmlParser();
        srcName = Utilities.path(folder, ref + ".xml");
    } else if (new File(Utilities.path(folder, ref + ".json")).exists()) {
        p = new JsonParser();
        srcName = Utilities.path(folder, ref + ".json");
    } else
        throw new Exception("Unable to find source for " + ref + " in " + filename + " (" + Utilities.path(folder, ref + ".xml/json)"));
    FileInputStream input = new FileInputStream(srcName);
    try {
        ValueSet result = ValueSetUtilities.makeShareable((ValueSet) p.parse(input));
        result.setId(ref.substring(9));
        if (!result.hasExperimental())
            result.setExperimental(false);
        // if (!result.hasUrl())
        result.setUrl("http://hl7.org/fhir/ValueSet/" + ref.substring(9));
        if (!result.hasVersion() || result.getUrl().startsWith("http://hl7.org/fhir"))
            result.setVersion(version);
        if (!Utilities.noString(committee)) {
            if (!result.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
                result.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee));
            } else {
                String ec = ToolingExtensions.readStringExtension(result, ToolingExtensions.EXT_WORKGROUP);
                if (!ec.equals(committee))
                    System.out.println("ValueSet " + result.getUrl() + " WG mismatch 1: is " + ec + ", want to set to " + committee);
            }
        }
        result.setUserData("filename", "valueset-" + ref.substring(9));
        result.setUserData("path", "valueset-" + ref.substring(9) + ".html");
        new CodeSystemConvertor(codeSystems).convert(p, result, srcName, packageInfo);
        return result;
    } finally {
        IOUtils.closeQuietly(input);
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) CodeSystemConvertor(org.hl7.fhir.definitions.parsers.CodeSystemConvertor) CodeType(org.hl7.fhir.r5.model.CodeType) File(java.io.File) ValueSet(org.hl7.fhir.r5.model.ValueSet) URISyntaxException(java.net.URISyntaxException) FileInputStream(java.io.FileInputStream) IParser(org.hl7.fhir.r5.formats.IParser) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 33 with ValueSet

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

the class OldSpreadsheetParser method readBindings.

// Adds bindings to global definition.bindings. Returns list of
// newly found bindings in the sheet.
private void readBindings(Sheet sheet) throws Exception {
    for (int row = 0; row < sheet.rows.size(); row++) {
        String bindingName = sheet.getColumn(row, "Binding Name");
    }
    ValueSetGenerator vsGen = new ValueSetGenerator(definitions, version.toCode(), genDate, context.translator(), packageInfo);
    for (int row = 0; row < sheet.rows.size(); row++) {
        String bindingName = sheet.getColumn(row, "Binding Name");
        // Ignore bindings whose name start with "!"
        if (Utilities.noString(bindingName) || bindingName.startsWith("!"))
            continue;
        // if (Character.isLowerCase(bindingName.charAt(0)))
        // throw new Exception("binding name "+bindingName+" is illegal - must start with a capital letter");
        BindingSpecification cd = new BindingSpecification(usageContext, bindingName, false);
        if (definitions != null)
            definitions.getAllBindings().add(cd);
        cd.setDefinition(Utilities.appendPeriod(sheet.getColumn(row, "Definition")));
        cd.setBindingMethod(BindingsParser.readBinding(sheet.getColumn(row, "Binding"), cd.getName() + " in " + folder));
        String ref = sheet.getColumn(row, "Reference");
        if (!cd.getBinding().equals(BindingMethod.Unbound) && Utilities.noString(ref))
            throw new Exception("binding " + cd.getName() + " is missing a reference");
        if (cd.getBinding() == BindingMethod.CodeList) {
            if (ref.startsWith("#valueset-"))
                throw new Exception("don't start code list references with #valueset-");
            cd.setValueSet(ValueSetUtilities.makeShareable(new ValueSet()));
            valuesets.add(cd.getValueSet());
            cd.getValueSet().setVersion(version.toCode());
            cd.getValueSet().setId(igSuffix(ig) + ref.substring(1));
            cd.getValueSet().setUrl("http://hl7.org/fhir/ValueSet/" + igSuffix(ig) + ref.substring(1));
            cd.getValueSet().setUserData("filename", "valueset-" + cd.getValueSet().getId());
            if (!cd.getValueSet().hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
                cd.getValueSet().addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee.getCode()));
            } else {
                String ec = ToolingExtensions.readStringExtension(cd.getValueSet(), ToolingExtensions.EXT_WORKGROUP);
                if (!ec.equals(committee))
                    System.out.println("ValueSet " + cd.getValueSet().getUrl() + " WG mismatch 3: is " + ec + ", want to set to " + committee.getCode());
            }
            if (ig != null) {
                cd.getValueSet().setUserDataINN(ToolResourceUtilities.NAME_RES_IG, ig);
                cd.getValueSet().setUserData("path", "valueset-" + cd.getValueSet().getId() + ".html");
            } else
                cd.getValueSet().setUserData("path", "valueset-" + cd.getValueSet().getId() + ".html");
            if (!cd.getValueSet().getUserData("path").equals(cd.getValueSet().getUserData("filename") + ".html"))
                throw new Exception("Mis-identified value set");
            if (!ref.startsWith("#"))
                throw new Exception("Error parsing binding " + cd.getName() + ": code list reference '" + ref + "' must started with '#'");
            Sheet cs = xls.getSheets().get(ref.substring(1));
            if (cs == null)
                throw new Exception("Error parsing binding " + cd.getName() + ": code list reference '" + ref + "' not resolved");
            vsGen.updateHeader(cd, cd.getValueSet());
            new CodeListToValueSetParser(cs, ref.substring(1), cd.getValueSet(), version.toCode(), codeSystems, maps, packageInfo).execute(sheet.getColumn(row, "v2"), checkV3Mapping(sheet.getColumn(row, "v3")), getIsUtg(bindingName));
        } else if (cd.getBinding() == BindingMethod.ValueSet) {
            if (ref.startsWith("http:"))
                // will sort this out later
                cd.setReference(sheet.getColumn(row, "Reference"));
            else
                cd.setValueSet(loadValueSet(ref));
        } else if (cd.getBinding() == BindingMethod.Special) {
            if ("#operation-outcome".equals(sheet.getColumn(row, "Reference")))
                new ValueSetGenerator(definitions, version.toCode(), genDate, context.translator(), packageInfo).loadOperationOutcomeValueSet(cd);
            else
                throw new Exception("Special bindings are only allowed in bindings.xml");
        }
        // do this anyway in the short term
        cd.setReference(sheet.getColumn(row, "Reference"));
        if (cd.getValueSet() != null) {
            ValueSet vs = cd.getValueSet();
            ValueSetUtilities.makeShareable(vs);
            vs.setUserData("filename", "valueset-" + vs.getId());
            if (!vs.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
                vs.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee.getCode()));
            } else {
                String ec = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP);
                if (!ec.equals(committee.getCode()))
                    System.out.println("ValueSet " + vs.getUrl() + " WG mismatch 4: is " + ec + ", want to set to " + committee.getCode());
            }
            if (ig != null) {
                vs.setUserDataINN(ToolResourceUtilities.NAME_RES_IG, ig);
                vs.setUserData("path", ig.getCode() + "/valueset-" + vs.getId() + ".html");
            } else
                vs.setUserData("path", "valueset-" + vs.getId() + ".html");
            if (!ValueSetUtilities.hasOID(vs))
                ValueSetUtilities.setOID(vs, "urn:oid:" + BindingSpecification.DEFAULT_OID_VS + registry.idForUri(vs.getUrl()));
            if (vs.getUserData("cs") != null) {
                if (!CodeSystemUtilities.hasOID((CodeSystem) vs.getUserData("cs")))
                    CodeSystemUtilities.setOID((CodeSystem) vs.getUserData("cs"), "urn:oid:" + BindingSpecification.DEFAULT_OID_CS + registry.idForUri(((CodeSystem) vs.getUserData("cs")).getUrl()));
            }
            if (definitions != null)
                definitions.getBoundValueSets().put(vs.getUrl(), vs);
            else
                ig.getValueSets().add(vs);
        } else if (cd.getReference() != null && cd.getReference().startsWith("http:")) {
            if (definitions != null)
                definitions.getUnresolvedBindings().add(cd);
            else
                ig.getUnresolvedBindings().add(cd);
        }
        cd.setDescription(sheet.getColumn(row, "Description"));
        if (!Utilities.noString(sheet.getColumn(row, "Example")))
            throw new Exception("The 'Example' column is no longer supported");
        if (!Utilities.noString(sheet.getColumn(row, "Extensible")))
            throw new Exception("The 'Extensible' column is no longer supported");
        cd.setStrength(BindingsParser.readBindingStrength(sheet.getColumn(row, "Conformance")));
        if (cd.getBinding() == BindingMethod.Unbound) {
            cd.setStrength(BindingStrength.EXAMPLE);
        }
        cd.setSource(name);
        cd.setUri(sheet.getColumn(row, "Uri"));
        String oid = sheet.getColumn(row, "Oid");
        if (!Utilities.noString(oid))
            // no cs oid in this case
            cd.setVsOid(oid);
        cd.setStatus(PublicationStatus.fromCode(sheet.getColumn(row, "Status")));
        cd.setWebSite(sheet.getColumn(row, "Website"));
        cd.setEmail(sheet.getColumn(row, "Email"));
        cd.setCopyright(sheet.getColumn(row, "Copyright"));
        cd.setV2Map(sheet.getColumn(row, "v2"));
        cd.setV3Map(checkV3Mapping(sheet.getColumn(row, "v3")));
        String max = sheet.getColumn(row, "Max");
        if (!Utilities.noString(max))
            if (max.startsWith("http:")) {
                // will sort this out later
                cd.setMaxReference(max);
            } else
                cd.setMaxValueSet(loadValueSet(max));
        bindings.put(cd.getName(), cd);
        if (cd.getValueSet() != null) {
            ValueSet vs = cd.getValueSet();
            vsGen.updateHeader(cd, cd.getValueSet());
        }
    }
}
Also used : CodeListToValueSetParser(org.hl7.fhir.definitions.parsers.CodeListToValueSetParser) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) CodeType(org.hl7.fhir.r5.model.CodeType) ValueSet(org.hl7.fhir.r5.model.ValueSet) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ValueSetGenerator(org.hl7.fhir.definitions.parsers.ValueSetGenerator) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 34 with ValueSet

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

the class SourceParser method loadValueSet.

private void loadValueSet(String n) throws FileNotFoundException, Exception {
    XmlParser xml = new XmlParser();
    ValueSet vs = (ValueSet) xml.parse(new CSFileInputStream(srcDir + ini.getStringProperty("valuesets", n).replace('\\', File.separatorChar)));
    new CodeSystemConvertor(definitions.getCodeSystems()).convert(xml, vs, srcDir + ini.getStringProperty("valuesets", n).replace('\\', File.separatorChar), page.packageInfo());
    vs.setId(FormatUtilities.makeId(n));
    vs.setUrl("http://hl7.org/fhir/ValueSet/" + vs.getId());
    if (!vs.hasVersion() || vs.getUrl().startsWith("http://hl7.org/fhir"))
        vs.setVersion(version.toCode());
    vs.setUserData("path", "valueset-" + vs.getId() + ".html");
    vs.setUserData("filename", "valueset-" + vs.getId());
    definitions.getExtraValuesets().put(n, vs);
    definitions.getExtraValuesets().put(vs.getUrl(), vs);
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) ValueSet(org.hl7.fhir.r5.model.ValueSet) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 35 with ValueSet

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

the class SourceParser method loadGlobalBindings.

private void loadGlobalBindings() throws Exception {
    logger.log("Load Common Bindings", LogMessageType.Process);
    BindingsParser parser = new BindingsParser(new CSFileInputStream(new CSFile(termDir + "bindings.xml")), termDir + "bindings.xml", srcDir, registry, version.toCode(), definitions.getCodeSystems(), page.getConceptMaps(), genDate, exceptionIfExcelNotNormalised, page.packageInfo());
    List<BindingSpecification> cds = parser.parse();
    for (BindingSpecification cd : cds) {
        definitions.getAllBindings().add(cd);
        definitions.getCommonBindings().put(cd.getName(), cd);
        if (cd.getValueSet() != null) {
            vsGen.updateHeader(cd, cd.getValueSet());
            definitions.getBoundValueSets().put(cd.getValueSet().getUrl(), cd.getValueSet());
        } else if (cd.getReference() != null && cd.getReference().startsWith("http:")) {
            definitions.getUnresolvedBindings().add(cd);
        }
        if (cd.getMaxValueSet() != null) {
            vsGen.updateHeader(cd, cd.getMaxValueSet());
            definitions.getBoundValueSets().put(cd.getMaxValueSet().getUrl(), cd.getMaxValueSet());
        }
    }
    if (!page.getDefinitions().getBoundValueSets().containsKey("http://hl7.org/fhir/ValueSet/data-absent-reason"))
        throw new Exception("d-a-r not found");
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) CSFile(org.hl7.fhir.utilities.CSFile) BindingsParser(org.hl7.fhir.definitions.parsers.spreadsheets.BindingsParser) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

ValueSet (org.hl7.fhir.r5.model.ValueSet)159 ValueSet (org.hl7.fhir.r4.model.ValueSet)116 Test (org.junit.jupiter.api.Test)115 ArrayList (java.util.ArrayList)101 FHIRException (org.hl7.fhir.exceptions.FHIRException)100 IOException (java.io.IOException)97 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)59 ValueSet (org.hl7.fhir.r4b.model.ValueSet)59 FileNotFoundException (java.io.FileNotFoundException)58 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)56 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)46 HashMap (java.util.HashMap)45 Test (org.junit.Test)45 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)43 File (java.io.File)36 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)36 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)29 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)29 FileInputStream (java.io.FileInputStream)27