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;
}
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);
}
}
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);
}
}
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");
}
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);
}
}
}
Aggregations