use of org.hl7.fhir.r5.model.Range in project quality-measure-and-cohort-service by Alvearie.
the class FHIRRestUtils method complicatedTypeValueConstructor.
static String complicatedTypeValueConstructor(ParameterDefinition parameterDefinition) {
FhirContext context = FhirContext.forCached(FhirVersionEnum.R4);
IParser parser = context.newJsonParser();
String valueKey;
// In order to use the hapi parser, we cannot translate an extension by itself. The patient object wraps the extension
Patient patient = new Patient();
Extension extension = new Extension();
switch(parameterDefinition.getType()) {
case "Period":
Period period = (Period) parameterDefinition.getExtension().get(0).getValue();
extension.setValue(period);
patient.addExtension(extension);
valueKey = "valuePeriod";
break;
case "Range":
Range range = (Range) parameterDefinition.getExtension().get(0).getValue();
extension.setValue(range);
patient.addExtension(extension);
valueKey = "valueRange";
break;
case "Quantity":
Quantity quantity = (Quantity) parameterDefinition.getExtension().get(0).getValue();
extension.setValue(quantity);
patient.addExtension(extension);
valueKey = "valueQuantity";
break;
default:
throw new RuntimeException("Complicated Type" + parameterDefinition.getType() + " not yet implemented");
}
String intermediateValue = parser.encodeResourceToString(patient);
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode root = mapper.readTree(intermediateValue);
JsonNode nameNode = root.path("extension");
return nameNode.get(0).path(valueKey).toString();
} catch (JsonProcessingException e) {
throw new RuntimeException("There was an issue with json translation", e);
}
}
use of org.hl7.fhir.r5.model.Range in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeRange.
protected void composeRange(Complex parent, String parentType, String name, Range element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeElement(t, "Range", name, element, index);
if (element.hasLow())
composeQuantity(t, "Range", "low", element.getLow(), -1);
if (element.hasHigh())
composeQuantity(t, "Range", "high", element.getHigh(), -1);
}
use of org.hl7.fhir.r5.model.Range in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeRange.
protected void composeRange(Complex parent, String parentType, String name, Range element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeElement(t, "Range", name, element, index);
if (element.hasLow())
composeQuantity(t, "Range", "low", element.getLow(), -1);
if (element.hasHigh())
composeQuantity(t, "Range", "high", element.getHigh(), -1);
}
use of org.hl7.fhir.r5.model.Range in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeObservationDefinitionObservationDefinitionQualifiedIntervalComponent.
protected void composeObservationDefinitionObservationDefinitionQualifiedIntervalComponent(Complex parent, String parentType, String name, ObservationDefinition.ObservationDefinitionQualifiedIntervalComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "qualifiedInterval", name, element, index);
if (element.hasCategoryElement())
composeEnum(t, "ObservationDefinition", "category", element.getCategoryElement(), -1);
if (element.hasRange())
composeRange(t, "ObservationDefinition", "range", element.getRange(), -1);
if (element.hasContext())
composeCodeableConcept(t, "ObservationDefinition", "context", element.getContext(), -1);
for (int i = 0; i < element.getAppliesTo().size(); i++) composeCodeableConcept(t, "ObservationDefinition", "appliesTo", element.getAppliesTo().get(i), i);
if (element.hasGenderElement())
composeEnum(t, "ObservationDefinition", "gender", element.getGenderElement(), -1);
if (element.hasAge())
composeRange(t, "ObservationDefinition", "age", element.getAge(), -1);
if (element.hasGestationalAge())
composeRange(t, "ObservationDefinition", "gestationalAge", element.getGestationalAge(), -1);
if (element.hasConditionElement())
composeString(t, "ObservationDefinition", "condition", element.getConditionElement(), -1);
}
use of org.hl7.fhir.r5.model.Range 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, String path, int indent, ResourceContext rc) 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)
return;
else if (e instanceof InstantType)
x.addText(((InstantType) e).toHumanDisplay());
else if (e instanceof DateTimeType) {
if (e.hasPrimitiveValue())
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.r4.model.DateType)
x.addText(((org.hl7.fhir.r4.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.r4.model.IntegerType) {
x.addText(Integer.toString(((org.hl7.fhir.r4.model.IntegerType) e).getValue()));
} else if (e instanceof org.hl7.fhir.r4.model.DecimalType) {
x.addText(((org.hl7.fhir.r4.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, defn.getPath(), rc != null && rc.resourceResource != null ? rc.resourceResource.getId() : null);
} 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.tx("/");
renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
} else if (e instanceof Period) {
Period p = (Period) e;
x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
x.tx(" --> ");
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(), rc);
if (!r.getReference().startsWith("#")) {
if (tr != null && tr.getReference() != null)
c = x.ah(tr.getReference());
else
c = x.ah(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 && tr.getResource() != null) {
c.tx(". Generated Summary: ");
generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"), rc);
}
} else if (tr != null && tr.getResource() != null) {
generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"), rc);
} else {
c.addText(r.getReference());
}
} else if (e instanceof Resource) {
return;
} else if (e instanceof ElementDefinition) {
x.tx("todo-bundle");
} else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
StructureDefinition sd = context.fetchTypeDefinition(e.fhirType());
if (sd == null)
throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet, and no structure found");
else
generateByProfile(res, sd, ew, sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep(), getChildrenForPath(sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep().getPath()), x, path, showCodeDetails, indent + 1, rc);
}
}
Aggregations