Search in sources :

Example 6 with BindingSpecification

use of org.hl7.fhir.definitions.model.BindingSpecification 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 7 with BindingSpecification

use of org.hl7.fhir.definitions.model.BindingSpecification 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)

Example 8 with BindingSpecification

use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.

the class ResourceParser method parseBinding.

public BindingSpecification parseBinding(ElementDefinitionBindingComponent binding) throws IOException {
    BindingSpecification bs = new BindingSpecification("core", binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName"), "true".equals(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding")));
    bs.setStrength(binding.getStrength());
    bs.setBindingMethod(BindingMethod.ValueSet);
    bs.setDescription(binding.getDescription());
    bs.setReference(binding.getValueSet());
    if (bs.hasReference()) {
        bs.setValueSet(loadValueSet(bs.getReference(), false));
    }
    if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet")) {
        bs.setMaxReference(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"));
        bs.setMaxValueSet(loadValueSet(bs.getMaxReference(), false));
    }
    if (binding.hasExtension(BuildExtensions.EXT_V2_MAP)) {
        bs.setV2Map(binding.getExtensionString(BuildExtensions.EXT_V2_MAP));
    }
    if (binding.hasExtension(BuildExtensions.EXT_V3_MAP)) {
        bs.setV3Map(binding.getExtensionString(BuildExtensions.EXT_V3_MAP));
    }
    if (binding.hasExtension(BuildExtensions.EXT_DEFINITION)) {
        bs.setDefinition(binding.getExtensionString(BuildExtensions.EXT_DEFINITION));
    }
    if (binding.hasExtension(BuildExtensions.EXT_URI)) {
        bs.setUri(binding.getExtensionString(BuildExtensions.EXT_URI));
    }
    if (binding.hasExtension(BuildExtensions.EXT_WEBSITE)) {
        bs.setWebSite(binding.getExtensionString(BuildExtensions.EXT_WEBSITE));
    }
    if (binding.hasExtension(BuildExtensions.EXT_EMAIL)) {
        bs.setEmail(binding.getExtensionString(BuildExtensions.EXT_EMAIL));
    }
    if (binding.hasExtension(BuildExtensions.EXT_COPYRIGHT)) {
        bs.setCopyright(binding.getExtensionString(BuildExtensions.EXT_COPYRIGHT));
    }
    if (binding.hasExtension(BuildExtensions.EXT_CS_OID)) {
        bs.setCsOid(binding.getExtensionString(BuildExtensions.EXT_CS_OID));
    }
    if (binding.hasExtension(BuildExtensions.EXT_VS_OID)) {
        bs.setVsOid(binding.getExtensionString(BuildExtensions.EXT_VS_OID));
    }
    if (binding.hasExtension(BuildExtensions.EXT_STATUS)) {
        bs.setStatus(PublicationStatus.fromCode(binding.getExtensionString(BuildExtensions.EXT_STATUS)));
    }
    return bs;
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification)

Example 9 with BindingSpecification

use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.

the class ResourceParser method parseBinding.

private BindingSpecification parseBinding(OperationDefinitionParameterBindingComponent binding) throws IOException {
    BindingSpecification bs = new BindingSpecification("core", binding.getExtensionString(BuildExtensions.EXT_BINDING_NAME), "true".equals(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding")));
    bs.setStrength(binding.getStrength());
    bs.setBindingMethod(BindingMethod.ValueSet);
    bs.setReference(binding.getValueSet());
    if (bs.hasReference()) {
        bs.setValueSet(loadValueSet(bs.getReference(), false));
    }
    if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet")) {
        bs.setMaxReference(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"));
        bs.setMaxValueSet(loadValueSet(bs.getMaxReference(), false));
    }
    if (binding.hasExtension(BuildExtensions.EXT_V2_MAP)) {
        bs.setV2Map(binding.getExtensionString(BuildExtensions.EXT_V2_MAP));
    }
    if (binding.hasExtension(BuildExtensions.EXT_V3_MAP)) {
        bs.setV3Map(binding.getExtensionString(BuildExtensions.EXT_V3_MAP));
    }
    if (binding.hasExtension(BuildExtensions.EXT_DEFINITION)) {
        bs.setDefinition(binding.getExtensionString(BuildExtensions.EXT_DEFINITION));
    }
    if (binding.hasExtension(BuildExtensions.EXT_URI)) {
        bs.setUri(binding.getExtensionString(BuildExtensions.EXT_URI));
    }
    if (binding.hasExtension(BuildExtensions.EXT_WEBSITE)) {
        bs.setWebSite(binding.getExtensionString(BuildExtensions.EXT_WEBSITE));
    }
    if (binding.hasExtension(BuildExtensions.EXT_EMAIL)) {
        bs.setEmail(binding.getExtensionString(BuildExtensions.EXT_EMAIL));
    }
    if (binding.hasExtension(BuildExtensions.EXT_COPYRIGHT)) {
        bs.setCopyright(binding.getExtensionString(BuildExtensions.EXT_COPYRIGHT));
    }
    if (binding.hasExtension(BuildExtensions.EXT_CS_OID)) {
        bs.setCsOid(binding.getExtensionString(BuildExtensions.EXT_CS_OID));
    }
    if (binding.hasExtension(BuildExtensions.EXT_VS_OID)) {
        bs.setVsOid(binding.getExtensionString(BuildExtensions.EXT_VS_OID));
    }
    if (binding.hasExtension(BuildExtensions.EXT_STATUS)) {
        bs.setStatus(PublicationStatus.fromCode(binding.getExtensionString(BuildExtensions.EXT_STATUS)));
    }
    return bs;
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification)

Example 10 with BindingSpecification

use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.

the class TerminologyNotesGenerator method scan.

private void scan(ElementDefn e, String path) throws Exception {
    if (e.hasBinding()) {
        BindingSpecification cd = e.getBinding();
        if (!txusages.containsKey(cd)) {
            txusages.put(cd, new ArrayList<CDUsage>());
            c++;
            txusages.get(cd).add(new CDUsage(String.valueOf(c), null));
        }
        txusages.get(cd).add(new CDUsage(path, e));
    }
    for (ElementDefn c : e.getElements()) {
        scan(c, path + "." + c.getName());
    }
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Aggregations

BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)20 ValueSet (org.hl7.fhir.r5.model.ValueSet)13 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)10 ArrayList (java.util.ArrayList)8 TypeRef (org.hl7.fhir.definitions.model.TypeRef)6 FHIRException (org.hl7.fhir.exceptions.FHIRException)6 IOException (java.io.IOException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 CodeType (org.hl7.fhir.r5.model.CodeType)4 FileNotFoundException (java.io.FileNotFoundException)3 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)3 CSFile (org.hl7.fhir.utilities.CSFile)3 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 TransformerException (javax.xml.transform.TransformerException)2 DefinedCode (org.hl7.fhir.definitions.model.DefinedCode)2 Invariant (org.hl7.fhir.definitions.model.Invariant)2 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)2 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)2