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 InterventionsTreatmentsForAttendenceVo getInterventionsTreatmentsForAttendence(
      CareContextRefVo attendence) {
    if (attendence == null || attendence.getID_CareContext() == null) return null;

    DomainFactory factory = getDomainFactory();
    String query =
        "select it from InterventionsTreatmentsForAttendence as it where it.attendance.id = :AttendenceId ";

    List<?> list =
        factory.find(
            query, new String[] {"AttendenceId"}, new Object[] {attendence.getID_CareContext()});

    if (list == null || list.size() == 0) return null;

    return InterventionsTreatmentsForAttendenceVoAssembler.create(
        (InterventionsTreatmentsForAttendence) list.get(0));
  }