@Override
  @PlusTransactional
  public ResponseEvent<DpRequirementDetail> updateRequirement(
      RequestEvent<DpRequirementDetail> req) {
    try {
      AccessCtrlMgr.getInstance().ensureUserIsAdmin();

      Long dpReqId = req.getPayload().getId();
      DpRequirement existing = getDprDao().getById(dpReqId);
      if (existing == null) {
        return ResponseEvent.userError(DpRequirementErrorCode.NOT_FOUND);
      }

      DpRequirement newDpr = dprFactory.createDistributionProtocolRequirement(req.getPayload());
      OpenSpecimenException ose = new OpenSpecimenException(ErrorType.USER_ERROR);
      ensureUniqueReqConstraints(existing, newDpr, ose);
      ose.checkAndThrow();

      existing.update(newDpr);
      getDprDao().saveOrUpdate(existing);
      return ResponseEvent.response(DpRequirementDetail.from(existing));
    } catch (OpenSpecimenException ose) {
      return ResponseEvent.error(ose);
    } catch (Exception e) {
      return ResponseEvent.serverError(e);
    }
  }
  @Override
  @PlusTransactional
  public ResponseEvent<DpRequirementDetail> deleteRequirement(RequestEvent<Long> req) {
    try {
      AccessCtrlMgr.getInstance().ensureUserIsAdmin();

      DpRequirement existing = getDprDao().getById(req.getPayload());
      if (existing == null) {
        return ResponseEvent.userError(DpRequirementErrorCode.NOT_FOUND);
      }

      existing.delete();
      getDprDao().saveOrUpdate(existing);
      return ResponseEvent.response(DpRequirementDetail.from(existing));
    } catch (OpenSpecimenException ose) {
      return ResponseEvent.error(ose);
    } catch (Exception e) {
      return ResponseEvent.serverError(e);
    }
  }
  private void ensureUniqueReqConstraints(
      DpRequirement oldDpr, DpRequirement newDpr, OpenSpecimenException ose) {
    if (oldDpr != null && oldDpr.equalsSpecimenGroup(newDpr)) {
      return;
    }

    DistributionProtocol dp = newDpr.getDistributionProtocol();
    if (dp.hasRequirement(
        newDpr.getSpecimenType(), newDpr.getAnatomicSite(), newDpr.getPathologyStatus())) {
      ose.addError(
          DpRequirementErrorCode.ALREADY_EXISTS,
          newDpr.getSpecimenType(),
          newDpr.getAnatomicSite(),
          newDpr.getPathologyStatus());
    }
  }