use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.
the class BindingsParser method loadValueSet.
private ValueSet loadValueSet(String ref, String committee) throws Exception {
String folder = new File(filename).getParent();
String srcName;
IParser p;
if (new File(Utilities.path(folder, ref + ".xml")).exists()) {
p = new XmlParser();
srcName = Utilities.path(folder, ref + ".xml");
} else if (new File(Utilities.path(folder, ref + ".json")).exists()) {
p = new JsonParser();
srcName = Utilities.path(folder, ref + ".json");
} else
throw new Exception("Unable to find source for " + ref + " in " + filename + " (" + Utilities.path(folder, ref + ".xml/json)"));
FileInputStream input = new FileInputStream(srcName);
try {
ValueSet result = ValueSetUtilities.makeShareable((ValueSet) p.parse(input));
result.setId(ref.substring(9));
if (!result.hasExperimental())
result.setExperimental(false);
// if (!result.hasUrl())
result.setUrl("http://hl7.org/fhir/ValueSet/" + ref.substring(9));
if (!result.hasVersion() || result.getUrl().startsWith("http://hl7.org/fhir"))
result.setVersion(version);
if (!Utilities.noString(committee)) {
if (!result.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
result.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee));
} else {
String ec = ToolingExtensions.readStringExtension(result, ToolingExtensions.EXT_WORKGROUP);
if (!ec.equals(committee))
System.out.println("ValueSet " + result.getUrl() + " WG mismatch 1: is " + ec + ", want to set to " + committee);
}
}
result.setUserData("filename", "valueset-" + ref.substring(9));
result.setUserData("path", "valueset-" + ref.substring(9) + ".html");
new CodeSystemConvertor(codeSystems).convert(p, result, srcName, packageInfo);
return result;
} finally {
IOUtils.closeQuietly(input);
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.
the class OldSpreadsheetParser method findContext.
private ElementDefn findContext(ElementDefn root, String pathname, String source) throws Exception {
String[] path = pathname.split("\\.");
if (!path[0].equals(root.getName()))
throw new Exception("Element Path '" + pathname + "' is not legal found at " + source);
ElementDefn res = root;
for (int i = 1; i < path.length; i++) {
String en = path[i];
if (en.length() == 0)
throw new Exception("Improper path " + pathname + " found at " + source);
if (en.charAt(en.length() - 1) == '*')
throw new Exception("no-list wrapper found at " + source);
ElementDefn t = res.getElementByName(en, true, definitions, "find context", false);
if (t == null) {
throw new Exception("Reference to undefined Element " + pathname + " found at " + source);
}
res = t;
}
return res;
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.
the class SourceParser method loadIgs.
private void loadIgs() throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document xdoc = builder.parse(new CSFileInputStream(srcDir + "igs.xml"));
Element root = xdoc.getDocumentElement();
if (root.getNodeName().equals("igs")) {
Element ig = XMLUtil.getFirstChild(root);
while (ig != null) {
if (ig.getNodeName().equals("ig") && (!ig.hasAttribute("local") || isOkLocally(ig.getAttribute("code"))) && !isRuledOutLocally(ig.getAttribute("code"))) {
ImplementationGuideDefn igg = new ImplementationGuideDefn(ig.getAttribute("committee"), ig.getAttribute("code"), ig.getAttribute("name"), ig.getAttribute("brief"), ig.getAttribute("source").replace('\\', File.separatorChar), "1".equals(ig.getAttribute("review")), ig.getAttribute("ballot"), ig.getAttribute("fmm"), ig.getAttribute("section"), "yes".equals(ig.getAttribute("core")), page.getValidationErrors());
definitions.getIgs().put(igg.getCode(), igg);
definitions.getSortedIgs().add(igg);
}
ig = XMLUtil.getNextSibling(ig);
}
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.
the class SourceParser method checkConditions.
public void checkConditions(List<String> errors, Map<String, Long> dates) throws Exception {
Utilities.checkFolder(srcDir, errors);
Utilities.checkFolder(termDir, errors);
Utilities.checkFolder(imgDir, errors);
this.dates = dates;
checkFile("required", termDir, "bindings.xml", errors, "all");
checkFile("required", dtDir, "primitives.xml", errors, "all");
for (String n : ini.getPropertyNames("types")) if (ini.getStringProperty("types", n).equals("")) {
TypeRef t = new TypeParser(version.toString()).parse(n, false, null, context, true).get(0);
checkFile("type definition", dtDir, t.getName().toLowerCase() + ".xml", errors, "all");
}
String[] shared = ini.getPropertyNames("shared");
if (shared != null)
for (String n : shared) checkFile("shared structure definition", dtDir, n.toLowerCase() + ".xml", errors, "all");
for (String n : ini.getPropertyNames("infrastructure")) checkFile("infrastructure definition", dtDir, n.toLowerCase() + ".xml", errors, "all");
for (String n : ini.getPropertyNames("resources")) {
if (!new File(srcDir + n).exists())
errors.add("unable to find folder for resource " + n);
else {
for (String fn : new File(srcDir + n + File.separatorChar).list()) checkFile("source", srcDir + n + File.separatorChar, fn, errors, n);
}
}
for (String n : ini.getPropertyNames("special-resources")) {
// now iterate all the files in the directory checking data
for (String fn : new File(srcDir + n + File.separatorChar).list()) checkFile("source", srcDir + n + File.separatorChar, fn, errors, n);
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source 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);
}
Aggregations