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();
}
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);
}
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());
});
}
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;
}
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;
}
Aggregations