Search in sources :

Example 11 with MEDICATIONSTATEMENT

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project eCRNow by drajer-health.

the class FhirEicrGeneratorFromR4 method convertR4FhirBundletoCdaEicr.

public static String convertR4FhirBundletoCdaEicr(R4FhirData data) {
    StringBuilder eICR = new StringBuilder();
    if (data != null) {
        Bundle bundle = data.getData();
        if (bundle != null) {
            List<BundleEntryComponent> entries = bundle.getEntry();
            for (BundleEntryComponent ent : entries) {
                // Populate data ..this can be moved to the APIs where the bundle is getting created.
                if (ent.getResource() instanceof Patient) {
                    logger.info(" Bundle contains Patient ");
                    data.setPatient((Patient) ent.getResource());
                } else if (ent.getResource() instanceof Practitioner) {
                    logger.info(" Bundle contains Practitioner ");
                    data.setPractitioner((Practitioner) ent.getResource());
                } else if (ent.getResource() instanceof Encounter) {
                    logger.info(" Bundle contains Encounter ");
                    data.setEncounter((Encounter) ent.getResource());
                } else if (ent.getResource() instanceof Location) {
                    logger.info(" Bundle contains Location ");
                    data.setLocation((Location) ent.getResource());
                } else if (ent.getResource() instanceof Organization) {
                    logger.info(" Bundle contains Organization ");
                    data.setOrganization((Organization) ent.getResource());
                } else if (ent.getResource() instanceof Condition) {
                    logger.info(" Bundle contains Condition ");
                    data.getConditions().add((Condition) ent.getResource());
                } else if (ent.getResource() instanceof Observation) {
                    logger.info(" Bundle constains Observation ");
                    Observation obs = (Observation) ent.getResource();
                } else if (ent.getResource() instanceof DiagnosticReport) {
                    logger.info(" Bundle contains Diagnostic Report ");
                    data.getDiagReports().add((DiagnosticReport) ent.getResource());
                } else if (ent.getResource() instanceof MedicationStatement) {
                    logger.info(" Bundle contains MedicationStatement ");
                    data.getMedications().add((MedicationStatement) ent.getResource());
                } else if (ent.getResource() instanceof Immunization) {
                    logger.info(" Bundle contains Immunization ");
                    data.getImmunizations().add((Immunization) ent.getResource());
                }
            }
        }
    } else {
        logger.error(" No Fhir Bundle Available to create CDA Documents ");
    }
    return eICR.toString();
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Immunization(org.hl7.fhir.r4.model.Immunization) Organization(org.hl7.fhir.r4.model.Organization) Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) Practitioner(org.hl7.fhir.r4.model.Practitioner) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Observation(org.hl7.fhir.r4.model.Observation) Encounter(org.hl7.fhir.r4.model.Encounter) MedicationStatement(org.hl7.fhir.r4.model.MedicationStatement) Location(org.hl7.fhir.r4.model.Location)

Example 12 with MEDICATIONSTATEMENT

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project nia-patient-switching-standard-adaptor by NHSDigital.

the class MedicationStatementMapperTest method When_MappingPrescribeResourceWithNoOptionals_Expect_AllFieldsToBeMappedCorrectly.

@Test
public void When_MappingPrescribeResourceWithNoOptionals_Expect_AllFieldsToBeMappedCorrectly() {
    var ehrExtract = unmarshallEhrExtract("ehrExtract3.xml");
    var medicationStatement = unmarshallMedicationStatement("medicationStatementAuthoriseAllOptionals_MedicationStatement.xml");
    var authorise = medicationStatement.getComponent().stream().filter(RCMRMT030101UK04Component2::hasEhrSupplyAuthorise).map(RCMRMT030101UK04Component2::getEhrSupplyAuthorise).findFirst();
    when(medicationMapper.extractMedicationReference(any())).thenReturn(Optional.of(new Reference(new IdType(ResourceType.Medication.name(), MEDICATION_ID))));
    assertThat(authorise.isPresent()).isTrue();
    var medicationStatement1 = medicationStatementMapper.mapToMedicationStatement(ehrExtract, medicationStatement, authorise.get(), PRACTISE_CODE, new DateTimeType());
    var lastIssuedDate = medicationStatement1.getExtensionsByUrl("https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-MedicationStatementLastIssueDate-1");
    assertThat(lastIssuedDate.size()).isEqualTo(1);
    var dateTime = (DateTimeType) lastIssuedDate.get(0).getValue();
    assertThat(dateTime.getValue()).isEqualTo(DateFormatUtil.parseToDateTimeType("20060428").getValue());
    var prescribingAgency = medicationStatement1.getExtensionsByUrl("https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-PrescribingAgency-1");
    assertThat(prescribingAgency.size()).isEqualTo(1);
    assertThat(medicationStatement1.getBasedOnFirstRep().getReferenceElement().getIdPart()).isEqualTo(TEST_ID);
    assertThat(medicationStatement1.getStatus()).isEqualTo(ACTIVE);
    assertThat(medicationStatement1.getMedicationReference().getReferenceElement().getIdPart()).isEqualTo(MEDICATION_ID);
    assertThat(medicationStatement1.getTaken()).isEqualTo(UNK);
    assertThat(medicationStatement1.getDosageFirstRep().getText()).isEqualTo(TAKE_ONE_DAILY);
}
Also used : DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Reference(org.hl7.fhir.dstu3.model.Reference) RCMRMT030101UK04Component2(org.hl7.v3.RCMRMT030101UK04Component2) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.jupiter.api.Test)

Example 13 with MEDICATIONSTATEMENT

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project nia-patient-switching-standard-adaptor by NHSDigital.

the class MedicationRequestMapperTest method When_MappingMedicationStatement_Expect_CorrectMappersToBeCalled.

@Test
public void When_MappingMedicationStatement_Expect_CorrectMappersToBeCalled() {
    var ehrExtract = unmarshallEhrExtract("ehrExtract1.xml");
    when(medicationRequestPlanMapper.mapToPlanMedicationRequest(any(), any(), any(), any())).thenReturn(new MedicationRequest());
    when(medicationRequestOrderMapper.mapToOrderMedicationRequest(any(), any(), any(), any())).thenReturn(new MedicationRequest());
    when(medicationStatementMapper.mapToMedicationStatement(any(), any(), any(), any(), any())).thenReturn(new MedicationStatement());
    when(medicationMapper.createMedication(any())).thenReturn(new Medication());
    var resources = medicationRequestMapper.mapResources(ehrExtract, (Patient) new Patient().setId(PATIENT_ID), List.of(), PRACTISE_CODE);
    verify(medicationRequestPlanMapper, times(DOUBLE_INVOCATION)).mapToPlanMedicationRequest(any(), any(), any(), any());
    verify(medicationRequestOrderMapper, times(SINGLE_INVOCATION)).mapToOrderMedicationRequest(any(), any(), any(), any());
    verify(medicationStatementMapper, times(DOUBLE_INVOCATION)).mapToMedicationStatement(any(), any(), any(), any(), any());
    verify(medicationMapper, times(SINGLE_INVOCATION)).createMedication(any());
    assertThat(resources.size()).isEqualTo(EXPECTED_RESOURCES_MAPPED);
    resources.stream().filter(resource -> ResourceType.MedicationRequest.equals(resource.getResourceType())).map(MedicationRequest.class::cast).forEach(medicationRequest -> {
        assertThat(medicationRequest.getSubject().getResource().getIdElement().getIdPart()).isEqualTo(PATIENT_ID);
        assertThat(medicationRequest.getAuthoredOnElement().getValue()).isEqualTo(EXPECTED_DATE_TIME_TYPE.getValue());
    });
    resources.stream().filter(resource -> ResourceType.MedicationStatement.equals(resource.getResourceType())).map(MedicationStatement.class::cast).forEach(medicationStatement -> {
        assertThat(medicationStatement.getSubject().getResource().getIdElement().getIdPart()).isEqualTo(PATIENT_ID);
        assertThat(medicationStatement.getDateAssertedElement().getValue()).isEqualTo(EXPECTED_DATE_TIME_TYPE.getValue());
    });
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) Medication(org.hl7.fhir.dstu3.model.Medication) Patient(org.hl7.fhir.dstu3.model.Patient) MedicationStatement(org.hl7.fhir.dstu3.model.MedicationStatement) Test(org.junit.jupiter.api.Test)

Example 14 with MEDICATIONSTATEMENT

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project nia-patient-switching-standard-adaptor by NHSDigital.

the class MedicationRequestOrderMapper method mapToOrderMedicationRequest.

public MedicationRequest mapToOrderMedicationRequest(RCMRMT030101UK04EhrExtract ehrExtract, RCMRMT030101UK04MedicationStatement medicationStatement, RCMRMT030101UK04Prescribe supplyPrescribe, String practiseCode) {
    var ehrSupplyPrescribeIdExtract = extractEhrSupplyPrescribeId(supplyPrescribe);
    var inFulfillmentOfId = extractInFulfillmentOfId(supplyPrescribe);
    if (ehrSupplyPrescribeIdExtract.isPresent()) {
        var ehrSupplyPrescribeId = ehrSupplyPrescribeIdExtract.get();
        MedicationRequest medicationRequest = createMedicationRequestSkeleton(ehrSupplyPrescribeId);
        medicationRequest.addIdentifier(buildIdentifier(ehrSupplyPrescribeId, practiseCode));
        medicationRequest.setStatus(COMPLETED);
        medicationRequest.setIntent(ORDER);
        medicationRequest.addDosageInstruction(buildDosage(medicationStatement.getPertinentInformation()));
        medicationRequest.setDispenseRequest(buildDispenseRequestForPrescribe(supplyPrescribe));
        buildNotesForPrescribe(supplyPrescribe).forEach(medicationRequest::addNote);
        medicationMapper.extractMedicationReference(medicationStatement).ifPresent(medicationRequest::setMedication);
        inFulfillmentOfId.ifPresent(inFulfillmentId -> {
            var supplyAuthorise = extractSupplyAuthorise(ehrExtract, inFulfillmentId);
            buildPrescriptionTypeExtension(supplyAuthorise).ifPresent(medicationRequest::addExtension);
            medicationRequest.addBasedOn(buildMedicationRequestReference(inFulfillmentId));
        });
        return medicationRequest;
    }
    return null;
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest)

Example 15 with MEDICATIONSTATEMENT

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project gpconnect-demonstrator by nhsconnect.

the class PopulateMedicationBundle method getPractitionerIds.

private Set<String> getPractitionerIds(MedicationStatement medStatement, List<MedicationRequest> allMedReqs) {
    Set<String> practitionerIds = new HashSet<>();
    medStatement.getNote().forEach(note -> {
        try {
            if (note.getAuthorReference() != null && note.getAuthorReference().getReference() != null && note.getAuthorReference().getReference().startsWith("Practitioner")) {
                String[] split = note.getAuthorReference().getReference().split("/");
                practitionerIds.add(split[1]);
            }
        } catch (FHIRException e) {
            throw new UnprocessableEntityException(e.getMessage());
        }
    });
    allMedReqs.forEach(medReq -> {
        medReq.getNote().forEach(note -> {
            try {
                if (note.getAuthorReference() != null && note.getAuthorReference().getReference() != null && note.getAuthorReference().getReference().startsWith("Practitioner")) {
                    String[] split = note.getAuthorReference().getReference().split("/");
                    practitionerIds.add(split[1]);
                }
            } catch (FHIRException e) {
                throw new UnprocessableEntityException(e.getMessage());
            }
        });
        if (medReq.getRecorder() != null && medReq.getRecorder().getReference().startsWith("Practitioner")) {
            String[] split = medReq.getRecorder().getReference().split("/");
            practitionerIds.add(split[1]);
        }
    });
    return practitionerIds;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

ArrayList (java.util.ArrayList)11 MedicationStatement (org.hl7.fhir.r4.model.MedicationStatement)9 Test (org.junit.jupiter.api.Test)9 Coding (org.hl7.fhir.r4.model.Coding)8 Reference (org.hl7.fhir.dstu3.model.Reference)6 IdType (org.hl7.fhir.dstu3.model.IdType)5 Date (java.util.Date)4 RCMRMT030101UK04Component2 (org.hl7.v3.RCMRMT030101UK04Component2)4 RCMRMT030101UK04EhrExtract (org.hl7.v3.RCMRMT030101UK04EhrExtract)4 DateTimeType (org.hl7.fhir.dstu3.model.DateTimeType)3 Extension (org.hl7.fhir.dstu3.model.Extension)3 Bundle (org.hl7.fhir.r4.model.Bundle)3 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)2 FileOutputStream (java.io.FileOutputStream)2 List (java.util.List)2 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)2 MedicationRequest (org.hl7.fhir.dstu3.model.MedicationRequest)2 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)2 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)2 Condition (org.hl7.fhir.r4.model.Condition)2