/** * Function used to retrieve the Tracking record based on CareContext provided (must be equal to Tracking.Attendance.CareContext) */ public TrackingAttendanceOutcomeVo getTrackingAttendanceOutcomeVo(CareContextRefVo careContext) { // Check care context parameter if (careContext == null || careContext.getID_CareContext() == null) return null; StringBuilder query = new StringBuilder(); query.append("SELECT track FROM Tracking AS track "); query.append(" LEFT JOIN FETCH track.attendance AS attend "); query.append(" LEFT JOIN FETCH attend.careContext as context "); query.append(" LEFT JOIN FETCH track.currentStatus "); query.append(" LEFT JOIN FETCH attend.emergencyEpisode "); query.append(" LEFT JOIN FETCH attend.patient "); query.append(" WHERE context.id = :CONTEXT_ID "); return TrackingAttendanceOutcomeVoAssembler.create((Tracking) getDomainFactory().findFirst(query.toString(), "CONTEXT_ID", careContext.getID_CareContext())); }
public PendingEmergencyAdmissionAdmitVo autoDischargeFromEmergencyTracking(PendingEmergencyAdmissionRefVo pendingEmergencyAdmissionRef, DateTime conclusionDateTime, HcpLiteVo consultant) throws StaleObjectException { if (pendingEmergencyAdmissionRef == null || pendingEmergencyAdmissionRef.getID_PendingEmergencyAdmission() == null) throw new CodingRuntimeException("Invalid parameter: PendingEmergencyAdmission record cannot be null."); DomainFactory factory = getDomainFactory(); // Get Tracking record StringBuilder queryTracking = new StringBuilder("SELECT tracking "); queryTracking.append(" FROM Tracking AS tracking "); queryTracking.append(" LEFT JOIN tracking.associatedPendingEmergencyAdmission AS emergency "); queryTracking.append(" WHERE emergency.id = :ER_ADMISSION_ID "); Tracking doTracking = (Tracking) factory.findFirst(queryTracking.toString(), "ER_ADMISSION_ID", pendingEmergencyAdmissionRef.getID_PendingEmergencyAdmission()); TrackingAttendanceOutcomeVo tracking = TrackingAttendanceOutcomeVoAssembler.create(doTracking); // Set the Conclusion and Outcome details tracking.getAttendance().setConclusionDateTime(conclusionDateTime); tracking.getAttendance().setOutcome(AttendanceOutcome.ADMISSIONS); tracking.getAttendance().setDischargeDateTime(conclusionDateTime); AuthoringInformationVo discharghingAuthoringInformation = new AuthoringInformationVo(); discharghingAuthoringInformation.setAuthoringDateTime(conclusionDateTime); discharghingAuthoringInformation.setAuthoringHcp(consultant); tracking.getAttendance().setDischargingHCP(discharghingAuthoringInformation); // Set tracking status // Create new current status (Decision To Admit) for tracking TrackingAttendanceStatusVo newStatus = new TrackingAttendanceStatusVo(); newStatus.setPatient(new PatientRefVo(doTracking.getPatient().getId(), doTracking.getPatient().getVersion())); newStatus.setEpisode(new EpisodeOfCareRefVo(doTracking.getEpisode().getEpisodeOfCare().getId(), doTracking.getEpisode().getEpisodeOfCare().getVersion())); newStatus.setAttendance(new CareContextRefVo(doTracking.getAttendance().getCareContext().getId(), doTracking.getAttendance().getCareContext().getVersion())); if (doTracking.getCurrentArea() != null) newStatus.setTrackingArea(new TrackingAreaRefVo(doTracking.getCurrentArea().getId(), doTracking.getCurrentArea().getVersion())); newStatus.setStatusDatetime(new DateTime()); newStatus.setCreatedBy((MemberOfStaffRefVo) getMosUser()); newStatus.setStatus(TrackingStatus.DISCHARGED); newStatus.setPrevStatus((tracking != null && tracking.getCurrentStatus() != null) ? tracking.getCurrentStatus().getStatus() : null); newStatus.setPrevTrackingArea((tracking != null && tracking.getCurrentStatus() != null) ? tracking.getCurrentStatus().getTrackingArea() : null); tracking.setCurrentStatus(newStatus); // Set the status of the associated PendingEmergencyAddmision if (tracking.getAssociatedPendingEmergencyAdmission() != null && EmergencyAdmissionStatus.DTA.equals(tracking.getAssociatedPendingEmergencyAdmission().getAdmissionStatus())) { tracking.getAssociatedPendingEmergencyAdmission().setAdmissionStatus(EmergencyAdmissionStatus.DISCHARGED); tracking.getAssociatedPendingEmergencyAdmission().setConclusionDate(conclusionDateTime); } tracking.setRequiringDischargeDocumentationReview(true); // Set Discharging data tracking.setIsDischarged(Boolean.TRUE); tracking.setCurrentArea(null); tracking.getAttendance().getCareContext().setEndDateTime(conclusionDateTime); // Save Tracking record doTracking = TrackingAttendanceOutcomeVoAssembler.extractTracking(getDomainFactory(), tracking); factory.save(doTracking); // Return updated PendingEmergencyAdmission return PendingEmergencyAdmissionAdmitVoAssembler.create((PendingEmergencyAdmission) factory.getDomainObject(PendingEmergencyAdmission.class, pendingEmergencyAdmissionRef.getID_PendingEmergencyAdmission())); }