public PatientAssessmentVo getPatientAssessment(PatientAssessmentRefVo patientAssessment) {
    // Test Patient Assessment record
    if (patientAssessment == null || patientAssessment.getID_PatientAssessment() == null)
      return null;

    // Return Patient Assessment record from database
    return PatientAssessmentVoAssembler.create(
        (PatientAssessment)
            getDomainFactory()
                .getDomainObject(
                    PatientAssessment.class, patientAssessment.getID_PatientAssessment()));
  }
  public PatientAssessmentVo getLatestVersionAssessment(
      PatientAssessmentRefVo assessment, CatsReferralRefVo referral) {
    if (assessment == null || referral == null) return null;

    StringBuilder query = new StringBuilder();

    ArrayList<String> paramNames = new ArrayList<String>();
    ArrayList<Object> paramValues = new ArrayList<Object>();

    query.append("SELECT assessment FROM PatientAssessment AS assessment ");
    query.append(" WHERE assessment.id = :ASSESS_ID AND assessment.isRIE is null");

    paramNames.add("ASSESS_ID");
    paramValues.add(assessment.getID_PatientAssessment());

    query.append(" AND assessment.id = (");
    query.append(
        " SELECT MAX(assess.id) FROM ConsultationAssessments AS ca LEFT JOIN ca.patientAssessment AS assess LEFT JOIN ca.catsReferral AS cats ");
    query.append(" WHERE cats.id = :CATS_ID AND ca.isRIE is null");
    query.append(")");

    paramNames.add("CATS_ID");
    paramValues.add(referral.getID_CatsReferral());

    return PatientAssessmentVoAssembler.create(
        (PatientAssessment)
            getDomainFactory().findFirst(query.toString(), paramNames, paramValues));
  }