use of org.hl7.fhir.dstu2016may.formats.XmlParser in project kindling by HL7.
the class SourceParser method loadValueSet.
private void loadValueSet(String n) throws FileNotFoundException, Exception {
XmlParser xml = new XmlParser();
ValueSet vs = (ValueSet) xml.parse(new CSFileInputStream(srcDir + ini.getStringProperty("valuesets", n).replace('\\', File.separatorChar)));
new CodeSystemConvertor(definitions.getCodeSystems()).convert(xml, vs, srcDir + ini.getStringProperty("valuesets", n).replace('\\', File.separatorChar), page.packageInfo());
vs.setId(FormatUtilities.makeId(n));
vs.setUrl("http://hl7.org/fhir/ValueSet/" + vs.getId());
if (!vs.hasVersion() || vs.getUrl().startsWith("http://hl7.org/fhir"))
vs.setVersion(version.toCode());
vs.setUserData("path", "valueset-" + vs.getId() + ".html");
vs.setUserData("filename", "valueset-" + vs.getId());
definitions.getExtraValuesets().put(n, vs);
definitions.getExtraValuesets().put(vs.getUrl(), vs);
}
use of org.hl7.fhir.dstu2016may.formats.XmlParser in project kindling by HL7.
the class SourceParser method loadConformancePackage.
private void loadConformancePackage(Profile ap, List<ValidationMessage> issues, WorkGroup wg) throws FileNotFoundException, IOException, Exception {
if (ap.getSourceType() == ConformancePackageSourceType.Spreadsheet) {
OldSpreadsheetParser sparser = new OldSpreadsheetParser(ap.getCategory(), new CSFileInputStream(ap.getSource()), Utilities.noString(ap.getId()) ? ap.getSource() : ap.getId(), ap.getSource(), definitions, srcDir, logger, registry, version, context, genDate, false, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
sparser.setFolder(Utilities.getDirectoryForFile(ap.getSource()));
sparser.parseConformancePackage(ap, definitions, Utilities.getDirectoryForFile(ap.getSource()), ap.getCategory(), issues, wg);
errors.addAll(sparser.getErrors());
} else if (ap.getSourceType() == ConformancePackageSourceType.StructureDefinition) {
Resource rf;
try {
rf = new XmlParser().parse(new CSFileInputStream(ap.getSource()));
} catch (Exception e) {
throw new Exception("Error parsing " + ap.getSource() + ": " + e.getMessage(), e);
}
if (!(rf instanceof StructureDefinition))
throw new Exception("Error parsing Profile: not a structure definition");
StructureDefinition sd = (StructureDefinition) rf;
sd.setVersion(version.toCode());
ap.putMetadata("id", sd.getId() + "-pack");
ap.putMetadata("date", sd.getDateElement().asStringValue());
ap.putMetadata("title", sd.getTitle());
ap.putMetadata("status", sd.getStatus().toCode());
ap.putMetadata("description", new XhtmlComposer(XhtmlComposer.HTML).compose(sd.getText().getDiv()));
if (ToolingExtensions.hasExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg")) {
wg = definitions.getWorkgroups().get(ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg"));
ap.putMetadata("workgroup", wg.getCode());
}
ap.setTitle(sd.getTitle());
new ProfileUtilities(page.getWorkerContext(), null, null).setIds(sd, false);
ap.getProfiles().add(new ConstraintStructure(sd, definitions.getUsageIG(ap.getCategory(), "Parsing " + ap.getSource()), wg == null ? wg(sd) : wg, fmm(sd), sd.getExperimental()));
} else if (ap.getSource() != null) {
parseConformanceDocument(ap, ap.getId(), new CSFile(ap.getSource()), ap.getCategory(), wg);
}
}
use of org.hl7.fhir.dstu2016may.formats.XmlParser in project kindling by HL7.
the class SpreadSheetBase method saveXml.
protected void saveXml(String fn, Resource res) throws IOException {
File f = new CSFile(fn);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f), res);
f.setLastModified(date);
}
use of org.hl7.fhir.dstu2016may.formats.XmlParser in project kindling by HL7.
the class ADLImporter method execute.
private void execute() throws Exception {
// load config
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
adlConfig = builder.parse(new FileInputStream(config)).getDocumentElement();
// load ADL
builder = factory.newDocumentBuilder();
adl = builder.parse(new FileInputStream(source)).getDocumentElement();
check("root", adl.getNamespaceURI(), "http://schemas.openehr.org/v1", "Wrong namespace for ADL XML");
check("root", adl.getNodeName(), "archetype", "Wrong XML for ADL XML");
check("root", XMLUtil.getNamedChild(adl, "adl_version").getTextContent(), "1.4", "unsupported ADL version");
String id = XMLUtil.getFirstChild(XMLUtil.getNamedChild(adl, "archetype_id")).getTextContent().split("\\.")[1];
String baseType = XMLUtil.getNamedChild(XMLUtil.getNamedChild(adl, "definition"), "rm_type_name").getTextContent();
if (!baseType.equals("OBSERVATION"))
return;
// load texts from ontology
List<Element> set = new ArrayList<Element>();
Element ontology = XMLUtil.getNamedChild(adl, "ontology");
Element term_definitions = XMLUtil.getNamedChild(ontology, "term_definitions");
set.clear();
XMLUtil.getNamedChildren(term_definitions, "items", set);
for (Element item : set) {
processTextItem(item);
}
// create structure definition
StructureDefinition sd = new StructureDefinition();
sd.setId("netha-" + id);
sd.setUrl("http://hl7.org/fhir/StructureDefinition/" + sd.getId());
sd.setKind(StructureDefinitionKind.LOGICAL);
populateMetadata(set, sd);
// load data and protocol
Element definition = XMLUtil.getNamedChild(adl, "definition");
NodeTreeEntry root = new NodeTreeEntry();
root.typeName = XMLUtil.getNamedChild(definition, "rm_type_name").getTextContent();
root.atCode = XMLUtil.getNamedChild(definition, "node_id").getTextContent();
root.name = generateToken(root.atCode, true);
sd.setName(root.name);
root.cardinality = readCardinality("root", XMLUtil.getNamedChild(definition, "occurrences"));
set.clear();
XMLUtil.getNamedChildren(definition, "attributes", set);
for (Element item : set) {
// we're actually skipping this level - we don't care about data protocol etc.
// XMLUtil.getNamedChild(XMLUtil.getNamedChild(item, "children"), "attributes");
Element attributes = item;
loadChildren(root.atCode, root, attributes);
}
dumpChildren("", root);
genElements(sd, root.name, root);
// save
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(dest), sd);
System.out.println("done. saved as " + dest);
}
use of org.hl7.fhir.dstu2016may.formats.XmlParser in project kindling by HL7.
the class ResourceOrderUpdater method process.
private static void process(String filename) throws Exception {
System.out.println(" process " + filename);
XmlParser xml = new XmlParser();
xml.setOutputStyle(OutputStyle.PRETTY);
InputStream si = new FileInputStream(filename);
Resource r = xml.parse(si);
si.close();
OutputStream so = new FileOutputStream(filename);
xml.compose(so, r);
so.close();
}
Aggregations