Search in sources :

Example 6 with CD

use of org.hl7.v3.CD 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 7 with CD

use of org.hl7.v3.CD 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 8 with CD

use of org.hl7.v3.CD 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 9 with CD

use of org.hl7.v3.CD in project kindling by HL7.

the class SvgGenerator method drawElement.

private ClassItem drawElement(XMLWriter xml, String[] classNames) throws Exception {
    // classNames.length == 1 && classNames[0].equals("Base");
    boolean onlyElement = false;
    if (classNames != null) {
        for (String cn : classNames) {
            if (definitions.getPrimitives().containsKey(cn)) {
                DefinedCode cd = definitions.getPrimitives().get(cn);
                ElementDefn fake = fakes.get(cn);
                if (cd instanceof DefinedStringPattern) {
                    links.add(new Link(classes.get(fakes.get(((DefinedStringPattern) cd).getBase())), drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                } else {
                    ClassItem parent = classes.get(definitions.getElementDefn(version.isR4B() ? "Element" : "PrimitiveType"));
                    if (parent == null) {
                        drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
                    } else {
                        links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                    }
                }
            } else if ("xhtml".equals(cn)) {
                DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
                ElementDefn fake = fakes.get(cn);
                ClassItem parent = classes.get(definitions.getElementDefn(version.isR4B() ? "Element" : "DataType"));
                if (parent == null) {
                    drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
                } else {
                    links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                }
            } else if (definitions.getConstraints().containsKey(cn)) {
                ProfiledType cd = definitions.getConstraints().get(cn);
                ElementDefn fake = fakes.get(cn);
                ClassItem parent = classes.get(definitions.getElementDefn(cd.getBaseType()));
                links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, null, StandardsStatus.NORMATIVE), LinkType.CONSTRAINT, null, null, PointKind.unknown, null, null));
            } else if (definitions.getPrimitives().containsKey(cn)) {
                DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
                ElementDefn fake = fakes.get(cn);
                // links.add(new Link(item,
                // , LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
            } else if (!onlyElement) {
                ElementDefn e = definitions.getElementDefn(cn);
                ClassItem parent = Utilities.noString(e.typeCode()) ? null : classes.get(definitions.getElementDefn(e.typeCode()));
                if (parent == null) {
                    drawClass(xml, e, false, null, true, cn, null, e.getStandardsStatus());
                } else {
                    links.add(new Link(parent, drawClass(xml, e, false, null, true, cn, null, e.getStandardsStatus()), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                }
            }
        }
    }
    return null;
}
Also used : DefinedStringPattern(org.hl7.fhir.definitions.model.DefinedStringPattern) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 10 with CD

use of org.hl7.v3.CD in project kindling by HL7.

the class SvgGenerator method determineMetrics.

private Point determineMetrics(String[] classNames) throws Exception {
    double width = textWidth("Element") * 1.8;
    double height = HEADER_HEIGHT + GAP_HEIGHT * 2;
    // if ("true".equals(ini.getStringProperty("diagram", "element-attributes"))) {
    // height = height + LINE_HEIGHT + GAP_HEIGHT;
    // width = textWidth("extension : Extension 0..*");
    // }
    Point p = new Point(0, 0, PointKind.unknown);
    ClassItem item = new ClassItem(p.x, p.y, width, height, id);
    classes.put(null, item);
    double x = item.right() + MARGIN_X;
    double y = item.bottom() + MARGIN_Y;
    if (classNames != null) {
        for (String cn : classNames) {
            if (definitions.getPrimitives().containsKey(cn)) {
                DefinedCode cd = definitions.getPrimitives().get(cn);
                ElementDefn fake = new ElementDefn();
                fake.setName(cn);
                fakes.put(cn, fake);
                if (cd instanceof DefinedStringPattern)
                    p = determineMetrics(fake, classes.get(fakes.get(((DefinedStringPattern) cd).getBase())), cn, false, cd);
                else
                    p = determineMetrics(fake, item, cn, false, cd);
            } else if ("xhtml".equals(cn)) {
                ElementDefn fake = new ElementDefn();
                fake.setName("xhtml");
                fakes.put("xhtml", fake);
                DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
                p = determineMetrics(fake, item, cn, false, cd);
            } else if (definitions.getConstraints().containsKey(cn)) {
                ProfiledType cd = definitions.getConstraints().get(cn);
                ElementDefn ed = definitions.getElementDefn(cd.getBaseType());
                ClassItem parentClss = classes.get(ed);
                ElementDefn fake = new ElementDefn();
                fake.setName(cn);
                fakes.put(cn, fake);
                p = determineMetrics(fake, parentClss, cn, false, null);
            } else {
                ElementDefn c = definitions.getElementDefn(cn);
                p = determineMetrics(c, item, c.getName(), false, null);
            }
            x = Math.max(x, p.x + MARGIN_X);
            y = Math.max(y, p.y + MARGIN_Y);
        }
    }
    return new Point(x, y, PointKind.unknown);
}
Also used : DefinedStringPattern(org.hl7.fhir.definitions.model.DefinedStringPattern) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Aggregations

ArrayList (java.util.ArrayList)24 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 Coding (org.hl7.fhir.r4.model.Coding)10 ValueSet (org.hl7.fhir.r5.model.ValueSet)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)9 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 CD (net.ihe.gazelle.hl7v3.datatypes.CD)7 CS (net.ihe.gazelle.hl7v3.datatypes.CS)7 II (net.ihe.gazelle.hl7v3.datatypes.II)7 TS (net.ihe.gazelle.hl7v3.datatypes.TS)7 MCCIMT000100UV01Device (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Device)7 MCCIMT000100UV01Receiver (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Receiver)7 MCCIMT000100UV01Sender (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Sender)7 Identifier (org.hl7.fhir.r4.model.Identifier)7 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)7 IOException (java.io.IOException)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 ContactDetail (org.hl7.fhir.r5.model.ContactDetail)5