public ims.clinicaladmin.vo.TreatmentInterventionLiteVoCollection
      listTreatmentsInterventionsFromHotlist(
          String listOfTreatmentsInterventionsAllreadyAdded, TreatmentInterventionType type) {
    DomainFactory factory = getDomainFactory();
    StringBuilder query =
        new StringBuilder(
            "select ti from TreatmentInterventionHotlist as th left join th.hotListItem as titem left join titem.treatmentIntervention as ti left join th.specialty as sp left join ti.treatmentInterventionType as tType where sp.id = :Emergency and ti.isActive = 1 ");

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

    markers.add("Emergency");
    values.add(Specialty.EMERGENCY.getID());

    if (listOfTreatmentsInterventionsAllreadyAdded != null
        && listOfTreatmentsInterventionsAllreadyAdded.length() > 0) {
      query.append(" and ti.id not in (" + listOfTreatmentsInterventionsAllreadyAdded + ") ");
    }

    if (type != null) {
      query.append(" and tType.id = :TType ");
      markers.add("TType");
      values.add(type.getID());
    }

    query.append(" order by UPPER(tType.text) asc, UPPER(ti.treatmentInterventionName) asc");

    List<?> tiList = factory.find(query.toString(), markers, values);

    return TreatmentInterventionLiteVoAssembler
        .createTreatmentInterventionLiteVoCollectionFromTreatmentIntervention(tiList);
  }
  public ims.clinicaladmin.vo.TreatmentInterventionLiteVoCollection listTreatmentsInterventions(
      String criteria, String listOfTreatmentsInterventionsAllreadyAdded) {
    if (criteria == null || criteria.length() == 0)
      throw new CodingRuntimeException("Cannot search on null TreatmentIntervention name.");

    DomainFactory factory = getDomainFactory();
    StringBuilder query =
        new StringBuilder(
            "select ti from TreatmentIntervention as ti left join ti.keywords as kw where ti.isActive = 1 and ti.id not in (select tisec.id from TreatmentInterventionHotlist as th left join th.hotListItem as titem left join titem.treatmentIntervention as tisec left join th.specialty as sp where sp.id = :Emergency) and (ti.treatmentInterventionName like :TreatmentName or kw.keyword like :TreatmentName) ");

    if (listOfTreatmentsInterventionsAllreadyAdded != null
        && listOfTreatmentsInterventionsAllreadyAdded.length() > 0) {
      query.append(" and ti.id not in (" + listOfTreatmentsInterventionsAllreadyAdded + ") ");
    }

    query.append(" order by UPPER(ti.treatmentInterventionName) asc");

    List<?> tiList =
        factory.find(
            query.toString(),
            new String[] {"Emergency", "TreatmentName"},
            new Object[] {Specialty.EMERGENCY.getID(), criteria + "%"});

    return TreatmentInterventionLiteVoAssembler
        .createTreatmentInterventionLiteVoCollectionFromTreatmentIntervention(tiList);
  }
  @Override
  protected void onBtnSaveClick() throws ims.framework.exceptions.PresentationLogicException {
    PatientElectiveListBedAdmissionVo patientElectiveList = null;
    if (Boolean.TRUE.equals(ConfigFlag.GEN.USE_ELECTIVE_LIST_FUNCTIONALITY.getValue())) {
      // Get current Patient Elective List
      patientElectiveList =
          domain.getPatientElectiveListForAppointment(
              form.getGlobalContext().Scheduling.getBookingAppointmentRef());

      if (patientElectiveList != null) {
        if (Specialty.EMERGENCY.equals(form.cmbSpecialty().getValue())) {
          // If there are no other elective list to be cancelled
          TCIOutcomeForPatientElectiveListVo outcome = new TCIOutcomeForPatientElectiveListVo();

          if (ElectiveListReason.DIAGNOSTIC.equals(patientElectiveList.getElectiveListReason()))
            outcome.setOutcome(AdmissionOfferOutcome.PATIENT_ADMITTED);
          else outcome.setOutcome(AdmissionOfferOutcome.PATIENT_ADMITTED_COMMENCED_8);

          outcome.setChangeBy((MemberOfStaffRefVo) domain.getMosUser());
          outcome.setStatusDateTime(new DateTime());
          outcome.setOutcomeReason(null);

          patientElectiveList.getTCIDetails().setCurrentOutcome(outcome);
          patientElectiveList.getTCIDetails().getOutcomeHistory().add(outcome);
          patientElectiveList.getTCIDetails().setIsActive(Boolean.FALSE);

          if (ElectiveListReason.DIAGNOSTIC.equals(patientElectiveList.getElectiveListReason())) {
            if (patientElectiveList.getPathwayClock() != null)
              patientElectiveList
                  .getPathwayClock()
                  .setStopDate(
                      form.dtimAdmDateTime().getValue() != null
                          ? form.dtimAdmDateTime().getValue().getDate()
                          : null);
          }

          // Check for existing Patient Elective list
          if (Boolean.TRUE.equals(
              domain.hasPatientElectiveListsToBeCancelled(
                  form.getGlobalContext().Core.getPatientShort(),
                  patientElectiveList,
                  patientElectiveList.getElectiveList().getService()))) {
            form.getLocalContext().setPatientElectiveList(patientElectiveList);
            engine.showMessage(
                "Patient has other Patient Elective records for the same service. Cancel these records?",
                "Warning",
                MessageButtons.YESNOCANCEL);
            return;
          }
        }
      }
    }

    if (saveAdmission(patientElectiveList, null)) engine.close(DialogResult.OK);
  }