public EmergencyAttendanceForPendingArrivalsVoCollection listPendingArrivals(LocationRefVo location, String surnameSearchText, String forenameSearchText, ReferredBy sourceOfReferral) { if (location == null || location.getID_Location() == null) { throw new CodingRuntimeException("Cannot get EmergencyAttendanceForPendingArrivalsVoCollection on null Id for Location "); } String hql = "select emergAtt from EmergencyAttendance as emergAtt left join emergAtt.emergencyEpisode as emergEpisode left join emergAtt.patient as patient where emergAtt.dischargeDateTime is null and emergAtt.expectedArrivalDateTime is not null "; StringBuilder hqlConditions = new StringBuilder(" "); ArrayList<String> markers = new ArrayList<String>(); ArrayList<Object> values = new ArrayList<Object>(); String andStr = "and"; hqlConditions.append(andStr); hqlConditions.append(" emergAtt.registrationLocation.id = :locID "); markers.add("locID"); values.add(location.getID_Location()); andStr = " and "; hqlConditions.append(andStr); hqlConditions.append(" emergAtt.isExpectedArrival = :isExpectedArrival "); markers.add("isExpectedArrival"); values.add(Boolean.TRUE); andStr = " and "; if (surnameSearchText != null) { hqlConditions.append(andStr); hqlConditions.append(" patient.name.upperSurname like :surname "); markers.add("surname"); values.add(surnameSearchText.toUpperCase() + "%"); andStr = " and "; } if (forenameSearchText != null) { hqlConditions.append(andStr); hqlConditions.append(" patient.name.upperForename like :forename "); markers.add("forename"); values.add(forenameSearchText.toUpperCase() + "%"); andStr = " and "; } if (sourceOfReferral != null) { hqlConditions.append(andStr); hqlConditions.append(" emergEpisode.sourceOfReferral.id = :source "); markers.add("source"); values.add(sourceOfReferral.getID()); andStr = " and "; } hqlConditions.append(" ) order by emergAtt.arrivalDateTime asc "); DomainFactory factory = getDomainFactory(); List<?> list = factory.find((hql + hqlConditions.toString()).toString(), markers, values); EmergencyAttendanceForPendingArrivalsVoCollection collection = EmergencyAttendanceForPendingArrivalsVoAssembler.createEmergencyAttendanceForPendingArrivalsVoCollectionFromEmergencyAttendance(list); return collection; }
public EmergencyAttendanceForPendingArrivalsVo save(TrackingForQuickRegistrationVo trackingToSave, EmergencyAttendanceForPendingArrivalsVo emergencyAttendanceToSave) throws StaleObjectException { if (trackingToSave == null && emergencyAttendanceToSave == null) throw new CodingRuntimeException("Cannot save null AllocatedMedic or TrackingForAllocatedMedicVo "); if (!trackingToSave.isValidated()) throw new DomainRuntimeException("TrackingForQuickRegistrationVo Not Validated."); if (!emergencyAttendanceToSave.isValidated()) throw new DomainRuntimeException("EmergencyAttendanceForPendingArrivalsVo Not Validated."); DomainFactory factory = getDomainFactory(); Tracking domainTracking = TrackingForQuickRegistrationVoAssembler.extractTracking(factory, trackingToSave); factory.save(domainTracking); EmergencyAttendance domainEmergencyAtt = EmergencyAttendanceForPendingArrivalsVoAssembler.extractEmergencyAttendance(factory, emergencyAttendanceToSave); factory.save(domainEmergencyAtt); return EmergencyAttendanceForPendingArrivalsVoAssembler.create(domainEmergencyAtt); }