// WDEV-19239
  public CodedDiagnosesForAttendanceVoCollection saveCodedDiagnosis(
      CodedDiagnosesForAttendanceVoCollection codedDiagList) throws StaleObjectException {
    if (codedDiagList == null)
      throw new CodingRuntimeException(
          "Cannot save a null CodedDiagnosesForAttendanceVoCollection.");

    if (!codedDiagList.isValidated())
      throw new CodingRuntimeException("CodedDiagnosesForAttendanceVoCollection is not validated.");

    DomainFactory factory = getDomainFactory();
    CodedDiagnosesForAttendanceVoCollection coll = new CodedDiagnosesForAttendanceVoCollection();

    for (CodedDiagnosesForAttendanceVo diagnose : codedDiagList) {
      if (diagnose == null) continue;

      CodedDiagForAttendance doCodedDiag =
          CodedDiagnosesForAttendanceVoAssembler.extractCodedDiagForAttendance(factory, diagnose);

      factory.save(doCodedDiag);
      coll.add(CodedDiagnosesForAttendanceVoAssembler.create(doCodedDiag));
    }

    return coll;
  }
  // WDEV-19239
  public PatientDiagnosisAtConsultationVoCollection saveDiagnosisSequence(
      PatientDiagnosisAtConsultationVoCollection patDiagnosis,
      CodedDiagnosesForAttendanceVoCollection codedDiagnosis,
      CareContextRefVo careContextRef)
      throws StaleObjectException {
    if (codedDiagnosis != null && codedDiagnosis.size() > 0) {
      saveCodedDiagnosis(codedDiagnosis);
    }

    PatientDiagnosisAtConsultationVoCollection collpatDiag = null;

    if (patDiagnosis != null && patDiagnosis.size() > 0) {
      collpatDiag = saveDiagnosis(patDiagnosis, careContextRef);
    }

    return collpatDiag;
  }
  public PatientDiagnosisAtConsultationVoCollection saveDiagnosis(
      PatientDiagnosisAtConsultationVoCollection diagnosis, CareContextRefVo careContext)
      throws StaleObjectException {
    if (diagnosis == null)
      throw new CodingRuntimeException(
          "Cannot save a null PatientDiagnosisAtConsultationVoCollection.");

    if (!diagnosis.isValidated())
      throw new CodingRuntimeException(
          "PatientDiagnosisAtConsultationVoCollection is not validated.");

    DomainFactory factory = getDomainFactory();
    PatientDiagnosisAtConsultationVoCollection coll =
        new PatientDiagnosisAtConsultationVoCollection();

    // WDEV-19239
    boolean isPatientDiagPrimary = false;
    CareContextRefVo careContextRef = null;
    for (PatientDiagnosisAtConsultationVo diagnose : diagnosis) {
      if (diagnose == null) continue;

      careContextRef = diagnose.getCareContext();
      if (isPrimary(diagnose)) isPatientDiagPrimary = true;

      PatientDiagnosis doDiagnose =
          PatientDiagnosisAtConsultationVoAssembler.extractPatientDiagnosis(factory, diagnose);

      factory.save(doDiagnose);
      coll.add(PatientDiagnosisAtConsultationVoAssembler.create(doDiagnose));
    }

    CodedDiagnosesForAttendanceVoCollection collCodedDiag =
        listCodedDiagnosesForAttendance(careContextRef, true);

    if (isPatientDiagPrimary && collCodedDiag != null && collCodedDiag.size() > 0) {
      for (CodedDiagnosesForAttendanceVo codedDiag : collCodedDiag) {
        codedDiag.setIsMain(false);

        CodedDiagForAttendance doCodedDiag =
            CodedDiagnosesForAttendanceVoAssembler.extractCodedDiagForAttendance(
                factory, codedDiag);
        factory.save(doCodedDiag);
      }
    }

    if (careContext != null) {
      AttendDiagInvTreatStatusVo attendDiagInvTreatStatus =
          getAttendDiagInvTreatStatus(careContext);

      if (attendDiagInvTreatStatus != null) {
        attendDiagInvTreatStatus.setNoDiagnoses(null);
        attendDiagInvTreatStatus.setDiagnosesNotRecorded(null);

        AttendDiagInvTreatStatus doAttendDiagInvTreatStatus =
            AttendDiagInvTreatStatusVoAssembler.extractAttendDiagInvTreatStatus(
                factory, attendDiagInvTreatStatus);
        factory.save(doAttendDiagInvTreatStatus);
      }
    }

    return coll;
  }