Example #1
0
  public DischargeSupplementaryNotesVo saveSupplementaryAndDD(
      DischargeSupplementaryNotesVo voDischSupp, DischargeDetailsVo voDD)
      throws DomainInterfaceException, StaleObjectException {
    if (voDischSupp == null)
      throw new CodingRuntimeException("DischargeSupplementaryNotesVo is null");

    if (!voDischSupp.isValidated())
      throw new CodingRuntimeException(
          "DischargeSupplementaryNotesVo Value Object has not been validated");

    DomainFactory factory = getDomainFactory();
    DischargeSupplementaryNotes doDSN =
        DischargeSupplementaryNotesVoAssembler.extractDischargeSupplementaryNotes(
            factory, voDischSupp);

    // WDEV-8813
    // Workaround for the case when 2 users save in the same time a new
    // DischargeSupplementaryNotesVO
    // In this case the domain.save call doesn't throw a StaleObjectExeption, even if it is the case
    if (!voDischSupp.getID_DischargeSupplementaryNotesIsNotNull()) {
      DischargeSupplementaryNotesVo voDischargeSupp =
          getSupplementary(voDischSupp.getCareContext());
      if (voDischargeSupp != null) {
        throw new StaleObjectException(
            doDSN, "A DischargeSupplementaryNotesVo was already saved by another user");
      }
    }

    factory.save(doDSN);

    if (voDD != null) {
      DischargeDetails doDD = DischargeDetailsVoAssembler.extractDischargeDetails(factory, voDD);
      factory.save(doDD);
    }
    return DischargeSupplementaryNotesVoAssembler.create(doDSN);
  }