Search in sources :

Example 1 with Attachment

use of org.hl7.fhir.dstu2016may.model.Attachment in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7DocumentReferenceFHIRConversionTest method doc_ref_content_test.

@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void doc_ref_content_test(String segment) {
    String documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + "TXA|1||TEXT||||201801180346||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + // Next three lines create an attachment
    "OBX|1|TX|||ECHOCARDIOGRAPHIC REPORT||||||F|||202101010000|||\n" + "OBX|2|TX|||NORMAL LV CHAMBER SIZE WITH MILD CONCENTRIC LVH||||||F|||202101010000|||\n" + "OBX|3|TX|||HYPERDYNAMIC LV SYSTOLIC FUNCTION, VISUAL EF 80%||||||F|||202101010000|||\n";
    DocumentReference report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    DocumentReference.DocumentReferenceContentComponent content = report.getContentFirstRep();
    // Future TXA.3, currently always defaults to text/plain
    assertThat(content.getAttachment().getContentType()).isEqualTo("text/plain");
    // TXA.7 date
    assertThat(content.getAttachment().getCreationElement().toString()).containsPattern("2018-01-18T03:46:00");
    assertThat(content.getAttachment().hasData()).isTrue();
    String decodedData = new String(Base64.getDecoder().decode(content.getAttachment().getDataElement().getValueAsString()));
    assertThat(decodedData).isEqualTo("ECHOCARDIOGRAPHIC REPORT\nNORMAL LV CHAMBER SIZE WITH MILD CONCENTRIC LVH\nHYPERDYNAMIC LV SYSTOLIC FUNCTION, VISUAL EF 80%");
    // TODO: Determine if we need to look at anything other than OBX.2 when it is TX
    // Leave this test in place as a reminder
    documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + "TXA|1||||||201801180346||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + // TODO: find better code for this test which is to see that OBX.2 is the fallback.
    "OBX|1|SN|||||||||F";
    report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    content = report.getContentFirstRep();
    // Because the OBX is not TX, the content is put in an Observation
    // FHIR requires a Content element, so only a minimal one is created.
    // Future OBX.2 is the backup for content type, but currently always defaults to text/plain
    assertThat(content.getAttachment().hasContentType()).isTrue();
    // Currently always defaults to text/plain
    assertThat(content.getAttachment().getContentType()).isEqualTo("text/plain");
    // TXA.7 date
    assertThat(content.getAttachment().getCreationElement().toString()).containsPattern("2018-01-18T03:46:00");
    assertThat(content.getAttachment().hasData()).isFalse();
    // Test that content is created even if TXA.7 is empty
    documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + // Ensure that empty TXA.7 still works
    "TXA|1||||||||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + "OBX|1|SN|||||||||F";
    report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    content = report.getContentFirstRep();
    // Because the OBX is not TX, the content is put in an Observation
    // FHIR requires a Content element, so only a minimal one is created.
    // Currently always defaults to text/plain
    assertThat(content.getAttachment().hasContentType()).isTrue();
    // Currently always defaults to text/plain, even if not data for content
    assertThat(content.getAttachment().getContentType()).isEqualTo("text/plain");
    // No TXA.7 date
    assertThat(content.getAttachment().hasCreationElement()).isFalse();
    assertThat(content.getAttachment().hasData()).isFalse();
}
Also used : DocumentReference(org.hl7.fhir.r4.model.DocumentReference) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Attachment

use of org.hl7.fhir.dstu2016may.model.Attachment in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ORUMessageTest method test_oru_with_specimen.

// Suppress warnings about too many assertions in a test.  Justification: creating a FHIR message is very costly; we need to check many asserts per creation for efficiency.
@java.lang.SuppressWarnings("squid:S5961")
@Test
void test_oru_with_specimen() throws IOException {
    String hl7message = "MSH|^~\\\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|ORU^R01|MSGID000005|T|2.6\r" + "PID||45483|45483||SMITH^SUZIE^||20160813|M|||123 MAIN STREET^^SCHENECTADY^NY^12345||(123)456-7890|||||^^^T||||||||||||\r" + "OBR|1||986^IA PHIMS Stage^2.16.840.1.114222.4.3.3.5.1.2^ISO|1051-2^New Born Screening^LN|||20151009173644|||||||||||||002|||||F|||2740^Tsadok^Janetary~2913^Merrit^Darren^F~3065^Mahoney^Paul^J~4723^Loh^Robert^L~9052^Winter^Oscar^||||3065^Mahoney^Paul^J|\r" + "OBX|1|ST|TS-F-01-002^Endocrine Disorders^L||obs report||||||F\r" + "SPM|1|SpecimenID||BLD|||||||P||||||201410060535|201410060821||Y||||||1\r";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Verify that the right resources are created
    List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
    assertThat(patientResource).hasSize(1);
    List<Resource> diagnosticReport = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
    assertThat(diagnosticReport).hasSize(1);
    List<Resource> servReqResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    assertThat(servReqResource).hasSize(1);
    List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(obsResource).hasSize(1);
    List<Resource> practitionerResource = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
    assertThat(practitionerResource).hasSize(1);
    List<Resource> specimenResource = ResourceUtils.getResourceList(e, ResourceType.Specimen);
    assertThat(specimenResource).hasSize(1);
    // Expecting only the above resources, no extras!
    assertThat(e).hasSize(6);
    // /////////////////////////////////////////
    // Now confirm content of the diagnosticReport because we don't have separate tests for DiagnosticReport
    // /////////////////////////////////////////
    DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(diagnosticReport.get(0), context);
    // Verify status from OBR.25
    assertThat(diag.getStatus().toCode()).isEqualTo("final");
    // Verify category from OBR.24
    assertThat(diag.getCategory()).isEmpty();
    // Verify code from OBR.4
    assertThat(diag.hasCode()).isTrue();
    List<Coding> codings = diag.getCode().getCoding();
    assertThat(codings).hasSize(1);
    Coding coding = codings.get(0);
    assertThat(coding.hasDisplay()).isTrue();
    assertThat(coding.getDisplay()).hasToString("New Born Screening");
    assertThat(coding.hasCode()).isTrue();
    assertThat(coding.getCode()).hasToString("1051-2");
    assertThat(coding.hasSystem()).isTrue();
    assertThat(coding.getSystem()).hasToString("http://loinc.org");
    // Verify encounter reference
    assertThat(diag.getEncounter().isEmpty()).isTrue();
    // Verify subject reference
    assertThat(diag.getSubject().isEmpty()).isFalse();
    // Verify effectiveDateTime from OBR.7 and OBR.8
    // This also verifies the type, confirming effectiveDateTime was set rather than effectivePeriod
    assertThat(diag.getEffectiveDateTimeType().asStringValue()).isEqualTo("2015-10-09T17:36:44+08:00");
    // Verify issued from OBR.22
    assertThat(diag.getIssued()).isNull();
    // Verify resultsInterpreter from OBR.32
    assertThat(diag.getResultsInterpreter()).hasSize(1);
    // Verify basedOn is ref to the ServiceRequest created for ORC or OBR
    assertThat(diag.getBasedOn()).hasSize(1);
    assertThat(diag.getBasedOn().get(0).getReference().substring(0, 15)).isEqualTo("ServiceRequest/");
    // Verify specimen reference
    List<Reference> spmRef = diag.getSpecimen();
    assertThat(spmRef).hasSize(1);
    assertThat(spmRef.get(0).isEmpty()).isFalse();
    // Verify result reference
    List<Reference> obsRef = diag.getResult();
    assertThat(obsRef).hasSize(1);
    assertThat(obsRef.get(0).isEmpty()).isFalse();
    // Verify presentedForm from OBX of type ST - No attachments expected because OBX of type not TX creates an Observation.
    List<Attachment> attachments = diag.getPresentedForm();
    Assertions.assertEquals(0, attachments.size(), "Unexpected number of attachments");
    // //////////////////////////////////
    for (Resource res : obsResource) {
        // Verify encounter reference
        Observation obs = (Observation) res;
        assertThat(obs.getEncounter().isEmpty()).isTrue();
        // Verify subject reference to Patient exists
        assertThat(obs.getSubject().isEmpty()).isFalse();
        assertThat(obs.getSubject().getReference().substring(0, 8)).isEqualTo("Patient/");
    }
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) Attachment(org.hl7.fhir.r4.model.Attachment) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.jupiter.api.Test)

Example 3 with Attachment

use of org.hl7.fhir.dstu2016may.model.Attachment in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ORUMessageTest method test_oru_with_multiple_reports.

// Suppress warnings about too many assertions in a test.  Justification: creating a FHIR message is very costly; we need to check many asserts per creation for efficiency.
@java.lang.SuppressWarnings("squid:S5961")
@Test
void test_oru_with_multiple_reports() throws IOException {
    String hl7message = "MSH|^~\\\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|ORU^R01|MSGID000005|T|2.6\r" + "PID||45483|45483||SMITH^SUZIE^||20160813|M|||123 MAIN STREET^^SCHENECTADY^NY^12345||(123)456-7890|||||^^^T||||||||||||\r" + "OBR|1||986^IA PHIMS Stage^2.16.840.1.114222.4.3.3.5.1.2^ISO|112^Final Echocardiogram Report|||20151009173644|||||||||||||002|||||F|||2740^Tsadok^Janetary~2913^Merrit^Darren^F~3065^Mahoney^Paul^J~4723^Loh^Robert^L~9052^Winter^Oscar^||||3068^JOHN^Paul^J|\r" + "OBX|1|ST|TS-F-01-007^Endocrine Disorders 7^L||obs report||||||F\r" + "OBX|2|ST|TS-F-01-008^Endocrine Disorders 8^L||ECHOCARDIOGRAPHIC REPORT||||||F\r" + "OBR|1||98^IA PHIMS Stage^2.16.840.1.114222.4.3.3.5.1.2^ISO|113^Echocardiogram Report|||20151009173644|||||||||||||002|||||F|||2740^Tsadok^Janetary~2913^Merrit^Darren^F~3065^Mahoney^Paul^J~4723^Loh^Robert^L~9052^Winter^Oscar^||||3065^Mahoney^Paul^J|\r" + "OBX|1|CWE|625-4^Bacteria identified in Stool by Culture^LN^^^^2.33^^result1|1|27268008^Salmonella^SCT^^^^20090731^^Salmonella species|||A^A^HL70078^^^^2.5|||P|||20120301|||^^^^^^^^Bacterial Culture||201203140957||||||\r" + "OBX|2|ST|TS-F-01-002^Endocrine Disorders^L||ECHOCARDIOGRAPHIC REPORT Group 2||||||F\r";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Verify that the right resources are being created
    List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
    assertThat(patientResource).hasSize(1);
    List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(obsResource).hasSize(4);
    List<Resource> practitionerResource = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
    assertThat(practitionerResource).hasSize(2);
    List<Resource> diagnosticReport = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
    assertThat(diagnosticReport).hasSize(2);
    List<Resource> servReqResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    assertThat(servReqResource).hasSize(2);
    // Expecting only the above resources, no extras!
    assertThat(e).hasSize(11);
    // /////////////////////////////////////////
    // Now confirm content of the FIRST diagnosticReport because we don't have separate tests for DiagnosticReport
    // /////////////////////////////////////////
    DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(diagnosticReport.get(0), context);
    // Verify status from OBR.25
    assertThat(diag.getStatus().toCode()).isEqualTo("final");
    // Verify category from OBR.24
    assertThat(diag.getCategory()).isEmpty();
    // Verify code from OBR.4
    assertThat(diag.hasCode()).isTrue();
    List<Coding> codings = diag.getCode().getCoding();
    assertThat(codings).hasSize(1);
    Coding coding = codings.get(0);
    assertThat(coding.hasDisplay()).isTrue();
    assertThat(coding.getDisplay()).hasToString("Final Echocardiogram Report");
    assertThat(coding.hasCode()).isTrue();
    assertThat(coding.getCode()).hasToString("112");
    assertThat(coding.hasSystem()).isFalse();
    // Verify encounter reference
    assertThat(diag.getEncounter().isEmpty()).isTrue();
    // Verify subject reference
    assertThat(diag.getSubject().isEmpty()).isFalse();
    // Verify effectiveDateTime from OBR.7 and OBR.8
    // This also verifies the type, confirming effectiveDateTime was set rather than effectivePeriod
    assertThat(diag.getEffectiveDateTimeType().asStringValue()).isEqualTo("2015-10-09T17:36:44+08:00");
    // Verify issued from OBR.22
    assertThat(diag.getIssued()).isNull();
    // Verify resultsInterpreter from OBR.32
    assertThat(diag.getResultsInterpreter()).hasSize(1);
    // Verify basedOn is ref to the ServiceRequest created for ORC or OBR
    assertThat(diag.getBasedOn()).hasSize(1);
    assertThat(diag.getBasedOn().get(0).getReference().substring(0, 15)).isEqualTo("ServiceRequest/");
    // Verify specimen reference
    assertThat(diag.getSpecimen()).isEmpty();
    // Verify result reference
    List<Reference> obsRef = diag.getResult();
    assertThat(obsRef).hasSize(2);
    assertThat(obsRef.get(0).isEmpty()).isFalse();
    // Verify presentedForm from OBX of type TX - In this case no attachments created because the OBX is not of type TX.
    List<Attachment> attachments = diag.getPresentedForm();
    Assertions.assertEquals(0, attachments.size(), "Unexpected number of attachments");
    // /////////////////////////////////////////
    // Now confirm content of the SECOND diagnosticReport because we don't have separate tests for DiagnosticReport
    // /////////////////////////////////////////
    DiagnosticReport diag2 = ResourceUtils.getResourceDiagnosticReport(diagnosticReport.get(0), context);
    // Verify status from OBR.25
    assertThat(diag2.getStatus().toCode()).isEqualTo("final");
    // Verify category from OBR.24
    assertThat(diag2.getCategory()).isEmpty();
    // Verify code from OBR.4
    assertThat(diag2.hasCode()).isTrue();
    List<Coding> codings2 = diag2.getCode().getCoding();
    assertThat(codings2).hasSize(1);
    Coding coding2 = codings.get(0);
    assertThat(coding2.hasDisplay()).isTrue();
    assertThat(coding2.getDisplay()).hasToString("Final Echocardiogram Report");
    assertThat(coding2.hasCode()).isTrue();
    assertThat(coding2.getCode()).hasToString("112");
    assertThat(coding2.hasSystem()).isFalse();
    // Verify encounter reference
    assertThat(diag2.getEncounter().isEmpty()).isTrue();
    // Verify subject reference
    assertThat(diag2.getSubject().isEmpty()).isFalse();
    // Verify effectiveDateTime from OBR.7 and OBR.8
    // This also verifies the type, confirming effectiveDateTime was set rather than effectivePeriod
    assertThat(diag2.getEffectiveDateTimeType().asStringValue()).isEqualTo("2015-10-09T17:36:44+08:00");
    // Verify issued from OBR.22
    assertThat(diag2.getIssued()).isNull();
    // Verify resultsInterpreter from OBR.32
    assertThat(diag2.getResultsInterpreter()).hasSize(1);
    // Verify basedOn is ref to the ServiceRequest created for ORC or OBR
    assertThat(diag.getBasedOn()).hasSize(1);
    assertThat(diag.getBasedOn().get(0).getReference().substring(0, 15)).isEqualTo("ServiceRequest/");
    // Verify specimen reference
    assertThat(diag2.getSpecimen()).isEmpty();
    // Verify result reference
    List<Reference> obsRef2 = diag2.getResult();
    assertThat(obsRef2).hasSize(2);
    assertThat(obsRef2.get(0).isEmpty()).isFalse();
    // Verify presentedForm from OBX of type TX - In this case no attachments created because the OBX is not type TX.
    List<Attachment> attachments2 = diag2.getPresentedForm();
    Assertions.assertEquals(0, attachments2.size(), "Unexpected number of attachments");
    // //////////////////////////////////
    for (Resource res : obsResource) {
        // Verify encounter reference is not set
        Observation obs = (Observation) res;
        assertThat(obs.getEncounter().isEmpty()).isTrue();
        // Verify subject reference to Patient exists
        Base subject = ResourceUtils.getValue(obs, "subject");
        assertThat(ResourceUtils.getValueAsString(subject, "reference").substring(0, 8)).isEqualTo("Patient/");
    }
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) Attachment(org.hl7.fhir.r4.model.Attachment) Base(org.hl7.fhir.r4.model.Base) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.jupiter.api.Test)

Example 4 with Attachment

use of org.hl7.fhir.dstu2016may.model.Attachment in project cqf-ruler by DBCG.

the class Libraries method getFunctions.

static LibraryFunctions getFunctions(FhirVersionEnum fhirVersionEnum) {
    FhirContext fhirContext = FhirContext.forCached(fhirVersionEnum);
    Class<? extends IBaseResource> libraryClass = fhirContext.getResourceDefinition(LIBRARY_RESOURCE_TYPE).getImplementingClass();
    Function<IBase, List<IBase>> attachments = Reflections.getFunction(libraryClass, "content");
    Function<IBase, String> contentType = Reflections.getPrimitiveFunction(fhirContext.getElementDefinition("Attachment").getImplementingClass(), "contentType");
    Function<IBase, byte[]> content = Reflections.getPrimitiveFunction(fhirContext.getElementDefinition("Attachment").getImplementingClass(), "data");
    Function<IBase, String> version = Reflections.getVersionFunction(libraryClass);
    return new LibraryFunctions(attachments, contentType, content, version);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) ArrayList(java.util.ArrayList) List(java.util.List) IBase(org.hl7.fhir.instance.model.api.IBase)

Example 5 with Attachment

use of org.hl7.fhir.dstu2016may.model.Attachment in project cqf-ruler by DBCG.

the class R4CarePlanToCdsCard method convert.

private static List<CdsCard> convert(RequestGroup requestGroup) {
    List<CdsCard> cards = new ArrayList<>();
    // links
    List<CdsCard.Links> links = new ArrayList<>();
    if (requestGroup.hasExtension()) {
        for (Extension extension : requestGroup.getExtension()) {
            CdsCard.Links link = new CdsCard.Links();
            if (extension.getValue() instanceof Attachment) {
                Attachment attachment = (Attachment) extension.getValue();
                if (attachment.hasUrl()) {
                    link.setUrl(attachment.getUrl());
                }
                if (attachment.hasTitle()) {
                    link.setLabel(attachment.getTitle());
                }
                if (attachment.hasExtension()) {
                    link.setType(attachment.getExtensionFirstRep().getValue().primitiveValue());
                }
            } else {
                throw new RuntimeException("Invalid link extension type: " + extension.getValue().fhirType());
            }
            links.add(link);
        }
    }
    if (requestGroup.hasAction()) {
        for (RequestGroup.RequestGroupActionComponent action : requestGroup.getAction()) {
            IParser jsonParser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser().setPrettyPrint(true);
            CdsCard card = new CdsCard(jsonParser);
            // basic
            if (action.hasTitle()) {
                card.setSummary(action.getTitle());
            }
            if (action.hasDescription()) {
                card.setDetail(action.getDescription());
            }
            if (action.hasExtension()) {
                card.setIndicator(action.getExtensionFirstRep().getValue().toString());
            }
            // source
            if (action.hasDocumentation()) {
                // Assuming first related artifact has everything
                RelatedArtifact documentation = action.getDocumentationFirstRep();
                CdsCard.Source source = new CdsCard.Source();
                if (documentation.hasDisplay()) {
                    source.setLabel(documentation.getDisplay());
                }
                if (documentation.hasUrl()) {
                    source.setUrl(documentation.getUrl());
                }
                if (documentation.hasDocument() && documentation.getDocument().hasUrl()) {
                    source.setIcon(documentation.getDocument().getUrl());
                }
                card.setSource(source);
            }
            if (action.hasSelectionBehavior()) {
                card.setSelectionBehavior(action.getSelectionBehavior().toCode());
            }
            // suggestions
            // TODO - uuid
            boolean hasSuggestions = false;
            CdsCard.Suggestions suggestions = new CdsCard.Suggestions();
            CdsCard.Suggestions.Action actions = new CdsCard.Suggestions.Action();
            if (action.hasPrefix()) {
                suggestions.setLabel(action.getPrefix());
                hasSuggestions = true;
                if (action.hasDescription()) {
                    actions.setDescription(action.getDescription());
                }
                if (action.hasType() && !action.getType().getCodingFirstRep().getCode().equals("fire-event")) {
                    String code = action.getType().getCodingFirstRep().getCode();
                    actions.setType(CdsCard.Suggestions.Action.ActionType.valueOf(code.equals("remove") ? "delete" : code));
                }
                if (action.hasResource()) {
                    if (actions.getType().name().equalsIgnoreCase("create")) {
                        action.getResourceTarget().setId((String) null);
                    }
                    actions.setResource(action.getResourceTarget());
                }
            }
            if (hasSuggestions) {
                suggestions.addAction(actions);
                card.addSuggestion(suggestions);
            }
            if (!links.isEmpty()) {
                card.setLinks(links);
            }
            cards.add(card);
        }
    }
    return cards;
}
Also used : ArrayList(java.util.ArrayList) Attachment(org.hl7.fhir.r4.model.Attachment) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) Extension(org.hl7.fhir.r4.model.Extension) RequestGroup(org.hl7.fhir.r4.model.RequestGroup) IParser(ca.uhn.fhir.parser.IParser)

Aggregations

Attachment (org.hl7.fhir.r4.model.Attachment)33 Reference (org.hl7.fhir.r4.model.Reference)17 ArrayList (java.util.ArrayList)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 Coding (org.hl7.fhir.r4.model.Coding)11 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)10 List (java.util.List)9 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)9 Observation (org.hl7.fhir.r4.model.Observation)9 Test (org.junit.jupiter.api.Test)9 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)8 Resource (org.hl7.fhir.r4.model.Resource)8 FhirContext (ca.uhn.fhir.context.FhirContext)5 HashMap (java.util.HashMap)5 Base64 (org.apache.commons.codec.binary.Base64)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)5 Extension (org.hl7.fhir.r4.model.Extension)5 Library (org.hl7.fhir.r4.model.Library)5