Search in sources :

Example 1 with FHIRFormatError

use of org.hl7.fhir.exceptions.FHIRFormatError in project kindling by HL7.

the class SpecNPMPackageGenerator method makeResourceList5.

private List<ResourceEntry> makeResourceList5(Map<String, byte[]> files, String version, List<ResourceEntry> res) throws FHIRFormatError, IOException {
    for (String k : files.keySet()) {
        if (k.endsWith(".xml")) {
            Bundle b = (Bundle) new org.hl7.fhir.r5.formats.XmlParser().parse(files.get(k));
            for (org.hl7.fhir.r5.model.Bundle.BundleEntryComponent be : b.getEntry()) {
                if (be.hasResource()) {
                    ResourceEntry e = new ResourceEntry();
                    e.type = be.getResource().fhirType();
                    e.id = be.getResource().getId();
                    e.json = new org.hl7.fhir.r5.formats.JsonParser().composeBytes(be.getResource());
                    e.xml = new org.hl7.fhir.r5.formats.XmlParser().composeBytes(be.getResource());
                    e.conf = true;
                    if (be.getResource() instanceof org.hl7.fhir.r5.model.CanonicalResource)
                        e.canonical = ((org.hl7.fhir.r5.model.CanonicalResource) be.getResource()).getUrl();
                    res.add(e);
                }
            }
        }
    }
    return null;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) Bundle(org.hl7.fhir.r5.model.Bundle) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 2 with FHIRFormatError

use of org.hl7.fhir.exceptions.FHIRFormatError in project kindling by HL7.

the class SpecNPMPackageGenerator method loadFile.

private void loadFile(List<ResourceEntry> reslist, byte[] b, String sourceName) throws FHIRFormatError, IOException {
    try {
        JsonObject json = parseJson(b);
        if (json.has("id") && json.has("resourceType")) {
            String id = json.get("id").getAsString();
            String type = json.get("resourceType").getAsString();
            if (!Utilities.noString(id) && !hasEntry(reslist, type, id)) {
                ResourceEntry e = new ResourceEntry();
                e.type = type;
                e.id = id;
                e.json = b;
                e.conf = false;
                reslist.add(e);
            }
        }
    } catch (Throwable e) {
        throw new Error("Exception parsing " + sourceName + ": " + e.getMessage(), e);
    }
}
Also used : JsonObject(com.google.gson.JsonObject) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError)

Example 3 with FHIRFormatError

use of org.hl7.fhir.exceptions.FHIRFormatError 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)

Example 4 with FHIRFormatError

use of org.hl7.fhir.exceptions.FHIRFormatError in project kindling by HL7.

the class CDAGenerator method processDataTypes.

private void processDataTypes(String filename) throws FileNotFoundException, ParserConfigurationException, SAXException, IOException, FHIRFormatError, DefinitionException {
    System.out.println("Process Data Types");
    Document dtMif = XMLUtil.parseFileToDom(filename);
    List<Element> dts = new ArrayList<Element>();
    XMLUtil.getNamedChildren(dtMif.getDocumentElement(), "mif:datatype", dts);
    for (Element dt : dts) {
        String n = dt.getAttribute("name");
        types.put(n, dt);
        if (n.equals("IVL")) {
            processDataType(dt, n + "_TS", "TS");
            processDataType(dt, n + "_PQ", "PQ");
            processDataType(dt, n + "_INT", "INT");
        } else if (n.equals("PIVL")) {
            processDataType(dt, n + "_TS", null);
        } else if (n.equals("EIVL")) {
            processDataType(dt, n + "_TS", null);
        } else if (n.equals("RTO")) {
            processDataType(dt, n + "_PQ_PQ", "PQ");
        } else if (!"Binding".equals(dt.getAttribute("datatypeKind")))
            processDataType(dt, n, null);
    }
    buildSXPR();
    buildInfrastructureRoot();
    for (StructureDefinition sd : structures) {
        // if (!sd.getAbstract())
        generateSnapShot(sd);
    }
    System.out.println(" ... done");
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document)

Example 5 with FHIRFormatError

use of org.hl7.fhir.exceptions.FHIRFormatError in project kindling by HL7.

the class SourceParser method loadCommonSearchParameters.

private void loadCommonSearchParameters() throws FHIRFormatError, FileNotFoundException, IOException {
    Bundle bnd = (Bundle) new XmlParser().parse(new CSFileInputStream(Utilities.path(srcDir, "searchparameter", "common-search-parameters.xml")));
    for (BundleEntryComponent be : bnd.getEntry()) {
        SearchParameter sp = (SearchParameter) be.getResource();
        CommonSearchParameter csp = new CommonSearchParameter();
        csp.setId(sp.getId());
        csp.setCode(sp.getCode());
        for (CodeType ct : sp.getBase()) {
            csp.getResources().add(ct.asStringValue());
            definitions.getCommonSearchParameters().put(ct.asStringValue() + "::" + sp.getCode(), csp);
        }
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r5.model.Bundle) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) CodeType(org.hl7.fhir.r5.model.CodeType) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)85 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)61 FileInputStream (java.io.FileInputStream)43 ArrayList (java.util.ArrayList)36 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)36 FileOutputStream (java.io.FileOutputStream)29 IOException (java.io.IOException)27 FHIRException (org.hl7.fhir.exceptions.FHIRException)26 File (java.io.File)22 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)19 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)18 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)13 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)13 JsonElement (com.google.gson.JsonElement)12 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)12 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)12 XmlParser (org.hl7.fhir.r5.formats.XmlParser)11 Resource (org.hl7.fhir.dstu3.model.Resource)9 HashMap (java.util.HashMap)8 Extension (org.hl7.fhir.r5.model.Extension)8