use of org.hl7.fhir.dstu2016may.model.UriType in project org.hl7.fhir.core by hapifhir.
the class R5ToR5Loader method loadBundle.
@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
Resource r5 = null;
if (isJson)
r5 = new JsonParser().parse(stream);
else
r5 = new XmlParser().parse(stream);
Bundle b;
if (r5 instanceof Bundle)
b = (Bundle) r5;
else {
b = new Bundle();
b.setId(UUID.randomUUID().toString().toLowerCase());
b.setType(BundleType.COLLECTION);
b.addEntry().setResource(r5).setFullUrl(r5 instanceof CanonicalResource ? ((CanonicalResource) r5).getUrl() : null);
}
for (CodeSystem cs : cslist) {
BundleEntryComponent be = b.addEntry();
be.setFullUrl(cs.getUrl());
be.setResource(cs);
}
if (killPrimitives) {
List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) be.getResource();
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
remove.add(be);
}
}
b.getEntry().removeAll(remove);
}
if (patchUrls) {
for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) be.getResource();
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
for (ElementDefinition ed : sd.getSnapshot().getElement()) patchUrl(ed);
for (ElementDefinition ed : sd.getDifferential().getElement()) patchUrl(ed);
}
}
}
return b;
}
use of org.hl7.fhir.dstu2016may.model.UriType 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.dstu2016may.model.UriType in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateComposition.
private boolean generateComposition(XhtmlNode x, ValueSet vs, boolean header) {
boolean hasExtensions = false;
if (!vs.hasCodeSystem()) {
if (header) {
XhtmlNode h = x.addTag("h2");
h.addText(vs.getName());
XhtmlNode p = x.addTag("p");
smartAddText(p, vs.getDescription());
if (vs.hasCopyrightElement())
generateCopyright(x, vs);
}
XhtmlNode p = x.addTag("p");
p.addText("This value set includes codes from the following code systems:");
} else {
XhtmlNode p = x.addTag("p");
p.addText("In addition, this value set includes codes from other code systems:");
}
XhtmlNode ul = x.addTag("ul");
XhtmlNode li;
for (UriType imp : vs.getCompose().getImport()) {
li = ul.addTag("li");
li.addText("Import all the codes that are contained in ");
AddVsRef(imp.getValue(), li);
}
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
hasExtensions = genInclude(ul, inc, "Include") || hasExtensions;
}
for (ConceptSetComponent exc : vs.getCompose().getExclude()) {
hasExtensions = genInclude(ul, exc, "Exclude") || hasExtensions;
}
return hasExtensions;
}
use of org.hl7.fhir.dstu2016may.model.UriType in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method includeCodes.
private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params) throws TerminologyServiceException, ETooCostly {
if (context.supportsSystem(inc.getSystem())) {
addCodes(context.expandVS(inc), params);
return;
}
ValueSet cs = context.fetchCodeSystem(inc.getSystem());
if (cs == null)
throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
if (cs.hasVersion())
if (!existsInParams(params, "version", new UriType(cs.getUrl() + "?version=" + cs.getVersion())))
params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "?version=" + cs.getVersion())));
if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
// special case - add all the code system
for (ConceptDefinitionComponent def : cs.getCodeSystem().getConcept()) {
addCodeAndDescendents(inc.getSystem(), def);
}
}
for (ConceptReferenceComponent c : inc.getConcept()) {
addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay());
}
if (inc.getFilter().size() > 1)
// need to and them, and this isn't done yet. But this shouldn't arise in non loinc and snomed value sets
throw new TerminologyServiceException("Multiple filters not handled yet");
if (inc.getFilter().size() == 1) {
ConceptSetFilterComponent fc = inc.getFilter().get(0);
if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISA) {
// special: all non-abstract codes in the target code system under the value
ConceptDefinitionComponent def = getConceptForCode(cs.getCodeSystem().getConcept(), fc.getValue());
if (def == null)
throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
addCodeAndDescendents(inc.getSystem(), def);
} else
throw new NotImplementedException("not done yet");
}
}
use of org.hl7.fhir.dstu2016may.model.UriType in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method importValueSet.
private void importValueSet(String value, List<ValueSetExpansionParameterComponent> params) throws ETooCostly, TerminologyServiceException, FileNotFoundException, IOException {
if (value == null)
throw new TerminologyServiceException("unable to find value set with no identity");
ValueSet vs = context.fetchResource(ValueSet.class, value);
if (vs == null)
throw new TerminologyServiceException("Unable to find imported value set " + value);
ValueSetExpansionOutcome vso = factory.getExpander().expand(vs);
if (vso.getService() != null)
throw new TerminologyServiceException("Unable to expand imported value set " + value);
if (vs.hasVersion())
if (!existsInParams(params, "version", new UriType(vs.getUrl() + "?version=" + vs.getVersion())))
params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "?version=" + vs.getVersion())));
for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
if (!existsInParams(params, p.getName(), p.getValue()))
params.add(p);
}
for (ValueSetExpansionContainsComponent c : vso.getValueset().getExpansion().getContains()) {
addCode(c.getSystem(), c.getCode(), c.getDisplay());
}
}
Aggregations