Esempio n. 1
0
  private String getServicesIDs(PreAssessmentWorklistSearchCriteriaVo searchCriteria) {
    if (searchCriteria == null) return null;

    if (searchCriteria.getService() == null && searchCriteria.getServices() == null) return null;

    StringBuffer ids = new StringBuffer();

    if (searchCriteria.getService() != null) {
      ids.append(searchCriteria.getService().getID_Service());
    } else if (searchCriteria.getServices() != null) {
      for (ServiceShortVo service : searchCriteria.getServices()) {
        if (service == null) continue;

        if (ids.length() > 0) ids.append(",");

        ids.append(service.getID_Service());
      }
    }

    return ids.toString();
  }
Esempio n. 2
0
  public PatientElectiveListForPreAssessmentWorklistVoCollection listPreAssessments(
      PreAssessmentWorklistSearchCriteriaVo searchCriteria) {
    DomainFactory factory = getDomainFactory();
    StringBuffer hqlConditions = new StringBuffer();
    StringBuffer hqlJoins = new StringBuffer();

    StringBuffer hql =
        new StringBuffer(
            " select patElective from PatientElectiveList as patElective left join patElective.electiveListStatus as elStatus  ");

    ArrayList<String> markers = new ArrayList<String>();
    ArrayList<Object> values = new ArrayList<Object>();

    String andStr = "";

    hqlConditions.append(andStr);
    hqlConditions.append(
        " patElective.preAssessmentRequired = 1 and elStatus.electiveListStatus.id <> :Status and ( patElective.requiresVetting = 0 or patElective.requiresVetting is null ) "); // wdev-21152
    markers.add("Status");
    values.add(WaitingListStatus.REMOVED.getID());

    andStr = " and ";

    if (searchCriteria.getServiceIsNotNull()
        || (searchCriteria.getServices() != null && searchCriteria.getServices().size() > 0)) {
      hqlConditions.append(andStr);
      hqlJoins.append(" left join patElective.electiveList as electiveListConfig  ");
      hqlConditions.append(
          " (electiveListConfig.service.id in (" + getServicesIDs(searchCriteria) + "))");
      andStr = " and ";
    }

    if (searchCriteria.getProcedureIsNotNull()) {
      hqlConditions.append(andStr);
      hqlConditions.append(
          " (patElective.primaryProcedure.id = :procedureID OR patElective.secondaryProcedure.id  = :procedureID) ");
      markers.add("procedureID");
      values.add(searchCriteria.getProcedure().getID_Procedure());
      andStr = " and ";
    }

    if (searchCriteria.getAnaestheticTypeIsNotNull()) {
      hqlConditions.append(andStr);
      hqlConditions.append(" (patElective.anaestheticType.id = :anaestheticTypeID) ");
      markers.add("anaestheticTypeID");
      values.add(searchCriteria.getAnaestheticType().getID());
      andStr = " and ";
    }

    if (searchCriteria.getUrgencyIsNotNull()) {
      hqlConditions.append(andStr);
      hqlJoins.append(" left join patElective.priority as priority ");
      hqlConditions.append(" (priority.id = :Urgency) ");
      markers.add("Urgency");
      values.add(searchCriteria.getUrgency().getID());
      andStr = " and ";
    }
    // WDEV-22781
    if (searchCriteria.getPatientIdentifierIsNotNull()) {
      hqlConditions.append(andStr);
      hqlJoins.append(
          " left join patElective.patient as patient left join patient.identifiers as ids ");
      hqlConditions.append(" (ids.value = :idValue AND ids.type = :idType) ");
      markers.add("idValue");
      markers.add("idType");
      values.add(searchCriteria.getPatientIdentifier());
      values.add(getDomLookup(searchCriteria.getPatIdType()));
      andStr = " and ";
    }
    // WDEV-22781 ends here

    if (searchCriteria.getBreachDateFromIsNotNull()) {
      hqlConditions.append(andStr);
      hqlJoins.append(
          " left join patElective.referral as catsRef left join catsRef.referralDetails as refDetails ");
      hqlConditions.append(" (refDetails.end18WW >= :fromdate) ");
      markers.add("fromdate");
      values.add(
          new DateTime(searchCriteria.getBreachDateFrom(), new Time("00:00:00")).getJavaDate());
      andStr = " and ";
    }

    if (searchCriteria.getBreachDateToIsNotNull()) {
      hqlConditions.append(andStr);
      hqlJoins.append(
          " left join patElective.referral as catsRef left join catsRef.referralDetails as refDetails ");
      hqlConditions.append(" (refDetails.end18WW <= :todate) ");
      markers.add("todate");
      values.add(
          new DateTime(searchCriteria.getBreachDateTo(), new Time("23:59:00"))
              .getJavaDate()); // WDEV-21037
      andStr = " and ";
    }

    if (searchCriteria.getTheatreTypeIsNotNull()) {
      hqlConditions.append(andStr);
      hqlJoins.append(" left join patElective.preAssessmentOutcome as preAssessmentOutcome ");
      hqlConditions.append(
          "( ( preAssessmentOutcome is not null AND preAssessmentOutcome.theatreType.id = :theatreType) OR (preAssessmentOutcome is null AND patElective.requiredTheatreType.id = :theatreType)) ");
      markers.add("theatreType");
      values.add(searchCriteria.getTheatreType().getID());
      andStr = " and ";
    }

    StringBuffer hqlConditionsOR = new StringBuffer();
    String orStr = "";
    if (searchCriteria
        .getPreAssessmentRequired()) // those that does not have preAssessmentOutcome saved and no
                                     // PreAssessment Booked
    {
      hqlConditionsOR.append(orStr);
      hqlJoins.append(" left join patElective.preAssessmentOutcome as preAssessmentOutcome ");
      hqlConditionsOR.append(
          " (patElective.preAssessmentOutcome is null AND patElective.preAssessmentAppointment is null) "); // WDEV-21037
      orStr = " OR ";
    }

    if (searchCriteria.getNotFitForSurgery()) {
      hqlConditionsOR.append(orStr);
      hqlJoins.append(" left join patElective.preAssessmentOutcome as preAssessmentOutcome ");
      hqlConditionsOR.append(" (preAssessmentOutcome.fitToProceed = 0) ");
      orStr = " OR ";
    }

    if (searchCriteria.getFitForSurgery()) {
      hqlConditionsOR.append(orStr);
      hqlJoins.append(" left join patElective.preAssessmentOutcome as preAssessmentOutcome ");
      hqlConditionsOR.append(" (preAssessmentOutcome.fitToProceed = 1) ");
      orStr = " OR ";
    }

    if (searchCriteria.getPreAssessmentOutcomePending()) {
      if (searchCriteria.getWaitingForIsNotNull() && searchCriteria.getWaitingFor().size() > 0) {
        hqlConditionsOR.append(orStr);
        hqlJoins.append(
            " left join patElective.preAssessmentOutcome as preAssessmentOutcome left join preAssessmentOutcome.waitingForDetails as waitingForDet left join waitingForDet.informationToBeReceived as infoReceived");
        hqlConditionsOR.append(
            " (preAssessmentOutcome is not null AND preAssessmentOutcome.fitToProceed is null AND (infoReceived.id in ("
                + getWaitingForIDs(searchCriteria.getWaitingFor())
                + ") AND (waitingForDet.received is null OR waitingForDet.received = 0))) ");
        orStr = " OR ";
      } else {
        hqlConditionsOR.append(orStr);
        hqlJoins.append(" left join patElective.preAssessmentOutcome as preAssessmentOutcome  ");
        hqlConditionsOR.append(
            " (preAssessmentOutcome.detailsOutstanding=1 AND preAssessmentOutcome.fitToProceed is null)");
        orStr = " OR ";
      }
    }

    // WDEV-21037
    if (searchCriteria.getPastAppointment()) {
      hqlConditionsOR.append(orStr);
      hqlJoins.append(" left join patElective.preAssessmentAppointment as preAssessmentAppt ");
      hqlConditionsOR.append(
          " (patElective.preAssessmentOutcome is null AND preAssessmentAppt.appointmentDate < :ApptTodayDate ) ");
      markers.add("ApptTodayDate");
      values.add(new DateTime().getJavaDate());
      orStr = " OR ";
    }

    if (searchCriteria.getFutureAppointment()) {
      hqlConditionsOR.append(orStr);
      hqlJoins.append(" left join patElective.preAssessmentAppointment as preAssessmentAppt ");
      hqlConditionsOR.append(
          " (patElective.preAssessmentOutcome is null AND preAssessmentAppt.appointmentDate > :ApptTodayDate ) ");
      markers.add("ApptTodayDate");
      values.add(new DateTime().getJavaDate());
      orStr = " OR ";
    }

    if (hqlConditionsOR.length() > 0) {
      hqlConditions.append(andStr);
      hqlConditions.append(" ( " + hqlConditionsOR + " ) ");
    }

    // WDEV-21037

    StringBuffer hqlConditionsElectiveListTypeOR = new StringBuffer();
    orStr = "";
    if (searchCriteria.getWaitingList()) {
      hqlConditionsElectiveListTypeOR.append(orStr);
      hqlConditionsElectiveListTypeOR.append(
          " (patElective.electiveAdmissionType.id = :WaitingListType OR patElective.electiveAdmissionType.id = :BookedListType) ");
      markers.add("WaitingListType");
      values.add(ElectiveAdmissionType.ELECTIVE_TYPE11.getID());
      markers.add("BookedListType");
      values.add(ElectiveAdmissionType.BOOKED_TYPE12.getID());
      orStr = " OR ";
    }

    if (searchCriteria.getSurveillancePlannedList()) {
      hqlConditionsElectiveListTypeOR.append(orStr);
      hqlConditionsElectiveListTypeOR.append(
          " (patElective.electiveAdmissionType.id = :PlannedList   ");
      markers.add("PlannedList");
      values.add(ElectiveAdmissionType.PLANNED_TYPE13.getID());
      orStr = " OR ";

      if (searchCriteria.getPlannedFromIsNotNull()) {
        hqlConditionsElectiveListTypeOR.append(andStr);

        hqlConditionsElectiveListTypeOR.append(
            " (patElective.plannedDate >= :fromdate) "); // wdev-21440
        markers.add("fromdate");
        values.add(
            new DateTime(searchCriteria.getPlannedFrom(), new Time("00:00:00")).getJavaDate());
        andStr = " and ";
      }

      if (searchCriteria.getPlannedToIsNotNull()) {
        hqlConditionsElectiveListTypeOR.append(andStr);

        hqlConditionsElectiveListTypeOR.append(
            " (patElective.plannedDate <= :todate) "); // wdev-21440
        markers.add("todate");
        values.add(new DateTime(searchCriteria.getPlannedTo(), new Time("23:59:59")).getJavaDate());
        andStr = " and ";
      }

      hqlConditionsElectiveListTypeOR.append(" )");
    }

    if (hqlConditionsElectiveListTypeOR.length() > 0) {
      hqlConditions.append(andStr);
      hqlConditions.append(" ( " + hqlConditionsElectiveListTypeOR + " ) ");
    }

    /*if (searchCriteria.getPlannedFromIsNotNull())
    {
    	hqlConditions.append(andStr);

    	//hqlJoins.append(" left join patElective.tCIDetails as tciDet ");
    	//hqlConditions.append(" (tciDet.plannedTCIDate >= :fromdate) ");
    	hqlConditions.append(" (patElective.plannedDate >= :fromdate) ");		//wdev-21440
    	markers.add("fromdate");
    	values.add(new DateTime(searchCriteria.getPlannedFrom(), new Time("00:00:00")).getJavaDate());
    	andStr = " and ";

    }

    if (searchCriteria.getPlannedToIsNotNull())
    {
    	hqlConditions.append(andStr);
    	//hqlJoins.append(" left join patElective.tCIDetails as tciDet ");
    	//hqlConditions.append(" (tciDet.plannedTCIDate <= :todate) ");
    	hqlConditions.append(" (patElective.plannedDate <= :todate) ");			//wdev-21440
    	markers.add("todate");
    	values.add(new DateTime(searchCriteria.getPlannedTo(), new Time("23:59:59")).getJavaDate());
    	andStr = " and ";

    }*/

    if (searchCriteria.getAddedToday()) {
      hqlConditions.append(andStr);
      hqlConditions.append(
          " (patElective.dateOnList >= :Today1 AND patElective.dateOnList <= :Today2) ");
      markers.add("Today1");
      values.add(new DateTime(new Date(), new Time("00:00:00")).getJavaDate());
      markers.add("Today2");
      values.add(new DateTime(new Date(), new Time("23:59:00")).getJavaDate());
      andStr = " and ";
    }
    // WDEV-23462
    if (searchCriteria.getIncludeEndoscopy()) {
      hqlConditions.append(andStr);
      hqlConditions.append(" patElective.admissionType.id = :AdmissionType ");
      markers.add("AdmissionType");
      values.add(WaitingCardAdmissionType.ENDOSCOPY.getID());
      andStr = " and ";
    }

    if (hqlConditions.length() > 0) {
      hqlConditions.insert(0, " where (");
      hqlConditions.append(" ) ");
    }

    List<?> list =
        factory.find(
            (hql.toString() + hqlJoins.toString() + hqlConditions.toString() + "  ").toString(),
            markers,
            values,
            2000); // order by refDetails.end18WW asc

    if (list == null || list.size() == 0) return null;

    return PatientElectiveListForPreAssessmentWorklistVoAssembler
        .createPatientElectiveListForPreAssessmentWorklistVoCollectionFromPatientElectiveList(list);
  }