Search in sources :

Example 1 with SlotDetail

use of uk.gov.hscic.model.appointment.SlotDetail 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;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) AppointmentDetail(uk.gov.hscic.model.appointment.AppointmentDetail) ArrayList(java.util.ArrayList) IdDt(ca.uhn.fhir.model.primitive.IdDt) ResourceVersionConflictException(ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) Date(java.util.Date) UnclassifiedServerFailureException(ca.uhn.fhir.rest.server.exceptions.UnclassifiedServerFailureException) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) SlotDetail(uk.gov.hscic.model.appointment.SlotDetail) Update(ca.uhn.fhir.rest.annotation.Update)

Example 2 with SlotDetail

use of uk.gov.hscic.model.appointment.SlotDetail in project gpconnect-demonstrator by nhsconnect.

the class SlotResourceProvider method getSlotsForScheduleId.

public List<Slot> getSlotsForScheduleId(String scheduleId, Date startDateTime, Date endDateTime) {
    ArrayList<Slot> slots = new ArrayList<>();
    List<SlotDetail> slotDetails = slotSearch.findSlotsForScheduleId(Long.valueOf(scheduleId), startDateTime, endDateTime);
    if (slotDetails != null && !slotDetails.isEmpty()) {
        for (SlotDetail slotDetail : slotDetails) {
            slots.add(slotDetailToSlotResourceConverter(slotDetail));
        }
    }
    return slots;
}
Also used : ArrayList(java.util.ArrayList) Slot(org.hl7.fhir.dstu3.model.Slot) SlotDetail(uk.gov.hscic.model.appointment.SlotDetail)

Example 3 with SlotDetail

use of uk.gov.hscic.model.appointment.SlotDetail in project gpconnect-demonstrator by nhsconnect.

the class SlotResourceProvider method getSlotsForScheduleIdNoOrganizationTypeOrODS.

/**
 * returns any slots not having org type or org id assigned
 *
 * @param scheduleId
 * @param startDateTime
 * @param endDateTime
 * @return
 */
public List<Slot> getSlotsForScheduleIdNoOrganizationTypeOrODS(String scheduleId, Date startDateTime, Date endDateTime) {
    ArrayList<Slot> slots = new ArrayList<>();
    List<SlotDetail> slotDetails = slotSearch.findSlotsForScheduleIdNoOrganizationTypeOrODS(Long.valueOf(scheduleId), startDateTime, endDateTime);
    if (slotDetails != null && !slotDetails.isEmpty()) {
        for (SlotDetail slotDetail : slotDetails) {
            slots.add(slotDetailToSlotResourceConverter(slotDetail));
        }
    }
    return slots;
}
Also used : ArrayList(java.util.ArrayList) Slot(org.hl7.fhir.dstu3.model.Slot) SlotDetail(uk.gov.hscic.model.appointment.SlotDetail)

Example 4 with SlotDetail

use of uk.gov.hscic.model.appointment.SlotDetail in project gpconnect-demonstrator by nhsconnect.

the class SlotResourceProvider method getSlotsForScheduleIdAndOrganizationId.

public List<Slot> getSlotsForScheduleIdAndOrganizationId(String scheduleId, Date startDateTime, Date endDateTime, Long orgId) {
    ArrayList<Slot> slots = new ArrayList<>();
    List<SlotDetail> slotDetails = slotSearch.findSlotsForScheduleIdAndOrganizationId(Long.valueOf(scheduleId), startDateTime, endDateTime, orgId);
    if (slotDetails != null && !slotDetails.isEmpty()) {
        for (SlotDetail slotDetail : slotDetails) {
            slots.add(slotDetailToSlotResourceConverter(slotDetail));
        }
    }
    return slots;
}
Also used : ArrayList(java.util.ArrayList) Slot(org.hl7.fhir.dstu3.model.Slot) SlotDetail(uk.gov.hscic.model.appointment.SlotDetail)

Example 5 with SlotDetail

use of uk.gov.hscic.model.appointment.SlotDetail in project gpconnect-demonstrator by nhsconnect.

the class SlotResourceProvider method getSlotById.

@Read()
public Slot getSlotById(@IdParam IdType slotId) {
    SlotDetail slotDetail = slotSearch.findSlotByID(slotId.getIdPartAsLong());
    if (slotDetail == null) {
        OperationOutcome operationalOutcome = new OperationOutcome();
        operationalOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setDiagnostics("No slot details found for ID: " + slotId.getIdPart());
        throw new InternalErrorException("No slot details found for ID: " + slotId.getIdPart(), operationalOutcome);
    }
    return slotDetailToSlotResourceConverter(slotDetail);
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) SlotDetail(uk.gov.hscic.model.appointment.SlotDetail) Read(ca.uhn.fhir.rest.annotation.Read)

Aggregations

SlotDetail (uk.gov.hscic.model.appointment.SlotDetail)13 ArrayList (java.util.ArrayList)6 Slot (org.hl7.fhir.dstu3.model.Slot)5 AppointmentDetail (uk.gov.hscic.model.appointment.AppointmentDetail)4 IdDt (ca.uhn.fhir.model.primitive.IdDt)3 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)3 ScheduleDetail (uk.gov.hscic.model.appointment.ScheduleDetail)3 Date (java.util.Date)2 AppointmentParticipantComponent (org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent)2 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)2 VC (uk.gov.hscic.common.validators.VC)2 Read (ca.uhn.fhir.rest.annotation.Read)1 Update (ca.uhn.fhir.rest.annotation.Update)1 InternalErrorException (ca.uhn.fhir.rest.server.exceptions.InternalErrorException)1 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)1 ResourceVersionConflictException (ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException)1 UnclassifiedServerFailureException (ca.uhn.fhir.rest.server.exceptions.UnclassifiedServerFailureException)1 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)1 File (java.io.File)1 IOException (java.io.IOException)1