Search in sources :

Example 66 with Range

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);
    }
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) FhirContext(ca.uhn.fhir.context.FhirContext) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Range(org.hl7.fhir.r4.model.Range) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser)

Example 67 with Range

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);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 68 with Range

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);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 69 with Range

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);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 70 with Range

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);
    }
}
Also used : Base64(org.apache.commons.codec.binary.Base64) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) org.hl7.fhir.r4.model(org.hl7.fhir.r4.model) Enumeration(org.hl7.fhir.r4.model.Enumeration) EventTiming(org.hl7.fhir.r4.model.Timing.EventTiming)

Aggregations

Test (org.junit.jupiter.api.Test)18 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)15 Quantity (org.hl7.fhir.r4.model.Quantity)14 Resource (org.hl7.fhir.r4.model.Resource)13 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Search (ca.uhn.fhir.rest.annotation.Search)11 Trace (com.newrelic.api.agent.Trace)10 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)10 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)9 ArrayList (java.util.ArrayList)9 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)8 Operation (gov.cms.bfd.server.war.Operation)8 OffsetLinkBuilder (gov.cms.bfd.server.war.commons.OffsetLinkBuilder)8 Date (java.util.Date)8 Range (org.hl7.fhir.r4.model.Range)8 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)7 List (java.util.List)7 Bundle (org.hl7.fhir.r4.model.Bundle)7