Search in sources :

Example 21 with Annotation

use of org.hl7.cql_annotations.r1.Annotation in project openmrs-module-fhir2 by openmrs.

the class MedicationRequestTranslatorImpl method toFhirResource.

@Override
public MedicationRequest toFhirResource(@Nonnull DrugOrder drugOrder) {
    notNull(drugOrder, "The DrugOrder object should not be null");
    MedicationRequest medicationRequest = new MedicationRequest();
    medicationRequest.setId(drugOrder.getUuid());
    medicationRequest.setStatus(statusTranslator.toFhirResource(drugOrder));
    medicationRequest.setMedication(medicationReferenceTranslator.toFhirResource(drugOrder.getDrug()));
    medicationRequest.setPriority(medicationRequestPriorityTranslator.toFhirResource(drugOrder.getUrgency()));
    medicationRequest.setRequester(practitionerReferenceTranslator.toFhirResource(drugOrder.getOrderer()));
    medicationRequest.setEncounter(encounterReferenceTranslator.toFhirResource(drugOrder.getEncounter()));
    medicationRequest.setSubject(patientReferenceTranslator.toFhirResource(drugOrder.getPatient()));
    medicationRequest.setIntent(MedicationRequest.MedicationRequestIntent.ORDER);
    medicationRequest.addNote(new Annotation().setText(drugOrder.getCommentToFulfiller()));
    medicationRequest.addReasonCode(conceptTranslator.toFhirResource(drugOrder.getOrderReason()));
    medicationRequest.addDosageInstruction(dosageTranslator.toFhirResource(drugOrder));
    if (drugOrder.getPreviousOrder() != null && (drugOrder.getAction() == Order.Action.DISCONTINUE || drugOrder.getAction() == Order.Action.REVISE)) {
        medicationRequest.setPriorPrescription(createOrderReference(drugOrder.getPreviousOrder()).setIdentifier(orderIdentifierTranslator.toFhirResource(drugOrder.getPreviousOrder())));
    } else if (drugOrder.getPreviousOrder() != null && drugOrder.getAction() == Order.Action.RENEW) {
        medicationRequest.setBasedOn(Collections.singletonList(createOrderReference(drugOrder.getPreviousOrder()).setIdentifier(orderIdentifierTranslator.toFhirResource(drugOrder.getPreviousOrder()))));
    }
    return medicationRequest;
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) Annotation(org.hl7.fhir.r4.model.Annotation)

Example 22 with Annotation

use of org.hl7.cql_annotations.r1.Annotation in project org.hl7.fhir.core by hapifhir.

the class DeviceUseStatement10_50 method convertDeviceUseStatement.

public static org.hl7.fhir.dstu2.model.DeviceUseStatement convertDeviceUseStatement(org.hl7.fhir.r5.model.DeviceUsage src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.dstu2.model.DeviceUseStatement tgt = new org.hl7.fhir.dstu2.model.DeviceUseStatement();
    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
    if (src.getBodySite().hasConcept())
        tgt.setBodySite(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getBodySite().getConcept()));
    if (src.getDevice().hasReference())
        tgt.setDevice(Reference10_50.convertReference(src.getDevice().getReference()));
    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
    for (CodeableReference t : src.getReason()) if (t.hasConcept())
        tgt.addIndication(CodeableConcept10_50.convertCodeableConcept(t.getConcept()));
    for (Annotation t : src.getNote()) tgt.addNotes(t.getText());
    if (src.hasDateAssertedElement())
        tgt.setRecordedOnElement(DateTime10_50.convertDateTime(src.getDateAssertedElement()));
    if (src.hasPatient())
        tgt.setSubject(Reference10_50.convertReference(src.getPatient()));
    if (src.hasTiming())
        tgt.setTiming(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getTiming()));
    return tgt;
}
Also used : CodeableReference(org.hl7.fhir.r5.model.CodeableReference) Annotation(org.hl7.fhir.r5.model.Annotation)

Example 23 with Annotation

use of org.hl7.cql_annotations.r1.Annotation in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method renderAnnotation.

private void renderAnnotation(Annotation a, XhtmlNode x, boolean showCodeDetails) throws FHIRException {
    StringBuilder s = new StringBuilder();
    if (a.hasAuthor()) {
        s.append("Author: ");
        if (a.hasAuthorReference())
            s.append(a.getAuthorReference().getReference());
        else if (a.hasAuthorStringType())
            s.append(a.getAuthorStringType().getValue());
    }
    if (a.hasTimeElement()) {
        if (s.length() > 0)
            s.append("; ");
        s.append("Made: ").append(a.getTimeElement().toHumanDisplay());
    }
    if (a.hasText()) {
        if (s.length() > 0)
            s.append("; ");
        s.append("Annotation: ").append(a.getText());
    }
    x.addText(s.toString());
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 24 with Annotation

use of org.hl7.cql_annotations.r1.Annotation 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");
}
Also used : Meta(org.hl7.fhir.dstu2.model.Meta) Base64(org.apache.commons.codec.binary.Base64) Address(org.hl7.fhir.dstu2.model.Address) StringType(org.hl7.fhir.dstu2.model.StringType) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Attachment(org.hl7.fhir.dstu2.model.Attachment) UriType(org.hl7.fhir.dstu2.model.UriType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HumanName(org.hl7.fhir.dstu2.model.HumanName) ContactPoint(org.hl7.fhir.dstu2.model.ContactPoint) Identifier(org.hl7.fhir.dstu2.model.Identifier) Coding(org.hl7.fhir.dstu2.model.Coding) Narrative(org.hl7.fhir.dstu2.model.Narrative) SampledData(org.hl7.fhir.dstu2.model.SampledData) Ratio(org.hl7.fhir.dstu2.model.Ratio) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) InstantType(org.hl7.fhir.dstu2.model.InstantType) Enumeration(org.hl7.fhir.dstu2.model.Enumeration) Reference(org.hl7.fhir.dstu2.model.Reference) BooleanType(org.hl7.fhir.dstu2.model.BooleanType) Resource(org.hl7.fhir.dstu2.model.Resource) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) Quantity(org.hl7.fhir.dstu2.model.Quantity) Period(org.hl7.fhir.dstu2.model.Period) Range(org.hl7.fhir.dstu2.model.Range) Base(org.hl7.fhir.dstu2.model.Base) Annotation(org.hl7.fhir.dstu2.model.Annotation) IdType(org.hl7.fhir.dstu2.model.IdType) Extension(org.hl7.fhir.dstu2.model.Extension) DateTimeType(org.hl7.fhir.dstu2.model.DateTimeType) CodeType(org.hl7.fhir.dstu2.model.CodeType) EventTiming(org.hl7.fhir.dstu2.model.Timing.EventTiming) Timing(org.hl7.fhir.dstu2.model.Timing) Base64BinaryType(org.hl7.fhir.dstu2.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.dstu2.model.CodeableConcept)

Example 25 with Annotation

use of org.hl7.cql_annotations.r1.Annotation in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeAnnotation.

protected void composeAnnotation(Complex parent, String parentType, String name, Annotation element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeElement(t, "Annotation", name, element, index);
    if (element.hasAuthor())
        composeType(t, "Annotation", "author", element.getAuthor(), -1);
    if (element.hasTimeElement())
        composeDateTime(t, "Annotation", "time", element.getTimeElement(), -1);
    if (element.hasTextElement())
        composeString(t, "Annotation", "text", element.getTextElement(), -1);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Aggregations

NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 Annotation (zipkin2.Annotation)14 Trace (com.newrelic.api.agent.Trace)13 Operation (gov.cms.bfd.server.war.Operation)13 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)12 Annotation (org.hl7.fhir.r4.model.Annotation)12 Map (java.util.Map)11 NoResultException (javax.persistence.NoResultException)11 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)9 Annotation (org.hl7.fhir.dstu3.model.Annotation)9 Search (ca.uhn.fhir.rest.annotation.Search)8 List (java.util.List)8 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)8 Read (ca.uhn.fhir.rest.annotation.Read)7 Patient (org.hl7.fhir.dstu3.model.Patient)7 OffsetLinkBuilder (gov.cms.bfd.server.war.commons.OffsetLinkBuilder)6 Collectors (java.util.stream.Collectors)6 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)6