use of uk.gov.hscic.model.appointment.BookingOrgDetail in project gpconnect-demonstrator by nhsconnect.
the class AppointmentResourceProvider method appointmentDetailToAppointmentResourceConverter.
private Appointment appointmentDetailToAppointmentResourceConverter(AppointmentDetail appointmentDetail) {
Appointment appointment = new Appointment();
String appointmentId = String.valueOf(appointmentDetail.getId());
String versionId = String.valueOf(appointmentDetail.getLastUpdated().getTime());
String resourceType = appointment.getResourceType().toString();
IdType id = new IdType(resourceType, appointmentId, versionId);
appointment.setId(id);
appointment.getMeta().setVersionId(versionId);
appointment.getMeta().setLastUpdated(appointmentDetail.getLastUpdated());
appointment.getMeta().addProfile(SystemURL.SD_GPC_APPOINTMENT);
Extension extension = new Extension(SystemURL.SD_EXTENSION_GPC_APPOINTMENT_CANCELLATION_REASON, new IdType(appointmentDetail.getCancellationReason()));
appointment.addExtension(extension);
Identifier identifier = new Identifier();
identifier.setSystem(SystemURL.ID_GPC_APPOINTMENT_IDENTIFIER).setValue(String.valueOf(appointmentDetail.getId()));
appointment.addIdentifier(identifier);
switch(appointmentDetail.getStatus().toLowerCase(Locale.UK)) {
case "pending":
appointment.setStatus(AppointmentStatus.PENDING);
break;
case "booked":
appointment.setStatus(AppointmentStatus.BOOKED);
break;
case "arrived":
appointment.setStatus(AppointmentStatus.ARRIVED);
break;
case "fulfilled":
appointment.setStatus(AppointmentStatus.FULFILLED);
break;
case "cancelled":
appointment.setStatus(AppointmentStatus.CANCELLED);
break;
case "noshow":
appointment.setStatus(AppointmentStatus.NOSHOW);
break;
default:
appointment.setStatus(AppointmentStatus.PENDING);
break;
}
Coding coding = new Coding().setSystem(SystemURL.HL7_VS_C80_PRACTICE_CODES).setCode(String.valueOf(appointmentDetail.getTypeCode())).setDisplay(appointmentDetail.getTypeDisplay());
CodeableConcept codableConcept = new CodeableConcept().addCoding(coding);
codableConcept.setText(appointmentDetail.getTypeDisplay());
appointment.setAppointmentType(codableConcept);
// Look into this
// appointment.getType().setText(appointmentDetail.getTypeText());
String reasonCode = appointmentDetail.getReasonCode();
String reasonDisplay = appointmentDetail.getReasonDisplay();
String reasonSystem = SystemURL.DEFAULTREASONURL;
if (reasonCode != null && reasonDisplay != null && reasonSystem != null) {
Coding codingReason = new Coding().setSystem(reasonSystem).setCode(String.valueOf(reasonCode)).setDisplay(reasonDisplay);
CodeableConcept codableConceptReason = new CodeableConcept().addCoding(codingReason);
codableConceptReason.setText(reasonDisplay);
appointment.addReason(codableConceptReason);
}
appointment.setStart(appointmentDetail.getStartDateTime());
appointment.setEnd(appointmentDetail.getEndDateTime());
List<Reference> slotResources = new ArrayList<>();
for (Long slotId : appointmentDetail.getSlotIds()) {
slotResources.add(new Reference("Slot/" + slotId));
}
appointment.setSlot(slotResources);
if (appointmentDetail.getPriority() != null) {
appointment.setPriority(appointmentDetail.getPriority());
}
appointment.setComment(appointmentDetail.getComment());
appointment.setDescription(appointmentDetail.getDescription());
appointment.addParticipant().setActor(new Reference("Patient/" + appointmentDetail.getPatientId())).setStatus(ParticipationStatus.ACCEPTED);
appointment.addParticipant().setActor(new Reference("Location/" + appointmentDetail.getLocationId())).setStatus(ParticipationStatus.ACCEPTED);
if (null != appointmentDetail.getPractitionerId()) {
appointment.addParticipant().setActor(new Reference("Practitioner/" + appointmentDetail.getPractitionerId())).setStatus(ParticipationStatus.ACCEPTED);
}
if (null != appointmentDetail.getCreated()) {
// DateTimeDt created = new
// DateTimeDt(appointmentDetail.getCreated());
// Extension createdExt = new
// Extension(SystemURL.SD_CC_APPOINTMENT_CREATED, created);
appointment.setCreated(appointmentDetail.getCreated());
}
if (null != appointmentDetail.getBookingOrganization()) {
String reference = "#1";
Reference orgRef = new Reference(reference);
Extension bookingOrgExt = new Extension(SystemURL.SD_CC_APPOINTMENT_BOOKINGORG, orgRef);
appointment.addExtension(bookingOrgExt);
BookingOrgDetail bookingOrgDetail = appointmentDetail.getBookingOrganization();
Organization bookingOrg = new Organization();
bookingOrg.setId(reference);
bookingOrg.getNameElement().setValue(bookingOrgDetail.getName());
bookingOrg.getTelecomFirstRep().setValue(bookingOrgDetail.getTelephone()).setUse(ContactPointUse.TEMP).setSystem(ContactPointSystem.PHONE);
bookingOrg.getMeta().addProfile(SystemURL.SD_GPC_ORGANIZATION);
if (null != bookingOrgDetail.getOrgCode()) {
bookingOrg.getIdentifierFirstRep().setSystem(SystemURL.ID_ODS_ORGANIZATION_CODE).setValue(bookingOrgDetail.getOrgCode());
}
appointment.getContained().add(bookingOrg);
}
return appointment;
}
use of uk.gov.hscic.model.appointment.BookingOrgDetail in project gpconnect-demonstrator by nhsconnect.
the class AppointmentResourceProvider method appointmentResourceConverterToAppointmentDetail.
private AppointmentDetail appointmentResourceConverterToAppointmentDetail(Appointment appointment) {
appointmentValidation.validateAppointmentExtensions(appointment.getExtension());
if (appointmentValidation.appointmentDescriptionTooLong(appointment)) {
throw new UnprocessableEntityException("Appointment description cannot be greater then 600 characters");
}
AppointmentDetail appointmentDetail = new AppointmentDetail();
Long id = appointment.getIdElement().getIdPartAsLong();
appointmentDetail.setId(id);
appointmentDetail.setLastUpdated(getLastUpdated(appointment.getMeta().getLastUpdated()));
List<Extension> cnlExtension = appointment.getExtensionsByUrl(SystemURL.SD_EXTENSION_GPC_APPOINTMENT_CANCELLATION_REASON);
if (cnlExtension != null && !cnlExtension.isEmpty()) {
IBaseDatatype value = cnlExtension.get(0).getValue();
if (null == value) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("Cancellation reason missing."), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
appointmentDetail.setCancellationReason(value.toString());
}
appointmentDetail.setStatus(appointment.getStatus().toString().toLowerCase(Locale.UK));
appointmentDetail.setTypeDisplay(appointment.getAppointmentType().getTextElement().toString());
appointmentDetail.setMinutesDuration(appointment.getMinutesDuration());
appointmentDetail.setPriority(appointment.getPriority());
appointmentDetail.setTypeText(appointment.getServiceType().toString());
Coding codingFirstRep = appointment.getReasonFirstRep().getCodingFirstRep();
if (!codingFirstRep.isEmpty()) {
String reasonSystem = codingFirstRep.getSystem();
if (reasonSystem == null) {
String message = "Problem with reason property of the appointment. If the reason is provided then the system property must be set.";
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(message), SystemCode.INVALID_RESOURCE, IssueType.INCOMPLETE);
} else {
appointmentDetail.setReasonURL(reasonSystem);
}
String reasonCode = codingFirstRep.getCode();
if (reasonCode == null) {
String message = "Problem with reason property of the appointment. If the reason is provided then the code property must be set.";
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(message), SystemCode.INVALID_RESOURCE, IssueType.INCOMPLETE);
} else {
appointmentDetail.setReasonCode(reasonCode);
}
String reasonDisplay = codingFirstRep.getDisplay();
if (reasonDisplay == null) {
String message = "Problem with reason property of the appointment. If the reason is provided then the display property must be set.";
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(message), SystemCode.INVALID_RESOURCE, IssueType.INCOMPLETE);
} else {
appointmentDetail.setReasonDisplay(reasonDisplay);
}
}
appointmentDetail.setStartDateTime(appointment.getStart());
appointmentDetail.setEndDateTime(appointment.getEnd());
List<Long> slotIds = new ArrayList<>();
for (Reference slotReference : appointment.getSlot()) {
try {
String here = slotReference.getReference().substring(5).toString();
Long slotId = new Long(here);
slotIds.add(slotId);
} catch (NumberFormatException ex) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(String.format("The slot reference value data type for %s is not valid.", slotReference.getReference())), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
}
}
appointmentDetail.setSlotIds(slotIds);
appointmentDetail.setComment(appointment.getComment());
appointmentDetail.setDescription(appointment.getDescription());
for (AppointmentParticipantComponent participant : appointment.getParticipant()) {
if (participant.getActor() != null) {
String participantReference = participant.getActor().getReference().toString();
String actorIdString = participantReference.substring(participantReference.lastIndexOf("/") + 1);
Long actorId;
if (actorIdString.equals("null")) {
actorId = null;
} else {
actorId = Long.valueOf(actorIdString);
}
if (participantReference.contains("Patient/")) {
appointmentDetail.setPatientId(actorId);
} else if (participantReference.contains("Practitioner/")) {
appointmentDetail.setPractitionerId(actorId);
} else if (participantReference.contains("Location/")) {
appointmentDetail.setLocationId(actorId);
}
} else {
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(String.format("Participant Actor cannot be null")), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
}
}
if (appointment.getCreated() != null) {
Date created = appointment.getCreated();
appointmentDetail.setCreated(created);
}
List<Resource> contained = appointment.getContained();
if (contained != null && !contained.isEmpty()) {
Resource org = contained.get(0);
Organization bookingOrgRes = (Organization) org;
BookingOrgDetail bookingOrgDetail = new BookingOrgDetail();
appointmentValidation.validateBookingOrganizationValuesArePresent(bookingOrgRes);
bookingOrgDetail.setName(bookingOrgRes.getName());
bookingOrgDetail.setTelephone(bookingOrgRes.getTelecomFirstRep().getValue());
if (!bookingOrgRes.getIdentifier().isEmpty()) {
bookingOrgDetail.setOrgCode(bookingOrgRes.getIdentifierFirstRep().getValue());
}
bookingOrgDetail.setAppointmentDetail(appointmentDetail);
appointmentDetail.setBookingOrganization(bookingOrgDetail);
}
List<Extension> bktExtension = appointment.getExtensionsByUrl(SystemURL.SD_CC_APPOINTMENT_BOOKINGORG);
if (bktExtension != null && !bktExtension.isEmpty()) {
IBaseDatatype bookingOrg = bktExtension.get(0).getValue();
if (null != bookingOrg && bookingOrg.getClass().getSimpleName().equals("Reference")) {
for (Resource resource : appointment.getContained()) {
if (resource.getResourceType().toString().equals("Organization")) {
// Organization bookingOrgRes = (Organization) resource;
// Reference bookingOrgRef = (Reference) bookingOrg;
// if
// (bookingOrgRes.getId().equals(bookingOrgRef.getReference()))
// {
// BookingOrgDetail bookingOrgDetail = new
// BookingOrgDetail();
// bookingOrgDetail.setName(bookingOrgRes.getName());
// bookingOrgDetail.setTelephone(bookingOrgRes.getTelecomFirstRep().getValue());
// if (!bookingOrgRes.getIdentifier().isEmpty()) {
// bookingOrgDetail.setOrgCode(bookingOrgRes.getIdentifierFirstRep().getValue());
// }
// bookingOrgDetail.setAppointmentDetail(appointmentDetail);
// appointmentDetail.setBookingOrganization(bookingOrgDetail);
// }
}
}
}
}
return appointmentDetail;
}
use of uk.gov.hscic.model.appointment.BookingOrgDetail in project gpconnect-demonstrator by nhsconnect.
the class BookingOrgEntityToBookingOrgDetailTransformer method transform.
@Override
public BookingOrgDetail transform(BookingOrgEntity item) {
if (null == item) {
return null;
}
BookingOrgDetail bookingOrgDetail = new BookingOrgDetail();
bookingOrgDetail.setId(item.getId());
bookingOrgDetail.setOrgCode(item.getOrgCode());
bookingOrgDetail.setName(item.getName());
bookingOrgDetail.setTelephone(item.getTelephone());
bookingOrgDetail.setLastUpdated(item.getLastUpdated());
return bookingOrgDetail;
}
Aggregations