public MyOrderOutpatAttendVo getOutPatientAttendance(PatientRefVo patient, PASEventRefVo pasEvent) { if (patient == null) throw new CodingRuntimeException("patient parameter is null method getOutPatientAttendance"); DomainFactory factory = getDomainFactory(); // WDEV-16607 MyOrderOutpatAttendVo todayAppointment = findTodayAppointment(patient, pasEvent); if (todayAppointment != null) return todayAppointment; String hql = ""; List outps = null; if(pasEvent != null) { hql = "from OutpatientAttendance as outp " + " where outp.pasEvent.patient.id = :idPatient " + " and outp.pasEvent.id = :idPasEvent " + " and outp.clinic is not null " + " and outp.appointmentStatus.id != :cancelledStatus"; outps = factory.find(hql, new String[]{"idPatient", "idPasEvent", "cancelledStatus"}, new Object[]{patient.getID_Patient(), pasEvent.getID_PASEvent(), new Integer(Status_Reason.CANCELLED.getId())}); } else { hql = "from OutpatientAttendance as outp " + " where outp.pasEvent.patient.id = :idPatient " + " and outp.clinic is not null " + " and outp.appointmentStatus.id != :cancelledStatus" + " and outp.appointmentDateTime >= :todayMinus7Days order by outp.appointmentDateTime"; outps = factory.find(hql, new String[]{"idPatient", "todayMinus7Days", "cancelledStatus"}, new Object[]{patient.getID_Patient(), new Date().addDay(-7).getDate(), new Integer(Status_Reason.CANCELLED.getId())}); } if(outps != null && outps.size() > 0) return MyOrderOutpatAttendVoAssembler.create((OutpatientAttendance) outps.get(0)); return null; }
private MyOrderOutpatAttendVo findTodayAppointment(PatientRefVo patient, PASEventRefVo pasEvent) { if (patient == null) return null; ArrayList<String> paramNames = new ArrayList<String>(); ArrayList<Object> paramValues = new ArrayList<Object>(); StringBuilder todayQuery = new StringBuilder("FROM OutpatientAttendance AS outp "); todayQuery.append("WHERE outp.pasEvent.patient.id = :PATIENT_ID "); paramNames.add("PATIENT_ID"); paramValues.add(patient.getID_Patient()); if (pasEvent != null) { todayQuery.append("AND outp.pasEvent.id = :PAS_EVENT_ID "); paramNames.add("PAS_EVENT_ID"); paramValues.add(pasEvent.getID_PASEvent()); } todayQuery.append("AND outp.clinic is not null AND outp.appointmentStatus.id != :CANCELLED_STATUS and outp.appointmentDateTime BETWEEN :TODAY AND :TODAY_MIDNIGHT"); paramNames.add("CANCELLED_STATUS"); paramValues.add(Status_Reason.CANCELLED.getID()); paramNames.add("TODAY"); paramValues.add(new DateTime(new Date(), new Time(0, 0, 0)).getJavaDate()); paramNames.add("TODAY_MIDNIGHT"); paramValues.add(new DateTime(new Date(), new Time(23, 59, 59)).getJavaDate()); MyOrderOutpatAttendVoCollection outpatientAttendances = MyOrderOutpatAttendVoAssembler.createMyOrderOutpatAttendVoCollectionFromOutpatientAttendance(getDomainFactory().find(todayQuery.toString(), paramNames, paramValues)); if (outpatientAttendances != null && outpatientAttendances.size() > 0) return outpatientAttendances.get(0); return null; }