use of org.hl7.fhir.r5.model 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.model in project kindling by HL7.
the class ExampleInspector method checkJsonLd.
private void checkJsonLd() throws IOException {
String s1 = "{\r\n" + " \"@type\": \"fhir:Claim\",\r\n" + " \"@id\": \"http://hl7.org/fhir/Claim/760152\",\r\n" + " \"decimal\": 123.45,\r\n" + " \"@context\": {\r\n" + " \"fhir\": \"http://hl7.org/fhir/\",\r\n" + " \"xsd\": \"http://www.w3.org/2001/XMLSchema#\",\r\n" + " \"decimal\": {\r\n" + " \"@id\": \"fhir:value\",\r\n" + " \"@type\": \"xsd:decimal\"\r\n" + " }\r\n" + " }\r\n" + "}\r\n";
String s2 = "{\r\n" + " \"@type\": \"fhir:Claim\",\r\n" + " \"@id\": \"http://hl7.org/fhir/Claim/760152\",\r\n" + " \"decimal\": \"123.45\",\r\n" + " \"@context\": {\r\n" + " \"fhir\": \"http://hl7.org/fhir/\",\r\n" + " \"xsd\": \"http://www.w3.org/2001/XMLSchema#\",\r\n" + " \"decimal\": {\r\n" + " \"@id\": \"fhir:value\",\r\n" + " \"@type\": \"xsd:decimal\"\r\n" + " }\r\n" + " }\r\n" + "}\r\n";
Model m1 = ModelFactory.createDefaultModel();
Model m2 = ModelFactory.createDefaultModel();
m1.read(new StringReader(s1), null, "JSON-LD");
m2.read(new StringReader(s2), null, "JSON-LD");
List<String> diffs = new ModelComparer().setModel1(m1, "j1").setModel2(m2, "j2").compare();
if (!diffs.isEmpty()) {
System.out.println("not isomorphic");
for (String s : diffs) {
System.out.println(" " + s);
}
}
}
use of org.hl7.fhir.r5.model 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.model in project kindling by HL7.
the class ExampleInspector method validateRDF.
private void validateRDF(String fttl, String fjld, String rt) throws FileNotFoundException, IOException {
if (VALIDATE_RDF && new File(fjld).exists()) {
FileInputStream f = new FileInputStream(fjld);
int size = f.available();
f.close();
if (size > 1000000)
return;
// replace @context with the contents of the right context file
JsonObject json = (JsonObject) new com.google.gson.JsonParser().parse(TextFile.fileToString(fjld));
json.remove("@context");
json.add("@context", jsonLdDefns.get("@context"));
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String jcnt = gson.toJson(json);
// TextFile.stringToFile(jcnt, "c:\\temp\\jsonld\\"+rt+".jsonld");
// parse to a model
Model mj = ModelFactory.createDefaultModel();
mj.read(new StringReader(jcnt), null, "JSON-LD");
// read turtle file into Jena
Model mt = RDFDataMgr.loadModel(fttl);
// use ShEx to validate turtle file - TODO
shex.validate(mt);
// List<String> diffs = new ModelComparer().setModel1(mt, "ttl").setModel2(mj, "json").compare();
// if (!diffs.isEmpty()) {
// System.out.println("not isomorphic");
// for (String s : diffs) {
// System.out.println(" "+s);
// }
// RDFDataMgr.write(new FileOutputStream("c:\\temp\\json.nt"), mj, RDFFormat.NTRIPLES_UTF8);
// RDFDataMgr.write(new FileOutputStream("c:\\temp\\ttl.nt"), mt, RDFFormat.NTRIPLES_UTF8);
// }
}
}
use of org.hl7.fhir.r5.model 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;
}
Aggregations