use of org.hl7.fhir.r5.utils.validation in project kindling by HL7.
the class DefinitionsUsageTracker method usage.
private void usage(org.hl7.fhir.r5.elementmodel.Element instance, ElementDefn definition, String path) throws Exception {
definition.setCoveredByExample(true);
for (Element c : instance.getChildren()) {
String p = c.getProperty().getDefinition().getPath();
ElementDefn ed = definitions.getElementByPath(p.split("\\."), "example usage", true);
if (ed != null)
usage(c, ed, path + "." + c.getName());
// else if (!c.getName().equals("extension"))
// System.out.println("error finding "+c.getName()+" at "+path);
}
}
use of org.hl7.fhir.r5.utils.validation 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;
}
use of org.hl7.fhir.r5.utils.validation 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.r5.utils.validation in project kindling by HL7.
the class DSTU3ValidationConvertor method convert.
public void convert(String bundleSource, String bundleTarget) throws Exception {
System.out.println("Convert " + bundleSource);
try {
source = (Bundle) new XmlParser().parse(new FileInputStream(bundleSource));
org.hl7.fhir.dstu3.model.Bundle target = Bundle30_50.convertBundle(source);
new org.hl7.fhir.dstu3.formats.XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(bundleTarget), target);
} catch (Exception e) {
throw new Exception(e);
}
}
use of org.hl7.fhir.r5.utils.validation in project kindling by HL7.
the class SourceParser method loadCompositeType.
private String loadCompositeType(String n, Map<String, org.hl7.fhir.definitions.model.TypeDefn> map, String fmm, boolean isAbstract) throws Exception {
TypeParser tp = new TypeParser(version.toString());
List<TypeRef> ts = tp.parse(n, false, null, context, true);
definitions.getKnownTypes().addAll(ts);
StandardsStatus status = loadStatus(n);
String nv = loadNormativeVersion(n);
try {
TypeRef t = ts.get(0);
File csv = new CSFile(dtDir + t.getName().toLowerCase() + ".xml");
if (csv.exists()) {
OldSpreadsheetParser p = new OldSpreadsheetParser("core", new CSFileInputStream(csv), csv.getName(), csv.getAbsolutePath(), definitions, srcDir, logger, registry, version, context, genDate, isAbstract, page, true, ini, wg("fhir"), definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
org.hl7.fhir.definitions.model.TypeDefn el = p.parseCompositeType();
el.setFmmLevel(fmm);
el.setStandardsStatus(status);
el.setNormativeVersion(nv);
map.put(t.getName(), el);
genTypeProfile(el);
errors.addAll(p.getErrors());
return el.getName();
} else {
String p = ini.getStringProperty("types", n);
csv = new CSFile(dtDir + p.toLowerCase() + ".xml");
if (!csv.exists())
throw new Exception("unable to find a definition for " + n + " in " + p);
XLSXmlParser xls = new XLSXmlParser(new CSFileInputStream(csv), csv.getAbsolutePath());
new XLSXmlNormaliser(csv.getAbsolutePath(), exceptionIfExcelNotNormalised).go();
Sheet sheet = xls.getSheets().get("Restrictions");
boolean found = false;
for (int i = 0; i < sheet.rows.size(); i++) {
if (sheet.getColumn(i, "Name").equals(n)) {
found = true;
Invariant inv = new Invariant();
inv.setId(n);
inv.setEnglish(sheet.getColumn(i, "Rules"));
inv.setOcl(sheet.getColumn(i, "OCL"));
inv.setXpath(sheet.getColumn(i, "XPath"));
inv.setExpression(sheet.getColumn(i, "Expression"));
inv.setExplanation(sheet.getColumn(i, "Explanation"));
inv.setTurtle(sheet.getColumn(i, "RDF"));
ProfiledType pt = new ProfiledType();
pt.setDefinition(sheet.getColumn(i, "Definition"));
pt.setDescription(sheet.getColumn(i, "Rules"));
String structure = sheet.getColumn(i, "Structure");
if (!Utilities.noString(structure)) {
String[] parts = structure.split("\\;");
for (String pp : parts) {
String[] words = pp.split("\\=");
pt.getRules().put(words[0], words[1]);
}
}
pt.setName(n);
pt.setBaseType(p);
pt.setInvariant(inv);
definitions.getConstraints().put(n, pt);
}
}
if (!found)
throw new Exception("Unable to find definition for " + n);
return n;
}
} catch (Exception e) {
throw new Exception("Unable to load " + n + ": " + e.getMessage(), e);
}
}
Aggregations