Search in sources :

Example 16 with Element

use of org.hl7.fhir.r4b.elementmodel.Element in project kindling by HL7.

the class ExampleInspector method fetch.

@Override
public Element fetch(IResourceValidator validator, Object appContext, String url) throws IOException, FHIRException {
    String[] parts = url.split("\\/");
    if (parts.length == 2 && definitions.hasResource(parts[0])) {
        ResourceDefn r = definitions.getResourceByName(parts[0]);
        for (Example e : r.getExamples()) {
            if (e.getElement() == null && e.hasXml()) {
                e.setElement(new org.hl7.fhir.r5.elementmodel.XmlParser(context).parse(e.getXml()));
                if (e.getElement().getProperty().getStructure().getBaseDefinition().contains("MetadataResource")) {
                    String urle = e.getElement().getChildValue("url");
                    String v = e.getElement().getChildValue("url");
                    if (urle != null && urle.startsWith("http://hl7.org/fhir") && !version.toCode().equals(v)) {
                        e.getElement().setChildValue("version", version.toCode());
                    }
                }
            }
            if (e.getElement() != null) {
                if (e.getElement().fhirType().equals("Bundle")) {
                    for (Base b : e.getElement().listChildrenByName("entry")) {
                        if (b.getChildByName("resource").hasValues()) {
                            Element res = (Element) b.getChildByName("resource").getValues().get(0);
                            if (res.fhirType().equals(parts[0]) && parts[1].equals(res.getChildValue("id"))) {
                                return res;
                            }
                        }
                    }
                } else if (e.getElement().fhirType().equals(parts[0]) && e.getId().equals(parts[1])) {
                    return e.getElement();
                }
            }
        }
        try {
            if (parts[0].equals("StructureDefinition"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(StructureDefinition.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("OperationDefinition"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(OperationDefinition.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("SearchParameter"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(SearchParameter.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("ValueSet"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(ValueSet.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("CodeSystem"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(CodeSystem.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
        } catch (Exception e) {
            return null;
        }
        return null;
    } else
        return null;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) ObjectConverter(org.hl7.fhir.r5.elementmodel.ObjectConverter) Example(org.hl7.fhir.definitions.model.Example) Element(org.hl7.fhir.r5.elementmodel.Element) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Base(org.hl7.fhir.r5.model.Base) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) ValidationException(org.everit.json.schema.ValidationException) MalformedURLException(java.net.MalformedURLException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 17 with Element

use of org.hl7.fhir.r4b.elementmodel.Element in project kindling by HL7.

the class BookMaker method fixReferences.

private void fixReferences(XhtmlNode parent, XhtmlNode node, String name) throws Exception {
    List<XhtmlNode> wantDelete = new ArrayList<XhtmlNode>();
    for (XhtmlNode child : node.getChildNodes()) {
        if (child.getNodeType() == NodeType.Element) {
            if ("index-only-no-book".equals(child.getAttribute("class")))
                wantDelete.add(child);
            else
                fixReferences(node, child, name);
        }
    }
    for (XhtmlNode c : wantDelete) node.getChildNodes().remove(c);
    if (node.getName().equals("a")) {
        if (node.getAttributes().containsKey("name")) {
            String lname = node.getAttributes().get("name");
            node.getAttributes().put("name", name + "." + lname);
        // System.out.println("found anchor "+name+"."+lname);
        } else if (node.getAttribute("href") != null || node.getAttributes().get("xlink:href") != null) {
            String s = node.getAttributes().get("href");
            if (s == null || s.length() == 0)
                s = node.getAttributes().get("xlink:href");
            if (s == null || s.length() == 0)
                throw new Error("empty \"href\" element in \"a\" tag around " + parent.allText());
            if (s.startsWith("#")) {
                s = "#" + name + "." + s.substring(1);
            } else if (s.startsWith("http:") || s.startsWith("https:") || s.startsWith("ftp:") || s.startsWith("mailto:")) {
            // s = s;
            } else {
                int i = s.indexOf('.');
                if (i == -1)
                    throw new Error("unable to understand ref: '" + s + "' on '" + node.allText() + "'");
                if (s.contains("#")) {
                    int j = s.indexOf('#');
                    s = "#" + s.substring(0, i) + "." + s.substring(j + 1);
                } else if (s.endsWith(".html")) {
                    s = "#" + s.substring(0, i);
                } else {
                    if (!s.endsWith(".zip") && !s.endsWith(".xsd") && !s.endsWith(".xml") && !s.endsWith(".json") && !s.endsWith(".png") && !s.endsWith(".xml") && !s.endsWith(".eap") && !s.endsWith(".xmi")) {
                        System.out.println("odd ref: " + s + " in " + node.allText());
                    // s = s;
                    } else {
                    // actually, what we want to do is do what?
                    // System.out.println("ref to remove: "+s+" in "+node.allText());
                    // Utilities.copyFile(new File(page.getFolders().dstDir+s), new File(targetBin+File.separatorChar+s));
                    // s = "http://hl7.org/documentcenter/public/standards/FHIR"+DSTU_PATH_PORTION+"/v"+page.getVersion()+"/"+s;
                    }
                }
            }
            node.getAttributes().put("href", s);
            if (s.startsWith("http") && parent != null && !node.allText().equals(s)) {
                node.addText(" (" + s + ") ");
            }
        // System.out.println("reference to "+s);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 18 with Element

use of org.hl7.fhir.r4b.elementmodel.Element in project kindling by HL7.

the class CDAGenerator method buildInfrastructureRoot.

private void buildInfrastructureRoot() throws DefinitionException {
    StructureDefinition sd = new StructureDefinition();
    sd.setId("InfrastructureRoot");
    sd.setUrl("http://hl7.org/fhir/cda/StructureDefinition/InfrastructureRoot");
    library.put(sd.getUrl(), sd);
    sd.setName("Base Type for all classes in the CDA structure");
    sd.setTitle("InfrastructureRoot");
    sd.setStatus(PublicationStatus.ACTIVE);
    sd.setExperimental(false);
    sd.setPublisher("HL7");
    sd.setDescription("Defines the base elements and attributes on all CDA elements (other than data types)");
    sd.setKind(StructureDefinitionKind.LOGICAL);
    sd.setType(sd.getUrl());
    sd.setAbstract(true);
    sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("urn:hl7-org:v3"));
    sd.setBaseDefinition("http://hl7.org/fhir/cda/StructureDefinition/ANY");
    sd.setDerivation(TypeDerivationRule.SPECIALIZATION);
    ElementDefinition edb = new ElementDefinition();
    edb.setPath(sd.getId());
    seePath(edb);
    edb.setMin(1);
    edb.setMax("*");
    edb.addType().setCode("Element");
    sd.getDifferential().getElement().add(edb);
    ElementDefinition ed = new ElementDefinition();
    ed.setPath("InfrastructureRoot.realmCode");
    seePath(ed);
    ed.setMin(0);
    ed.setMax("*");
    ed.setDefinition("When valued in an instance, this attribute signals the imposition of realm-specific constraints. The value of this attribute identifies the realm in question");
    ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/CS");
    sd.getDifferential().getElement().add(ed);
    ed = new ElementDefinition();
    ed.setPath("InfrastructureRoot.typeId");
    seePath(ed);
    ed.setMin(0);
    ed.setMax("1");
    ed.setDefinition("When valued in an instance, this attribute signals the imposition of constraints defined in an HL7-specified message type. This might be a common type (also known as CMET in the messaging communication environment), or content included within a wrapper. The value of this attribute provides a unique identifier for the type in question.");
    ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/II");
    sd.getDifferential().getElement().add(ed);
    ed = new ElementDefinition();
    ed.setPath("InfrastructureRoot.templateId");
    seePath(ed);
    ed.setMin(0);
    ed.setMax("*");
    ed.setDefinition("When valued in an instance, this attribute signals the imposition of a set of template-defined constraints. The value of this attribute provides a unique identifier for the templates in question");
    ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/II");
    sd.getDifferential().getElement().add(ed);
    new ProfileUtilities(null, null, null).setIds(sd, true);
    structures.add(sd);
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) UriType(org.hl7.fhir.r5.model.UriType)

Example 19 with Element

use of org.hl7.fhir.r4b.elementmodel.Element in project kindling by HL7.

the class CDAGenerator method checkType.

private void checkType(TypeRefComponent t) {
    String id = t.getWorkingCode();
    if (Utilities.existsInList(id, "string", "Element", "code", "boolean", "Resource"))
        return;
    for (StructureDefinition sd : structures) {
        if (sd.getId().equals(fix(id)))
            return;
    }
    if (id.equals("http://hl7.org/fhir/cda/StructureDefinition/PN") || id.equals("http://hl7.org/fhir/cda/StructureDefinition/ON"))
        t.setCode("http://hl7.org/fhir/cda/StructureDefinition/EN");
    else if (id.equals("NARRATIVE"))
        t.setCode("xhtml");
    else
        System.out.println("Unknown data type " + id);
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition)

Example 20 with Element

use of org.hl7.fhir.r4b.elementmodel.Element in project kindling by HL7.

the class CDAGenerator method processDataType.

private void processDataType(Element dt, String n, String p) throws FileNotFoundException, IOException, FHIRFormatError, DefinitionException {
    if (!Utilities.existsInList(n, "TYPE", "BN", "BIN", "CO", "UID", "OID", "UUID", "RUID", "URL", "ADXP", "ENXP", "PN", "TN", "ON", "RTO", "CAL", "CLCY", "SET", "LIST", "GLIST", "SLIST", "BAG", "HXIT", "HIST", "UVP", "NPPD", "PPD")) {
        if (n.equals("GTS"))
            n = "SXCM_TS";
        System.out.print(" " + n);
        StructureDefinition sd = new StructureDefinition();
        sd.setId(fix(n));
        sd.setUrl("http://hl7.org/fhir/cda/StructureDefinition/" + fix(n));
        library.put(sd.getUrl(), sd);
        sd.setName("V3 Data type " + n + " (" + dt.getAttribute("title") + ")");
        sd.setTitle(sd.getName());
        sd.setStatus(PublicationStatus.ACTIVE);
        sd.setExperimental(false);
        sd.setPublisher("HL7");
        sd.setDescription(getDefinition(dt));
        sd.setType(sd.getUrl());
        sd.setKind(StructureDefinitionKind.LOGICAL);
        sd.setAbstract("true".equals(dt.getAttribute("isAbstract")));
        sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("urn:hl7-org:v3"));
        Element derived = XMLUtil.getNamedChild(dt, "mif:derivedFrom");
        if (Utilities.existsInList(n, "ST", "ED", "TEL", "AD", "EN", "IVL_PQ", "IVL_INT", "TS")) {
            sd.setBaseDefinition("http://hl7.org/fhir/cda/StructureDefinition/ANY");
        } else if (Utilities.existsInList(n, "SXCM_TS")) {
            sd.setBaseDefinition("http://hl7.org/fhir/cda/StructureDefinition/TS");
        } else if (n.equals("PIVL_TS") || n.equals("EIVL_TS") || n.equals("IVL_TS")) {
            sd.setBaseDefinition("http://hl7.org/fhir/cda/StructureDefinition/SXCM_TS");
        } else if (derived != null) {
            sd.setBaseDefinition("http://hl7.org/fhir/cda/StructureDefinition/" + XMLUtil.getNamedChildAttribute(derived, "mif:targetDatatype", "name"));
        } else
            sd.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Element");
        sd.setDerivation(TypeDerivationRule.SPECIALIZATION);
        ElementDefinition edb = new ElementDefinition();
        edb.setPath(sd.getId());
        seePath(edb);
        edb.setMin(1);
        edb.setMax("*");
        edb.addType().setCode("Element");
        sd.getDifferential().getElement().add(edb);
        if (n.equals("ED"))
            addEDElements(sd.getDifferential().getElement());
        if (n.equals("SC"))
            copyAttributes(sd, getDefinition("CV"), "code", "codeSystem", "codeSystemVersion", "displayName");
        if (primitiveTypes.containsKey(n))
            addValueAttribute(sd.getDifferential().getElement(), n, primitiveTypes.get(n));
        if (n.equals("TS"))
            edb.addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-timeformat", new CodeType("YYYYMMDDHHMMSS.UUUU[+|-ZZzz]"));
        if (n.equals("TEL"))
            addValueAttribute(sd.getDifferential().getElement(), n, "uri");
        if (n.equals("SXCM_TS")) {
            addOperatorAttribute(sd.getDifferential().getElement(), "SXCM_TS");
            sd.setAbstract(true);
        }
        if (n.equals("AD")) {
            addParts(sd.getDifferential().getElement(), n, "delimiter", "country", "state", "county", "city", "postalCode", "streetAddressLine", "houseNumber", "houseNumberNumeric", "direction", "streetName", "streetNameBase", "streetNameType", "additionalLocator", "unitID", "unitType", "careOf", "censusTract", "deliveryAddressLine", "deliveryInstallationType", "deliveryInstallationArea", "deliveryInstallationQualifier", "deliveryMode", "deliveryModeIdentifier", "buildingNumberSuffix", "postBox", "precinct");
            addTextItem(sd.getDifferential().getElement(), n);
        }
        if (n.equals("EN")) {
            addParts(sd.getDifferential().getElement(), n, "delimiter", "family", "given", "prefix", "suffix");
            addTextItem(sd.getDifferential().getElement(), n);
        }
        List<Element> props = new ArrayList<Element>();
        XMLUtil.getNamedChildren(dt, "mif:property", props);
        for (Element prop : props) {
            processProperty(sd.getDifferential().getElement(), n, prop, p);
        }
        if (n.equals("TS") || n.equals("PQ"))
            addInclusiveAttribute(sd.getDifferential().getElement(), n);
        if (n.equals("CE") || n.equals("CV") || n.equals("CD"))
            addCDExtensions(sd.getDifferential().getElement(), n);
        new ProfileUtilities(null, null, null).setIds(sd, true);
        structures.add(sd);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) CodeType(org.hl7.fhir.r5.model.CodeType) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) UriType(org.hl7.fhir.r5.model.UriType)

Aggregations

Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)659 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)488 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)486 ArrayList (java.util.ArrayList)240 FHIRException (org.hl7.fhir.exceptions.FHIRException)162 Element (org.hl7.fhir.r5.elementmodel.Element)98 IOException (java.io.IOException)97 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)91 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)84 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)84 Element (org.w3c.dom.Element)74 JsonElement (com.google.gson.JsonElement)62 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)61 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)60 HashSet (java.util.HashSet)53 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)49 NamedElement (org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement)48 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)47 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)46 IndexedElement (org.hl7.fhir.validation.instance.utils.IndexedElement)43