/** listPrescriptions */
  public ims.RefMan.vo.PrescriptionsVoCollection listPrescriptions(
      ims.RefMan.vo.CatsReferralRefVo catsRefVo) {
    if (catsRefVo == null || catsRefVo.getID_CatsReferral() == null) {
      throw new CodingRuntimeException("CatsReferralVo is null or id not provided");
    }

    DomainFactory factory = getDomainFactory();
    StringBuffer hql =
        new StringBuffer(
            "select prescriptions from ReferralOutcome as ro join ro.catsReferral as cats join ro.prescriptions as prescriptions ");

    ArrayList<String> names = new ArrayList<String>();
    ArrayList<Integer> values = new ArrayList<Integer>();

    hql.append("  where cats.id = :idCatsRefferal");
    names.add("idCatsRefferal");
    values.add(catsRefVo.getID_CatsReferral());

    List result = factory.find(hql.toString(), names, values);

    if (result != null && result.size() > 0) {
      PrescriptionsVoCollection voColl =
          PrescriptionsVoAssembler.createPrescriptionsVoCollectionFromPrescription(result);
      if (voColl != null && voColl.size() > 0) {
        voColl.sort(SortOrder.DESCENDING);
        return voColl;
      }
    }

    return null;
  }
  public void savePatientDocument(
      PatientDocumentVo document,
      CatsReferralReportsVo catReferral,
      ReferralOutcomeVo voOutcome,
      PrescriptionsVo selectedPrescription)
      throws StaleObjectException {
    if (document != null) {
      if (!document.isValidated())
        throw new DomainRuntimeException("PatientDocumentVo not validated");
    }

    DomainFactory factory = getDomainFactory();

    // WDEV-13956
    Prescription prescription =
        PrescriptionsVoAssembler.extractPrescription(factory, selectedPrescription);
    factory.save(prescription);
    // end

    PatientDocument doc = PatientDocumentVoAssembler.extractPatientDocument(factory, document);
    factory.save(doc);

    CatsReferral doCatsReferral =
        CatsReferralReportsVoAssembler.extractCatsReferral(factory, catReferral);
    if (catReferral != null) doCatsReferral.getReferralDocuments().add(doc);

    factory.save(doCatsReferral);

    // --------------wdev-14193
    prescription =
        (Prescription)
            factory.getDomainObject(Prescription.class, selectedPrescription.getID_Prescription());
    PrescriptionsVo temppre = PrescriptionsVoAssembler.create(prescription);
    if (voOutcome != null) {
      if (voOutcome.getPrescriptions().contains(temppre)) {
        voOutcome.getPrescriptions().remove(temppre);
        voOutcome.getPrescriptions().add(temppre);
      }
    }
    // -----------

    ReferralOutcome doRef = ReferralOutcomeVoAssembler.extractReferralOutcome(factory, voOutcome);
    factory.save(doRef);
  }