use of org.hl7.fhir.dstu3.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.dstu3.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.dstu3.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.dstu3.model.Medication in project bunsen by cerner.
the class TestData method newMedRequest.
/**
* Returns a FHIR medication request for testing purposes.
*/
public static MedicationRequest newMedRequest() {
MedicationRequest medReq = new MedicationRequest();
medReq.setId("test-med");
// Medication code
CodeableConcept med = new CodeableConcept();
med.addCoding().setSystem("http://www.nlm.nih.gov/research/umls/rxnorm").setCode("582620").setDisplay("Nizatidine 15 MG/ML Oral Solution [Axid]");
med.setText("Nizatidine 15 MG/ML Oral Solution [Axid]");
medReq.setMedication(med);
Annotation annotation = new Annotation();
annotation.setText("Test medication note.");
annotation.setAuthor(new Reference("Provider/example").setDisplay("Example provider."));
medReq.addNote(annotation);
return medReq;
}
use of org.hl7.fhir.dstu3.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