public InterventionsTreatmentsForAttendenceVo save(
      InterventionsTreatmentsForAttendenceVo record, Boolean addedDuringCoding)
      throws StaleObjectException {
    if (record == null)
      throw new CodingRuntimeException(
          "Cannot save a null InterventionsTreatmentsForAttendenceVo.");

    if (!record.isValidated())
      throw new CodingRuntimeException("InterventionsTreatmentsForAttendenceVo is not validated.");

    DomainFactory factory = getDomainFactory();

    InterventionsTreatmentsForAttendence doRecord =
        InterventionsTreatmentsForAttendenceVoAssembler.extractInterventionsTreatmentsForAttendence(
            factory, record);

    if (record.getID_InterventionsTreatmentsForAttendence() == null
        && record.getAttendance() != null) {
      InterventionsTreatmentsForAttendenceVo staleRecord =
          getInterventionsTreatmentsForAttendence(record.getAttendance());
      if (staleRecord != null) throw new StaleObjectException(doRecord);
    }

    factory.save(doRecord);

    if (!Boolean.TRUE.equals(addedDuringCoding)) {
      AttendDiagInvTreatStatusVo attendDiagInvTreatStatus =
          getAttendDiagInvTreatStatus(record.getAttendance());
      if (attendDiagInvTreatStatus != null
          && (Boolean.TRUE.equals(attendDiagInvTreatStatus.getNoTreatments())
              || Boolean.TRUE.equals(attendDiagInvTreatStatus.getTreatmentsNotRecorded()))) {
        attendDiagInvTreatStatus.setNoTreatments(null);
        attendDiagInvTreatStatus.setTreatmentsNotRecorded(null);

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

    return InterventionsTreatmentsForAttendenceVoAssembler.create(doRecord);
  }
  public AttendDiagInvTreatStatusVo saveAttendDiagInvTreatStatus(
      AttendDiagInvTreatStatusVo attendDiagInvTreatStatus)
      throws StaleObjectException, UniqueKeyViolationException {
    if (attendDiagInvTreatStatus == null)
      throw new CodingRuntimeException("Cannot save a null AttendDiagInvTreatStatusVo.");

    if (!attendDiagInvTreatStatus.isValidated())
      throw new CodingRuntimeException("AttendDiagInvTreatStatusVo is not validated.");

    DomainFactory factory = getDomainFactory();
    AttendDiagInvTreatStatus doAttendDiagInvTreatStatus =
        AttendDiagInvTreatStatusVoAssembler.extractAttendDiagInvTreatStatus(
            factory, attendDiagInvTreatStatus);

    factory.save(doAttendDiagInvTreatStatus);

    return AttendDiagInvTreatStatusVoAssembler.create(doAttendDiagInvTreatStatus);
  }
  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;
  }