コード例 #1
0
  private String deIdentifyParticipantName(String report, Map<String, Object> contextMap) {
    Long visitId = (Long) contextMap.get("visitId");
    Visit visit = daoFactory.getVisitsDao().getById(visitId);
    Participant participant = visit.getRegistration().getParticipant();

    StringBuilder regex = new StringBuilder();
    String lastName = participant.getLastName();
    if (StringUtils.isNotBlank(lastName)) {
      regex.append(" ").append(lastName).append(" ");
    }

    String firstName = participant.getFirstName();
    if (StringUtils.isNotBlank(firstName)) {
      addOr(regex);
      regex.append(" ").append(firstName).append(" ");
    }

    if (regex.length() > 0) {
      regex.insert(0, "(?i)\\b(");
      regex.append(")\\b");
      report = report.replaceAll(regex.toString(), REPLACEMENT_STRING);
    }
    return report;
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  @Override
  public ResponseEvent<Map<String, Object>> importObject(
      RequestEvent<ImportObjectDetail<Map<String, Object>>> req) {
    try {
      ImportObjectDetail<Map<String, Object>> importDetail = req.getPayload();
      Map<String, Object> params = importDetail.getParams();

      Map<String, Object> extnObj = importDetail.getObject();
      String recordId = (String) extnObj.get("recordId");
      if (importDetail.isCreate() && StringUtils.isNotBlank(recordId)) {
        return ResponseEvent.userError(FormErrorCode.REC_ID_SPECIFIED_FOR_CREATE);
      } else if (!importDetail.isCreate() && StringUtils.isBlank(recordId)) {
        return ResponseEvent.userError(FormErrorCode.REC_ID_REQUIRED);
      }

      String entityType = (String) params.get("entityType");
      Long objectId = null;
      CollectionProtocol cp = null;

      if (entityType.equals("Participant")) {
        String ppid = (String) extnObj.get("ppid");
        String cpShortTitle = (String) extnObj.get("cpShortTitle");
        CollectionProtocolRegistration cpr =
            daoFactory.getCprDao().getCprByCpShortTitleAndPpid(cpShortTitle, ppid);
        if (cpr == null) {
          return ResponseEvent.userError(CprErrorCode.NOT_FOUND);
        }

        objectId = cpr.getId();
        cp = cpr.getCollectionProtocol();
      } else if (entityType.equals("SpecimenCollectionGroup")) {
        String visitName = (String) extnObj.get("visitName");
        Visit visit = daoFactory.getVisitsDao().getByName(visitName);
        if (visit == null) {
          return ResponseEvent.userError(VisitErrorCode.NOT_FOUND);
        }

        objectId = visit.getId();
        cp = visit.getCollectionProtocol();
      } else if (entityType.equals("Specimen") || entityType.equals("SpecimenEvent")) {
        String label = (String) extnObj.get("specimenLabel");
        Specimen specimen = daoFactory.getSpecimenDao().getByLabel(label);
        if (specimen == null) {
          return ResponseEvent.userError(SpecimenErrorCode.NOT_FOUND, label);
        }

        objectId = specimen.getId();
        cp = specimen.getCollectionProtocol();
      }

      String formName = (String) params.get("formName");
      Container form = Container.getContainer(formName);
      if (form == null) {
        return ResponseEvent.userError(FormErrorCode.NOT_FOUND);
      }

      Long formCtxId = formDao.getFormCtxtId(form.getId(), entityType, cp.getId());
      if (formCtxId == null) {
        return ResponseEvent.userError(
            FormErrorCode.NO_ASSOCIATION, cp.getShortTitle(), form.getCaption());
      }

      Map<String, Object> appData = new HashMap<String, Object>();
      appData.put("formCtxtId", formCtxId);
      appData.put("objectId", objectId);

      Map<String, Object> formValueMap = (Map<String, Object>) extnObj.get("formValueMap");
      formValueMap.put("appData", appData);

      if (StringUtils.isNotBlank(recordId)) {
        formValueMap.put("id", Long.parseLong(recordId));
      }

      FormData formData = FormData.getFormData(form, formValueMap, true, null);

      FormDataDetail formDataDetail = new FormDataDetail();
      formDataDetail.setFormId(form.getId());
      formDataDetail.setRecordId(formData.getRecordId());
      formDataDetail.setFormData(formData);
      ResponseEvent<FormDataDetail> resp =
          formSvc.saveFormData(new RequestEvent<FormDataDetail>(formDataDetail));
      resp.throwErrorIfUnsuccessful();

      return ResponseEvent.response(resp.getPayload().getFormData().getFieldNameValueMap(true));
    } catch (OpenSpecimenException ose) {
      return ResponseEvent.error(ose);
    } catch (Exception e) {
      return ResponseEvent.serverError(e);
    }
  }