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);
  }