public PatientAssessmentVo save(
      PatientAssessmentVo patientAssessment, ConsultationAssessmentsLiteVo consultationAssessment)
      throws StaleObjectException {
    // Check parameters
    if (patientAssessment == null || consultationAssessment == null)
      throw new CodingRuntimeException("Can't save null records.");

    if (patientAssessment.isValidated() == false || consultationAssessment.isValidated() == false)
      throw new CodingRuntimeException("Can't save records not validated.");

    DomainFactory factory = getDomainFactory();

    // Ensure the latest Consultation Assessments record is used (to avoid StaleObject)
    if (consultationAssessment.getID_ConsultationAssessments() != null) {
      // If the Consultation Assessment was saved then retrieve the latest version of it
      consultationAssessment =
          ConsultationAssessmentsLiteVoAssembler.create(
              (ConsultationAssessments)
                  factory.getDomainObject(
                      ConsultationAssessments.class,
                      consultationAssessment.getID_ConsultationAssessments()));
    } else {
      // IF the Consultation Assessment isn't saved then check database for a saved record
      ConsultationAssessmentsLiteVo recordInDB =
          getConsultationAssessments(consultationAssessment.getCatsReferral());

      if (recordInDB != null) consultationAssessment = recordInDB;
    }

    // Extract domain objects
    PatientAssessment domPatientAssessment =
        PatientAssessmentVoAssembler.extractPatientAssessment(factory, patientAssessment);

    // Commit PatientAssessment to database
    factory.save(domPatientAssessment);

    PatientAssessmentShortVo shortAssessment =
        PatientAssessmentShortVoAssembler.create(domPatientAssessment);
    consultationAssessment.getPatientAssessment().add(shortAssessment);

    ConsultationAssessments domConsultationAssessments =
        ConsultationAssessmentsLiteVoAssembler.extractConsultationAssessments(
            factory, consultationAssessment);

    factory.save(domConsultationAssessments);

    // Return the saved record
    return PatientAssessmentVoAssembler.create(domPatientAssessment);
  }
  public PatientAssessmentVo save(PatientAssessmentVo patientAssessment)
      throws StaleObjectException {
    // Check parameter for null and validation
    if (patientAssessment == null) throw new CodingRuntimeException("Can't save null record.");

    if (patientAssessment.isValidated() == false)
      throw new CodingRuntimeException("Can't save records not validated.");

    // Extract PatientAssessment record
    DomainFactory factory = getDomainFactory();

    PatientAssessment domPatientAssessment =
        PatientAssessmentVoAssembler.extractPatientAssessment(factory, patientAssessment);

    // Commit to database
    factory.save(domPatientAssessment);
    // Return the saved record
    return PatientAssessmentVoAssembler.create(domPatientAssessment);
  }
  public Boolean savePatientDocument(
      PatientDocumentVo patientDocument, PatientAssessmentVo patientAssessment)
      throws StaleObjectException {
    if (patientDocument == null) throw new DomainRuntimeException("Invalid PatientDocument record");
    if (!patientDocument.isValidated())
      throw new DomainRuntimeException("PatientDocument record not validated");
    if (patientAssessment == null) throw new DomainRuntimeException("Invalid patient assessment");
    if (!patientAssessment.isValidated())
      throw new DomainRuntimeException("User assessment not validated");

    DomainFactory factory = getDomainFactory();

    // Save PatientDocumet record
    PatientDocument domainPatientDocument =
        PatientDocumentVoAssembler.extractPatientDocument(factory, patientDocument);
    factory.save(domainPatientDocument);

    // Save PatientAssessment record
    PatientAssessment domainObject =
        PatientAssessmentVoAssembler.extractPatientAssessment(factory, patientAssessment);
    factory.save(domainObject);

    return true;
  }