use of org.hl7.fhir.dstu2.model.Base in project drug-formulary-ri by HL7-DaVinci.
the class ExampleServerDstu3IT method testCreateAndRead.
@Test
public void testCreateAndRead() {
ourLog.info("Base URL is: " + HapiProperties.getServerAddress());
String methodName = "testCreateResourceConditional";
Patient pt = new Patient();
pt.addName().setFamily(methodName);
IIdType id = ourClient.create().resource(pt).execute().getId();
Patient pt2 = ourClient.read().resource(Patient.class).withId(id).execute();
assertEquals(methodName, pt2.getName().get(0).getFamily());
}
use of org.hl7.fhir.dstu2.model.Base in project org.hl7.fhir.core by hapifhir.
the class ICD11Generator method execute.
private void execute(String base, String dest) throws IOException {
CodeSystem cs = makeMMSCodeSystem();
JsonObject version = fetchJson(Utilities.pathURL(base, "/icd/release/11/mms"));
String[] p = version.get("latestRelease").getAsString().split("\\/");
cs.setVersion(p[6]);
JsonObject root = fetchJson(url(base, version.get("latestRelease").getAsString()));
cs.setDateElement(new DateTimeType(root.get("releaseDate").getAsString()));
for (JsonElement child : root.getAsJsonArray("child")) {
processMMSEntity(cs, base, child.getAsString(), cs.addConcept(), dest);
System.out.println();
}
new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "icd-11-mms.xml")), cs);
makeFullVs(dest, cs);
cs = makeEntityCodeSystem();
root = fetchJson(Utilities.pathURL(base, "/icd/entity"));
cs.setVersion(root.get("releaseId").getAsString());
cs.setDateElement(new DateTimeType(root.get("releaseDate").getAsString()));
cs.setTitle(readString(root, "title"));
Set<String> ids = new HashSet<>();
for (JsonElement child : root.getAsJsonArray("child")) {
processEntity(cs, ids, base, tail(child.getAsString()), dest);
System.out.println();
}
new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "icd-11-foundation.xml")), cs);
makeFullVs2(dest, cs);
System.out.println("finished");
}
use of org.hl7.fhir.dstu2.model.Base in project org.hl7.fhir.core by hapifhir.
the class ICD11Generator method processMMSEntity.
private void processMMSEntity(CodeSystem cs, String base, String ref, org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent cc, String dest) throws IOException {
System.out.print(".");
JsonObject entity = fetchJson(url(base, ref));
cc.setId(tail(ref));
if (entity.has("code") && !Utilities.noString(entity.get("code").getAsString())) {
cc.setCode(entity.get("code").getAsString());
} else if (entity.has("blockId") && !Utilities.noString(entity.get("blockId").getAsString())) {
cc.setCode(entity.get("blockId").getAsString());
} else {
cc.setCode(cc.getId());
cc.addProperty().setCode("abstract").setValue(new BooleanType(true));
}
if (entity.has("classKind") && !Utilities.noString(entity.get("classKind").getAsString()) && !"category".equals(entity.get("classKind").getAsString())) {
cc.addProperty().setCode("kind").setValue(new CodeType(entity.get("classKind").getAsString()));
}
cc.setDisplay(readString(entity, "title"));
StringBuilder defn = new StringBuilder();
String d = readString(entity, "definition");
if (d != null) {
defn.append(d);
}
if (d == null && (entity.has("inclusion") || entity.has("exclusion"))) {
defn.append(cc.getDisplay());
}
if (entity.has("inclusion")) {
defn.append(". Includes: ");
boolean first = true;
for (JsonElement child : entity.getAsJsonArray("inclusion")) {
if (first)
first = false;
else
defn.append(", ");
defn.append(readString((JsonObject) child, "label"));
}
}
if (entity.has("exclusion")) {
defn.append(". Excludes: ");
boolean first = true;
for (JsonElement child : entity.getAsJsonArray("exclusion")) {
if (first)
first = false;
else
defn.append(", ");
JsonObject co = (JsonObject) child;
String v = readString(co, "label");
if (v != null) {
defn.append(v);
if (co.has("linearizationReference")) {
cc.addProperty().setValue(new Coding().setSystem("http://id.who.int/icd11/mms").setCode(tail(co.get("linearizationReference").getAsString())).setDisplay(v)).setCode("exclusion");
}
}
}
}
cc.setDefinition(defn.toString());
addDesignation(readString(entity, "longDefinition"), cc, "http://id.who.int/icd11/mms/designation", "longDefinition");
addDesignation(readString(entity, "fullySpecifiedName"), cc, "http://snomed.info/sct", "900000000000003001");
addProperty(readString(entity, "codingNote"), cc, "codingNote");
if (entity.has("indexTerm")) {
// }
for (JsonElement child : entity.getAsJsonArray("indexTerm")) {
processIndexTerm(cc, (JsonObject) child);
}
}
if (entity.has("postcoordinationScale")) {
for (JsonElement child : entity.getAsJsonArray("postcoordinationScale")) {
JsonObject o = (JsonObject) child;
String name = tail(o.get("axisName").getAsString());
ConceptPropertyComponent prop = cc.addProperty();
prop.setCode("postcoordinationScale");
prop.setValue(new CodeType(name));
ToolingExtensions.addBooleanExtension(prop, "http://id.who.int/icd11/extensions/required", o.get("requiredPostcoordination").getAsBoolean());
ToolingExtensions.addBooleanExtension(prop, "http://id.who.int/icd11/extensions/repeats", o.get("allowMultipleValues").getAsBoolean());
if (o.has("scaleEntity")) {
ToolingExtensions.addUriExtension(prop, "http://id.who.int/icd11/extensions/valueSet", buildValueSet(cs, cc.getCode(), name, o, dest));
}
}
}
if (entity.has("child")) {
for (JsonElement child : entity.getAsJsonArray("child")) {
processMMSEntity(cs, base, child.getAsString(), cc.addConcept(), dest);
}
}
}
use of org.hl7.fhir.dstu2.model.Base in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method renderLeaf.
private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints) throws FHIRException, UnsupportedEncodingException, IOException {
if (ew == null)
return;
Base e = ew.getBase();
if (e instanceof StringType)
x.addText(((StringType) e).getValue());
else if (e instanceof CodeType)
x.addText(((CodeType) e).getValue());
else if (e instanceof IdType)
x.addText(((IdType) e).getValue());
else if (e instanceof Extension)
x.addText("Extensions: Todo");
else if (e instanceof InstantType)
x.addText(((InstantType) e).toHumanDisplay());
else if (e instanceof DateTimeType)
x.addText(((DateTimeType) e).toHumanDisplay());
else if (e instanceof Base64BinaryType)
x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
else if (e instanceof org.hl7.fhir.dstu2.model.DateType)
x.addText(((org.hl7.fhir.dstu2.model.DateType) e).toHumanDisplay());
else if (e instanceof Enumeration) {
Object ev = ((Enumeration<?>) e).getValue();
// todo: look up a display name if there is one
x.addText(ev == null ? "" : ev.toString());
} else if (e instanceof BooleanType)
x.addText(((BooleanType) e).getValue().toString());
else if (e instanceof CodeableConcept) {
renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
} else if (e instanceof Coding) {
renderCoding((Coding) e, x, showCodeDetails);
} else if (e instanceof Annotation) {
renderAnnotation((Annotation) e, x);
} else if (e instanceof Identifier) {
renderIdentifier((Identifier) e, x);
} else if (e instanceof org.hl7.fhir.dstu2.model.IntegerType) {
x.addText(Integer.toString(((org.hl7.fhir.dstu2.model.IntegerType) e).getValue()));
} else if (e instanceof org.hl7.fhir.dstu2.model.DecimalType) {
x.addText(((org.hl7.fhir.dstu2.model.DecimalType) e).getValue().toString());
} else if (e instanceof HumanName) {
renderHumanName((HumanName) e, x);
} else if (e instanceof SampledData) {
renderSampledData((SampledData) e, x);
} else if (e instanceof Address) {
renderAddress((Address) e, x);
} else if (e instanceof ContactPoint) {
renderContactPoint((ContactPoint) e, x);
} else if (e instanceof UriType) {
renderUri((UriType) e, x);
} else if (e instanceof Timing) {
renderTiming((Timing) e, x);
} else if (e instanceof Range) {
renderRange((Range) e, x);
} else if (e instanceof Quantity) {
renderQuantity((Quantity) e, x, showCodeDetails);
} else if (e instanceof Ratio) {
renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
x.addText("/");
renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
} else if (e instanceof Period) {
Period p = (Period) e;
x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
x.addText(" --> ");
x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
} else if (e instanceof Reference) {
Reference r = (Reference) e;
XhtmlNode c = x;
ResourceWithReference tr = null;
if (r.hasReferenceElement()) {
tr = resolveReference(res, r.getReference());
if (!r.getReference().startsWith("#")) {
if (tr != null && tr.getReference() != null)
c = x.addTag("a").attribute("href", tr.getReference());
else
c = x.addTag("a").attribute("href", r.getReference());
}
}
// what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
if (r.hasDisplayElement()) {
c.addText(r.getDisplay());
if (tr != null) {
c.addText(". Generated Summary: ");
generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
}
} else if (tr != null) {
generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"));
} else {
c.addText(r.getReference());
}
} else if (e instanceof Resource) {
return;
} else if (e instanceof ElementDefinition) {
x.addText("todo-bundle");
} else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta))
throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet");
}
use of org.hl7.fhir.dstu2.model.Base in project org.hl7.fhir.core by hapifhir.
the class BatchLoader method main.
public static void main(String[] args) throws IOException, Exception {
if (args.length < 4) {
System.out.println("Batch uploader takes 4 parameters in order: server base url, file/folder to upload, xml/json, and batch size");
} else {
String server = args[0];
String file = args[1];
// args[2].equals("json") ? new JsonParser() : new XmlParser();
IParser p = new JsonParser();
int size = Integer.parseInt(args[3]);
size = 500;
if (file.endsWith(".xml")) {
throw new FHIRException("Unimplemented file type " + file);
} else if (file.endsWith(".json")) {
throw new FHIRException("Unimplemented file type " + file);
} else if (file.endsWith(".zip")) {
LoadZipFile(server, file, p, size, 0, -1);
} else if (new File(file).isDirectory()) {
LoadDirectory(server, file, p, size);
} else
throw new FHIRException("Unknown file type " + file);
}
}
Aggregations