Search in sources :

Example 61 with Value

use of org.hl7.fhir.utilities.graphql.Value 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 62 with Value

use of org.hl7.fhir.utilities.graphql.Value 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 63 with Value

use of org.hl7.fhir.utilities.graphql.Value in project kindling by HL7.

the class OldSpreadsheetParser method checkW5.

private String checkW5(String value, String path) throws Exception {
    if (Utilities.noString(value))
        return null;
    if (!definitions.getW5s().containsKey(value)) {
        if (!value.contains(".")) {
            throw new Exception("Unknown w5 value " + value + " at " + path);
        } else {
            String[] vs = value.split("\\.");
            if (vs.length != 2)
                throw new Exception("improper w5 value " + value + " at " + path);
            if (!definitions.getW5s().containsKey(vs[0]))
                throw new Exception("Unknown w5 value " + value + " at " + path);
            W5Entry w5 = definitions.getW5s().get(vs[0]);
            if (!w5.getSubClasses().contains(vs[1]))
                throw new Exception("Unknown w5 value " + value + " at " + path);
        }
    }
    return value;
}
Also used : W5Entry(org.hl7.fhir.definitions.model.W5Entry) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 64 with Value

use of org.hl7.fhir.utilities.graphql.Value in project kindling by HL7.

the class OldSpreadsheetParser method parseConformancePackage.

public void parseConformancePackage(Profile ap, Definitions definitions, String folder, String usage, List<ValidationMessage> issues, WorkGroup wg) throws Exception {
    try {
        isProfile = true;
        this.folder = folder;
        checkMappings(ap);
        Sheet sheet = loadSheet("Bindings");
        if (sheet != null)
            readBindings(sheet);
        sheet = loadSheet("Metadata");
        for (int row = 0; row < sheet.rows.size(); row++) {
            String n = sheet.getColumn(row, "Name");
            String v = sheet.getColumn(row, "Value");
            if (n != null && v != null) {
                if (ap.getMetadata().containsKey(n))
                    ap.getMetadata().get(n).add(v);
                else {
                    ArrayList<String> vl = new ArrayList<String>();
                    vl.add(v);
                    ap.getMetadata().put(n, vl);
                }
            }
        }
        if (!Utilities.noString(ap.metadata("category")))
            usage = ap.metadata("category");
        if (ap.hasMetadata("name"))
            ap.setTitle(ap.metadata("name"));
        if (ap.hasMetadata("introduction"))
            ap.setIntroduction(Utilities.path(folder, ap.metadata("introduction")));
        if (ap.hasMetadata("notes"))
            ap.setNotes(Utilities.path(folder, ap.metadata("notes")));
        if (!ap.hasMetadata("id"))
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " no 'id' found in metadata");
        if (!ap.metadata("id").matches(FormatUtilities.ID_REGEX))
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " 'id' is not a valid id");
        if (wg == null)
            wg = workgroups.get(ap.metadata("workgroup"));
        if (wg == null)
            wg = committee;
        if (wg == null)
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " : no workgroup value in the metadata");
        if (!ap.metadata("id").equals(ap.metadata("id").toLowerCase()))
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " 'id' must be all lowercase");
        this.profileExtensionBase = ap.metadata("extension.uri");
        if (ig == null || ig.isCore()) {
            if (!profileExtensionBase.startsWith("http://hl7.org/fhir/StructureDefinition/") && !profileExtensionBase.startsWith("http://fhir-registry.smarthealthit.org/StructureDefinition/"))
                throw new Exception("Core extensions must have a url starting with http://hl7.org/fhir/StructureDefinition/ for " + ap.getId());
        } else {
            if (!profileExtensionBase.startsWith("http://hl7.org/fhir/StructureDefinition/" + ig.getCode() + "-"))
                throw new Exception("Core extensions must have a url starting with http://hl7.org/fhir/StructureDefinition/" + ig.getCode() + "- for " + ap.getId());
        }
        Map<String, Invariant> invariants = null;
        sheet = loadSheet("Extensions-Inv");
        if (sheet != null) {
            invariants = readInvariants(sheet, "", "Extensions-Inv");
        }
        sheet = loadSheet("Extensions");
        if (sheet != null) {
            int row = 0;
            while (row < sheet.rows.size()) {
                if (sheet.getColumn(row, "Code").startsWith("!"))
                    row++;
                else
                    row = processExtension(null, sheet, row, definitions, ap.metadata("extension.uri"), ap, issues, invariants, wg);
            }
        }
        List<String> namedSheets = new ArrayList<String>();
        if (ap.getMetadata().containsKey("published.structure")) {
            for (String n : ap.getMetadata().get("published.structure")) {
                if (!Utilities.noString(n)) {
                    if (ig != null && !ig.isCore() && !n.toLowerCase().startsWith(ig.getCode() + "-"))
                        throw new Exception("Error: published structure names must start with the implementation guide code (" + ig.getCode() + "-)");
                    String fmm = ap.metadata("fmm-" + n);
                    if (Utilities.noString(fmm))
                        fmm = ap.metadata("fmm");
                    if (Utilities.noString(fmm))
                        // default fmm value
                        fmm = "1";
                    ap.getProfiles().add(parseProfileSheet(definitions, ap, n, namedSheets, true, usage, issues, wg, fmm));
                }
            }
        }
        int i = 0;
        while (i < namedSheets.size()) {
            String fmm = ap.metadata("fmm-" + namedSheets.get(i));
            if (Utilities.noString(fmm))
                fmm = ap.metadata("fmm");
            if (Utilities.noString(fmm))
                // default fmm value
                fmm = "1";
            ap.getProfiles().add(parseProfileSheet(definitions, ap, namedSheets.get(i), namedSheets, false, usage, issues, wg, fmm));
            i++;
        }
        if (namedSheets.isEmpty() && xls.getSheets().containsKey("Search"))
            readSearchParams(ap, xls.getSheets().get("Search"), this.profileExtensionBase);
        if (xls.getSheets().containsKey("Operations"))
            readOperations(ap.getOperations(), loadSheet("Operations"));
    } catch (Exception e) {
        throw new Exception("exception parsing pack " + ap.getSource() + ": " + e.getMessage(), e);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ArrayList(java.util.ArrayList) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 65 with Value

use of org.hl7.fhir.utilities.graphql.Value in project kindling by HL7.

the class SpreadSheetReloader method parseBinding.

private void parseBinding(OperationDefinitionParameterComponent param, String value, XSSFSheet bindings) {
    if (Utilities.noString(value)) {
        param.setBinding(null);
    } else {
        XSSFRow cols = bindings.getRow(0);
        XSSFRow row = lookupRow(bindings, cols, CN_BINDING_NAME, value);
        if (row == null) {
            throw new FHIRException("Unable to find binding " + value + " in " + xlsx);
        }
        OperationDefinitionParameterBindingComponent bs = param.getBinding();
        bs.removeExtension(BuildExtensions.EXT_NAME);
        readExt(bs, row, cols, CN_BINDING_NAME, BuildExtensions.EXT_BINDING_NAME, ExtensionType.String);
        readExt(bs, row, cols, CN_DEFINITION, BuildExtensions.EXT_DEFINITION, ExtensionType.String);
        bs.setStrength(BindingStrength.fromCode(getValue(row, cols, CN_STRENGTH)));
        bs.setValueSet(getValue(row, cols, CN_VALUE_SET));
        readExt(bs, row, cols, CN_OID, BuildExtensions.EXT_VS_OID, ExtensionType.String);
        readExt(bs, row, cols, CN_URI, BuildExtensions.EXT_URI, ExtensionType.String);
        readExt(bs, row, cols, CN_WEBSITE_EMAIL, BuildExtensions.EXT_WEBSITE, ExtensionType.Uri);
        readExt(bs, row, cols, CN_V2, BuildExtensions.EXT_V2_MAP, ExtensionType.String);
        readExt(bs, row, cols, CN_V3, BuildExtensions.EXT_V3_MAP, ExtensionType.String);
        readExt(bs, row, cols, CN_COPYRIGHT, BuildExtensions.EXT_COPYRIGHT, ExtensionType.String);
        readExt(bs, row, cols, CN_COMMITTEE_NOTES, BuildExtensions.EXT_COMMITTEE_NOTES, ExtensionType.Markdown);
    }
}
Also used : XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) OperationDefinitionParameterBindingComponent(org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

Test (org.junit.jupiter.api.Test)222 ArrayList (java.util.ArrayList)183 FHIRException (org.hl7.fhir.exceptions.FHIRException)107 List (java.util.List)97 DisplayName (org.junit.jupiter.api.DisplayName)96 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)89 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)85 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)70 Identifier (org.hl7.fhir.r4.model.Identifier)69 Test (org.junit.Test)66 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)64 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)54 IOException (java.io.IOException)52 Bundle (org.hl7.fhir.r4.model.Bundle)49 Coding (org.hl7.fhir.r4.model.Coding)49 ValueSet (org.hl7.fhir.r5.model.ValueSet)48 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)46 Resource (org.hl7.fhir.r4.model.Resource)46 BigDecimal (java.math.BigDecimal)45 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)44