use of org.hl7.fhir.r4.model.IdType in project gpconnect-demonstrator by nhsconnect.
the class AppointmentResourceProvider method updateAppointment.
@Update
public MethodOutcome updateAppointment(@IdParam IdType appointmentId, @ResourceParam Appointment appointment) {
MethodOutcome methodOutcome = new MethodOutcome();
OperationOutcome operationalOutcome = new OperationOutcome();
AppointmentDetail appointmentDetail = appointmentResourceConverterToAppointmentDetail(appointment);
// URL ID and Resource ID must be the same
if (!Objects.equals(appointmentId.getIdPartAsLong(), appointmentDetail.getId())) {
operationalOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics("Id in URL (" + appointmentId.getIdPart() + ") should match Id in Resource (" + appointmentDetail.getId() + ")");
methodOutcome.setOperationOutcome(operationalOutcome);
return methodOutcome;
}
// Make sure there is an existing appointment to be amended
AppointmentDetail oldAppointmentDetail = appointmentSearch.findAppointmentByID(appointmentId.getIdPartAsLong());
if (oldAppointmentDetail == null) {
operationalOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics("No appointment details found for ID: " + appointmentId.getIdPart());
methodOutcome.setOperationOutcome(operationalOutcome);
return methodOutcome;
}
String oldAppointmentVersionId = String.valueOf(oldAppointmentDetail.getLastUpdated().getTime());
String newAppointmentVersionId = appointmentId.getVersionIdPart();
if (newAppointmentVersionId != null && !newAppointmentVersionId.equalsIgnoreCase(oldAppointmentVersionId)) {
throw new ResourceVersionConflictException("The specified version (" + newAppointmentVersionId + ") did not match the current resource version (" + oldAppointmentVersionId + ")");
}
// Determin if it is a cancel or an amend
if (appointmentDetail.getCancellationReason() != null) {
if (appointmentDetail.getCancellationReason().isEmpty()) {
operationalOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics("The cancellation reason can not be blank");
methodOutcome.setOperationOutcome(operationalOutcome);
return methodOutcome;
}
// This is a Cancellation - so copy across fields which can be
// altered
boolean cancelComparisonResult = compareAppointmentsForInvalidPropertyCancel(oldAppointmentDetail, appointmentDetail);
if (cancelComparisonResult) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnclassifiedServerFailureException(400, "Invalid Appointment property has been amended (cancellation)"), SystemCode.BAD_REQUEST, IssueType.FORBIDDEN);
}
oldAppointmentDetail.setCancellationReason(appointmentDetail.getCancellationReason());
String oldStatus = oldAppointmentDetail.getStatus();
appointmentDetail = oldAppointmentDetail;
appointmentDetail.setStatus("cancelled");
if (!"cancelled".equalsIgnoreCase(oldStatus)) {
for (Long slotId : appointmentDetail.getSlotIds()) {
SlotDetail slotDetail = slotSearch.findSlotByID(slotId);
// slotDetail.setAppointmentId(null);
slotDetail.setFreeBusyType("FREE");
slotDetail.setLastUpdated(new Date());
slotStore.saveSlot(slotDetail);
}
}
} else {
if (appointment.getStatus().equals("cancelled")) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnclassifiedServerFailureException(400, "Appointment has been cancelled and cannot be amended"), SystemCode.BAD_REQUEST, IssueType.FORBIDDEN);
}
boolean amendComparisonResult = compareAppointmentsForInvalidPropertyAmend(appointmentDetail, oldAppointmentDetail);
if (amendComparisonResult) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnclassifiedServerFailureException(403, "Invalid Appointment property has been amended"), SystemCode.BAD_REQUEST, IssueType.FORBIDDEN);
}
// This is an Amend
oldAppointmentDetail.setComment(appointmentDetail.getComment());
oldAppointmentDetail.setReasonCode(appointmentDetail.getReasonCode());
oldAppointmentDetail.setDescription(appointmentDetail.getDescription());
oldAppointmentDetail.setReasonDisplay(appointmentDetail.getReasonDisplay());
oldAppointmentDetail.setTypeCode(appointmentDetail.getTypeCode());
oldAppointmentDetail.setTypeDisplay(appointmentDetail.getTypeDisplay());
appointmentDetail = oldAppointmentDetail;
}
List<SlotDetail> slots = new ArrayList<>();
for (Long slotId : appointmentDetail.getSlotIds()) {
SlotDetail slotDetail = slotSearch.findSlotByID(slotId);
if (slotDetail == null) {
throw new UnprocessableEntityException("Slot resource reference is not a valid resource");
}
slots.add(slotDetail);
}
// Update version and
appointmentDetail.setLastUpdated(new Date());
// lastUpdated timestamp
appointmentDetail = appointmentStore.saveAppointment(appointmentDetail, slots);
methodOutcome.setId(new IdDt("Appointment", appointmentDetail.getId()));
methodOutcome.setResource(appointmentDetailToAppointmentResourceConverter(appointmentDetail));
return methodOutcome;
}
use of org.hl7.fhir.r4.model.IdType 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.IdType 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.IdType 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.IdType in project gpconnect-demonstrator by nhsconnect.
the class PractitionerResourceProvider method practitionerDetailsToPractitionerResourceConverter.
private Practitioner practitionerDetailsToPractitionerResourceConverter(PractitionerDetails practitionerDetails) {
Identifier identifier = new Identifier().setSystem(SystemURL.ID_SDS_USER_ID).setValue(practitionerDetails.getUserId());
Practitioner practitioner = new Practitioner().addIdentifier(identifier);
practitionerDetails.getRoleIds().stream().distinct().map(roleId -> new Identifier().setSystem(SystemURL.ID_SDS_ROLE_PROFILE_ID).setValue(roleId)).forEach(practitioner::addIdentifier);
String resourceId = String.valueOf(practitionerDetails.getId());
String versionId = String.valueOf(practitionerDetails.getLastUpdated().getTime());
String resourceType = practitioner.getResourceType().toString();
IdType id = new IdType(resourceType, resourceId, versionId);
practitioner.setId(id);
practitioner.getMeta().setVersionId(versionId);
practitioner.getMeta().setLastUpdated(practitionerDetails.getLastUpdated());
practitioner.getMeta().addProfile(SystemURL.SD_GPC_PRACTITIONER);
HumanName name = new HumanName().setFamily(practitionerDetails.getNameFamily()).addGiven(practitionerDetails.getNameGiven()).addPrefix(practitionerDetails.getNamePrefix()).setUse(NameUse.USUAL);
practitioner.addName(name);
switch(practitionerDetails.getGender().toLowerCase(Locale.UK)) {
case "male":
practitioner.setGender(AdministrativeGender.MALE);
break;
case "female":
practitioner.setGender(AdministrativeGender.FEMALE);
break;
case "other":
practitioner.setGender(AdministrativeGender.OTHER);
break;
default:
practitioner.setGender(AdministrativeGender.UNKNOWN);
break;
}
Coding roleCoding = new Coding(SystemURL.VS_SDS_JOB_ROLE_NAME, practitionerDetails.getRoleCode(), practitionerDetails.getRoleDisplay());
for (int i = 0; i < practitionerDetails.getComCode().size(); i++) {
Coding comCoding = new Coding(SystemURL.VS_HUMAN_LANGUAGE, practitionerDetails.getComCode().get(i), null).setDisplay(practitionerDetails.getComDisplay().get(i));
practitioner.addCommunication().addCoding(comCoding);
}
return practitioner;
}
Aggregations