use of org.hl7.fhir.r4.model.Medication 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.Medication in project gpconnect-demonstrator by nhsconnect.
the class MedicationAdministrationResourceProvider method getMedicationAdministrationsForPatientId.
@Search
public List<MedicationAdministration> getMedicationAdministrationsForPatientId(@RequiredParam(name = "patient") String patientId) {
ArrayList<MedicationAdministration> medicationAdministrations = new ArrayList<>();
List<MedicationAdministrationDetail> medicationAdministrationDetailList = medicationAdministrationSearch.findMedicationAdministrationForPatient(Long.parseLong(patientId));
if (medicationAdministrationDetailList != null && !medicationAdministrationDetailList.isEmpty()) {
for (MedicationAdministrationDetail medicationAdministrationDetail : medicationAdministrationDetailList) {
MedicationAdministration medicationAdministration = new MedicationAdministration();
String resourceId = String.valueOf(medicationAdministrationDetail.getId());
String versionId = String.valueOf(medicationAdministrationDetail.getLastUpdated().getTime());
String resourceType = medicationAdministration.getResourceType().toString();
IdType id = new IdType(resourceType, resourceId, versionId);
medicationAdministration.setId(id);
medicationAdministration.getMeta().setVersionId(versionId);
medicationAdministration.getMeta().setLastUpdated(medicationAdministrationDetail.getLastUpdated());
medicationAdministration.addDefinition(new Reference("Patient/" + medicationAdministrationDetail.getPatientId()));
medicationAdministration.addDefinition(new Reference("Practitioner/" + medicationAdministrationDetail.getPractitionerId()));
medicationAdministration.setPrescription(new Reference("MedicationOrder/" + medicationAdministrationDetail.getPrescriptionId()));
medicationAdministration.setEffective(new DateType(medicationAdministrationDetail.getAdministrationDate()));
medicationAdministration.setMedication(new Reference("Medication/" + medicationAdministrationDetail.getMedicationId()));
medicationAdministrations.add(medicationAdministration);
}
}
return medicationAdministrations;
}
use of org.hl7.fhir.r4.model.Medication in project gpconnect-demonstrator by nhsconnect.
the class MedicationOrderResourceProvider method medicationOrderDetailsToMedicationOrderResourceConverter.
private MedicationRequest medicationOrderDetailsToMedicationOrderResourceConverter(MedicationOrderDetails medicationOrderDetails) {
MedicationRequest medicationOrder = new MedicationRequest();
String resourceId = String.valueOf(medicationOrderDetails.getId());
String versionId = String.valueOf(medicationOrderDetails.getLastUpdated().getTime());
String resourceType = medicationOrder.getResourceType().toString();
IdType id = new IdType(resourceType, resourceId, versionId);
medicationOrder.setId(id);
medicationOrder.getMeta().setVersionId(versionId);
medicationOrder.getMeta().setLastUpdated(medicationOrderDetails.getLastUpdated());
switch(medicationOrderDetails.getOrderStatus().toLowerCase(Locale.UK)) {
case "active":
medicationOrder.setStatus(MedicationRequestStatus.ACTIVE);
break;
case "completed":
medicationOrder.setStatus(MedicationRequestStatus.COMPLETED);
break;
case "draft":
medicationOrder.setStatus(MedicationRequestStatus.DRAFT);
break;
case "entered_in_error":
medicationOrder.setStatus(MedicationRequestStatus.ENTEREDINERROR);
break;
case "on_hold":
medicationOrder.setStatus(MedicationRequestStatus.ONHOLD);
break;
case "stopped":
medicationOrder.setStatus(MedicationRequestStatus.STOPPED);
break;
}
if (medicationOrderDetails.getPatientId() != null) {
medicationOrder.setSubject(new Reference("Patient/" + medicationOrderDetails.getPatientId()));
} else {
medicationOrder.setSubject(new Reference());
}
medicationOrder.setRecorder(new Reference("Practitioner/" + medicationOrderDetails.getAutherId()));
medicationOrder.setMedication(new Reference("Medication/" + medicationOrderDetails.getMedicationId()));
medicationOrder.addDosageInstruction().setText(medicationOrderDetails.getDosageText());
MedicationRequestDispenseRequestComponent dispenseRequest = new MedicationRequestDispenseRequestComponent();
dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_MEDICATION_QUANTITY_TEXT, new StringDt(medicationOrderDetails.getDispenseQuantityText())));
dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_PERSCRIPTION_REPEAT_REVIEW_DATE, new DateTimeDt(medicationOrderDetails.getDispenseReviewDate())));
dispenseRequest.setId("Medication/" + medicationOrderDetails.getDispenseMedicationId());
dispenseRequest.setNumberOfRepeatsAllowed(medicationOrderDetails.getDispenseRepeatsAllowed());
medicationOrder.setDispenseRequest(dispenseRequest);
return medicationOrder;
}
use of org.hl7.fhir.r4.model.Medication in project gpconnect-demonstrator by nhsconnect.
the class MedicationResourceProvider method getMedicationById.
@Read()
public Medication getMedicationById(@IdParam IdType medicationId) {
MedicationEntity medicationEntity = medicationRepository.findOne(medicationId.getIdPartAsLong());
if (medicationEntity == null) {
OperationOutcome operationalOutcome = new OperationOutcome();
operationalOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics("No medication details found for ID: " + medicationId.getIdPart());
throw new InternalErrorException("No medication details found for ID: " + medicationId.getIdPart(), operationalOutcome);
}
Medication medication = new Medication();
String resourceId = String.valueOf(medicationEntity.getId());
String versionId = String.valueOf(medicationEntity.getLastUpdated().getTime());
String resourceType = medication.getResourceType().toString();
IdType id = new IdType(resourceType, resourceId, versionId);
medication.setId(id);
medication.getMeta().setVersionId(versionId);
medication.getMeta().setLastUpdated(medicationEntity.getLastUpdated());
return medication;
}
use of org.hl7.fhir.r4.model.Medication in project gpconnect-demonstrator by nhsconnect.
the class MedicationRequestResourceProvider method getMedicationRequestFromDetail.
private MedicationRequest getMedicationRequestFromDetail(MedicationRequestDetail requestDetail) {
MedicationRequest medicationRequest = new MedicationRequest();
medicationRequest.setId(requestDetail.getId().toString());
List<Identifier> identifiers = new ArrayList<>();
Identifier identifier = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(requestDetail.getGuid());
identifiers.add(identifier);
medicationRequest.setIdentifier(identifiers);
medicationRequest.setMeta(new Meta().addProfile(SystemURL.SD_GPC_MEDICATION_REQUEST));
setBasedOnReferences(medicationRequest, requestDetail);
if (requestDetail.getPrescriptionTypeCode().contains("repeat")) {
medicationRequest.setGroupIdentifier(new Identifier().setValue(requestDetail.getGroupIdentifier()));
}
try {
medicationRequest.setStatus(MedicationRequestStatus.fromCode(requestDetail.getStatusCode()));
} catch (FHIRException e) {
throw new UnprocessableEntityException(e.getMessage());
}
try {
medicationRequest.setIntent(MedicationRequestIntent.fromCode(requestDetail.getIntentCode()));
} catch (FHIRException e) {
throw new UnprocessableEntityException(e.getMessage());
}
if (requestDetail.getMedicationId() != null) {
medicationRequest.setMedication(new Reference(new IdType("Medication", requestDetail.getMedicationId())));
}
if (requestDetail.getPatientId() != null) {
medicationRequest.setSubject(new Reference(new IdType("Patient", requestDetail.getPatientId())));
}
if (requestDetail.getAuthorisingPractitionerId() != null) {
medicationRequest.setRecorder(new Reference(new IdType("Practitioner", requestDetail.getAuthorisingPractitionerId())));
}
if (requestDetail.getPriorMedicationRequestId() != null) {
medicationRequest.setPriorPrescription(new Reference(new IdType("MedicationRequest", requestDetail.getPriorMedicationRequestId())));
}
medicationRequest.setAuthoredOn(requestDetail.getAuthoredOn());
medicationRequest.setDispenseRequest(getDispenseRequestComponent(requestDetail));
// medicationRequest.setRequester(getRequesterComponent(requestDetail)); //TODO - spec needs to clarify whether this should be populated or not
setReasonCodes(medicationRequest, requestDetail);
setNotes(medicationRequest, requestDetail);
if (medicationRequest.getIntent() != MedicationRequestIntent.ORDER) {
setRepeatInformation(medicationRequest, requestDetail);
}
setPrescriptionType(medicationRequest, requestDetail);
setStatusReason(medicationRequest, requestDetail);
String dosageInstructionText = requestDetail.getDosageText();
medicationRequest.addDosageInstruction(new Dosage().setText(dosageInstructionText == null || dosageInstructionText.trim().isEmpty() ? NO_INFORMATION_AVAILABLE : dosageInstructionText).setPatientInstruction(requestDetail.getDosageInstructions()));
return medicationRequest;
}
Aggregations