Search in sources :

Example 61 with Attachment

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

the class ActivityDefinitionApplyProvider method resolveTask.

private Task resolveTask(ActivityDefinition activityDefinition, String patientId) {
    Task task = new Task();
    task.setStatus(Task.TaskStatus.DRAFT);
    task.setIntent(Task.TaskIntent.PROPOSAL);
    task.setFor(new Reference(patientId));
    Task.ParameterComponent input = new Task.ParameterComponent();
    if (activityDefinition.hasCode()) {
        task.setCode(activityDefinition.getCode());
        input.setType(activityDefinition.getCode());
    }
    // Extension defined by CPG-on-FHIR for Questionnaire canonical URI
    Extension collectsWith = activityDefinition.getExtensionByUrl("http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-collectWith");
    if (collectsWith != null && collectsWith.getValueAsPrimitive().toString() != null) {
        CanonicalType uri = new CanonicalType(collectsWith.getValueAsPrimitive().toString());
        input.setValue(uri);
    }
    if (activityDefinition.hasRelatedArtifact()) {
        for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
            if (artifact.hasUrl()) {
                Attachment attachment = new Attachment().setUrl(artifact.getUrl());
                if (artifact.hasDisplay()) {
                    attachment.setTitle(artifact.getDisplay());
                }
                input.setValue(artifact.hasDisplay() ? attachment.setTitle(artifact.getDisplay()) : attachment);
            }
        // TODO - other relatedArtifact types
        }
    }
    // If input has been populated, then add it to the Task.
    if (input.getType() != null || input.getValue() != null) {
        task.addInput(input);
    }
    return task;
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Task(org.hl7.fhir.r4.model.Task) Reference(org.hl7.fhir.r4.model.Reference) Attachment(org.hl7.fhir.r4.model.Attachment) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) CanonicalType(org.hl7.fhir.r4.model.CanonicalType)

Example 62 with Attachment

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

the class STU3CarePlanToCdsCard 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.DSTU3).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.hasLabel()) {
                suggestions.setLabel(action.getLabel());
                hasSuggestions = true;
                if (action.hasDescription()) {
                    actions.setDescription(action.getDescription());
                }
                if (action.hasType() && !action.getType().getCode().equals("fire-event")) {
                    String code = action.getType().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.dstu3.model.Attachment) RelatedArtifact(org.hl7.fhir.dstu3.model.RelatedArtifact) Extension(org.hl7.fhir.dstu3.model.Extension) RequestGroup(org.hl7.fhir.dstu3.model.RequestGroup) IParser(ca.uhn.fhir.parser.IParser)

Example 63 with Attachment

use of org.hl7.fhir.r4.model.Attachment in project beneficiary-fhir-data by CMSgov.

the class PartDEventTransformerV2Test method shouldHaveCtstrphcCvrgCdSupInfo.

@Test
public void shouldHaveCtstrphcCvrgCdSupInfo() {
    SupportingInformationComponent sic = TransformerTestUtilsV2.findSupportingInfoByCode("https://bluebutton.cms.gov/resources/variables/ctstrphc_cvrg_cd", eob.getSupportingInfo());
    SupportingInformationComponent compare = TransformerTestUtilsV2.createSupportingInfo(// We don't care what the sequence number is here
    sic.getSequence(), // Category
    Arrays.asList(new Coding("http://terminology.hl7.org/CodeSystem/claiminformationcategory", "info", "Information"), new Coding("https://bluebutton.cms.gov/resources/codesystem/information", "https://bluebutton.cms.gov/resources/variables/ctstrphc_cvrg_cd", "Catastrophic Coverage Code")), // Code
    new Coding("https://bluebutton.cms.gov/resources/variables/ctstrphc_cvrg_cd", "C", "Above attachment point"));
    assertTrue(compare.equalsDeep(sic));
}
Also used : SupportingInformationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent) Coding(org.hl7.fhir.r4.model.Coding) Test(org.junit.jupiter.api.Test)

Example 64 with Attachment

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

the class Hl7DocumentReferenceFHIRConversionTest method doc_ref_ppr_test.

@ParameterizedTest
// Spot check for PPR messages
@ValueSource(strings = { "PPR^PC1" /* "PPR^PC2", "PPR^PC3" */
})
void doc_ref_ppr_test(String messageType) {
    String documentReferenceMessage = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|202101010000|security|" + messageType + "|1|P^I|2.6||||||ASCII||\r" + "PID|||1234^^^^MR||DOE^JANE^|||F|||||||||||||||||||||\r" + "PV1||I|6N^1234^A^GENHOS|||||||SUR|||||||0148^ANDERSON^CARL|S|1400|A|||||||||||||||||||SF|K||||199501102300\r" + "PRB|AD||202101010000|aortic stenosis|53692||2|||202101010000\r" + "OBX|1|NM|111^TotalProtein||7.5|gm/dl|5.9-8.4||||F\r" + "NTE|1|P|Problem Comments\r" + "ORC|NW|1000^OE|9999999^RX|||E|^Q6H^D10^^^R\r" + "OBR|1|TESTID|TESTID|||201801180346|201801180347||||||||||||||||||F||||||WEAKNESS||||||||||||\r" + // Next three lines create an attachment because OBX type TX
    "OBX|1|TX|||ECHOCARDIOGRAPHIC REPORT||||||F|||202101010000|||\r" + "OBX|2|TX|||NORMAL LV CHAMBER SIZE WITH MILD CONCENTRIC LVH||||||F|||202101010000|||\r" + "OBX|3|TX|||HYPERDYNAMIC LV SYSTOLIC FUNCTION, VISUAL EF 80%||||||F|||202101010000|||\n";
    DocumentReference documentRef = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    DocumentReference.DocumentReferenceContextComponent drContext = documentRef.getContext();
    // Should contain a reference to the service request
    assertThat(drContext.hasPeriod()).isFalse();
    DocumentReference.DocumentReferenceContentComponent content = documentRef.getContentFirstRep();
    // Currently always defaults to text/plain
    assertThat(content.getAttachment().getContentType()).isEqualTo("text/plain");
    // No TXA.7 in message
    assertThat(content.getAttachment().getCreation()).isNull();
    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%");
}
Also used : DocumentReference(org.hl7.fhir.r4.model.DocumentReference) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with Attachment

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

the class Hl7ORUMessageTest method test_oru_multipleOBXofDifferentTypes.

/**
 * ORU messages with an OBR and multiple OBX segments create records only for non TX type OBX
 * The OBX type TX are added to the presentedForm as an attachment for the diagnostic
 * @throws IOException
 */
// 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_multipleOBXofDifferentTypes() throws IOException {
    String json = ftv.convert(new File("src/test/resources/ORU-multiline-short.hl7"), OPTIONS_PRETTYPRINT);
    assertThat(json).isNotBlank();
    LOGGER.debug("FHIR json result:\n" + json);
    // Verify conversion
    FHIRContext context = new FHIRContext();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    Assertions.assertSame(BundleType.COLLECTION, b.getType(), "Bundle type not expected");
    List<BundleEntryComponent> e = b.getEntry();
    // Verify that the right resources have been created
    List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
    assertThat(patientResource).hasSize(1);
    List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    assertThat(encounterResource).hasSize(1);
    List<Resource> organizationResource = ResourceUtils.getResourceList(e, ResourceType.Organization);
    // We expect an organization created from an Encounter.serviceProvider reference
    assertThat(organizationResource).hasSize(1);
    List<Resource> practitionerResource = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
    assertThat(practitionerResource).hasSize(4);
    List<Resource> messageHeader = ResourceUtils.getResourceList(e, ResourceType.MessageHeader);
    assertThat(messageHeader).hasSize(1);
    // Verify Diagnostic Report is created as expected
    List<Resource> reportResource = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
    assertThat(reportResource).hasSize(1);
    List<Resource> servReqResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    assertThat(servReqResource).hasSize(1);
    // Verify there are no extra resources created
    assertThat(e).hasSize(10);
    // Verify no observations are created
    List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
    // TODO: When NTE is implemented, then update this to one.
    assertThat(obsResource).isEmpty();
    // /////////////////////////////////////////
    // Now confirm content of the diagnosticReport because we don't have separate tests for DiagnosticReport
    // /////////////////////////////////////////
    DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(reportResource.get(0), context);
    // Verify status from OBR.25
    assertThat(diag.getStatus().toCode()).isEqualTo("final");
    // Verify category from OBR.24
    assertThat(diag.getCategory()).hasSize(1);
    DatatypeUtils.checkCommonCodeableConceptAssertions(diag.getCategoryFirstRep(), "CT", "CAT Scan", "http://terminology.hl7.org/CodeSystem/v2-0074", "CT");
    // Verify code from OBR.4; This tests scenario of the code not being in the default loinc system.
    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("ECHO CARDIOGRAM COMPLETE");
    assertThat(coding.hasCode()).isTrue();
    assertThat(coding.getCode()).hasToString("1487");
    assertThat(coding.hasSystem()).isFalse();
    // Verify encounter reference
    assertThat(diag.getEncounter().isEmpty()).isFalse();
    // 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("2020-08-02T12:44:55+08:00");
    // Verify issued from OBR.22
    assertThat(diag.getIssued()).isNull();
    // Verify resultsInterpreter from OBR.32
    assertThat(diag.getResultsInterpreter()).isEmpty();
    // 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).isEmpty();
    // Verify result reference
    List<Reference> obsRef = diag.getResult();
    assertThat(obsRef).isEmpty();
    // Verify attachment to diagnostic report
    List<Attachment> attachments = diag.getPresentedForm();
    Assertions.assertEquals(1, attachments.size(), "Unexpected number of attachments");
    Attachment a = attachments.get(0);
    Assertions.assertTrue(a.getContentType().equalsIgnoreCase("text/plain"), "Incorrect content type");
    Assertions.assertTrue(a.getLanguage().equalsIgnoreCase("en"), "Incorrect language");
    // Verify data attachment after decoding
    String decoded = new String(Base64.getDecoder().decode(a.getDataElement().getValueAsString()));
    System.out.println("Decoded: '" + decoded + "'");
    Assertions.assertEquals("\n[PII] Emergency Department\nED Encounter Arrival Date: [ADDRESS] [PERSONALNAME]:", decoded, "Incorrect data");
    Assertions.assertTrue(a.getTitle().equalsIgnoreCase("ECHO CARDIOGRAM COMPLETE"), "Incorrect title");
    // Verify creation data is persisted correctly - 2020-08-02T12:44:55+08:00
    Calendar c = Calendar.getInstance();
    // needed to completely clear out calendar object
    c.clear();
    c.set(2020, 7, 2, 12, 44, 55);
    c.setTimeZone(TimeZone.getTimeZone(ZoneId.of("+08:00")));
    Date d = c.getTime();
    Assertions.assertEquals(d, a.getCreation(), "Incorrect creation date");
    // //////////////////////////////////
    for (Resource res : obsResource) {
        // Verify encounter reference exists
        Observation obs = (Observation) res;
        assertThat(obs.getEncounter().isEmpty()).isFalse();
        assertThat(obs.getEncounter().getReference().substring(0, 10)).isEqualTo("Encounter/");
        // Verify subject reference to Patient exists
        assertThat(obs.getSubject().isEmpty()).isFalse();
        assertThat(obs.getSubject().getReference().substring(0, 8)).isEqualTo("Patient/");
    }
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) Bundle(org.hl7.fhir.r4.model.Bundle) Reference(org.hl7.fhir.r4.model.Reference) Calendar(java.util.Calendar) 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) Date(java.util.Date) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

Attachment (org.hl7.fhir.r4.model.Attachment)33 ArrayList (java.util.ArrayList)32 Attachment (com.ibm.cloud.cloudant.v1.model.Attachment)17 Reference (org.hl7.fhir.r4.model.Reference)17 Test (org.testng.annotations.Test)17 DocumentRevisionStatus (com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus)16 Revisions (com.ibm.cloud.cloudant.v1.model.Revisions)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 HashMap (java.util.HashMap)12 Coding (org.hl7.fhir.r4.model.Coding)11 Document (com.ibm.cloud.cloudant.v1.model.Document)10 List (java.util.List)10 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)10 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 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)8 Resource (org.hl7.fhir.r4.model.Resource)8 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)7