protected ActivityReportBean createActivityReportBean(Result result, boolean useTestName) {
    ActivityReportBean item = new ActivityReportBean();

    ResultService resultService = new ResultService(result);
    SampleService sampleService =
        new SampleService(result.getAnalysis().getSampleItem().getSample());
    PatientService patientService = new PatientService(sampleService.getSample());
    item.setResultValue(resultService.getResultValue("\n", true, true));
    item.setTechnician(resultService.getSignature());
    item.setAccessionNumber(sampleService.getAccessionNumber().substring(PREFIX_LENGTH));
    item.setReceivedDate(sampleService.getReceivedDateWithTwoYearDisplay());
    item.setResultDate(DateUtil.convertTimestampToTwoYearStringDate(result.getLastupdated()));
    item.setCollectionDate(
        DateUtil.convertTimestampToTwoYearStringDate(
            result.getAnalysis().getSampleItem().getCollectionDate()));

    List<String> values = new ArrayList<String>();
    values.add(
        patientService.getLastName() == null ? "" : patientService.getLastName().toUpperCase());
    values.add(patientService.getNationalId());

    String referringPatientId =
        ObservationHistoryService.getValueForSample(
            ObservationType.REFERRERS_PATIENT_ID, sampleService.getSample().getId());
    values.add(referringPatientId == null ? "" : referringPatientId);

    String name = StringUtil.buildDelimitedStringFromList(values, " / ", true);

    if (useTestName) {
      item.setPatientOrTestName(resultService.getTestName());
      item.setNonPrintingPatient(name);
    } else {
      item.setPatientOrTestName(name);
    }

    return item;
  }
  /**
   * Move everything appropriate to the referralItem including one or more of the referralResults
   * from the given list. Note: This method removes an item from the referralResults list.
   *
   * @param referralItem The source item
   * @param referralResults The created list
   */
  private List<ReferralResult> setReferralItemForNextTest(
      IReferralResultTest referralItem, List<ReferralResult> referralResults) {

    ReferralResult nextTestFirstResult = referralResults.remove(0);
    List<ReferralResult> resultsForOtherTests = new ArrayList<ReferralResult>(referralResults);

    referralItem.setReferredTestId(nextTestFirstResult.getTestId());
    referralItem.setReferredTestIdShadow(referralItem.getReferredTestId());
    referralItem.setReferredReportDate(
        DateUtil.convertTimestampToStringDate(nextTestFirstResult.getReferralReportDate()));
    // We can not use ResultService because that assumes the result is for an analysis, not a
    // referral
    Result result = nextTestFirstResult.getResult();

    String resultType = (result != null) ? result.getResultType() : "N";
    referralItem.setReferredResultType(resultType);
    if (!ResultType.isMultiSelectVariant(resultType)) {
      if (result != null) {
        String resultValue =
            GenericValidator.isBlankOrNull(result.getValue()) ? "" : result.getValue();
        referralItem.setReferredResult(resultValue);
        referralItem.setReferredDictionaryResult(resultValue);
      }
    } else {
      ArrayList<Result> resultList = new ArrayList<Result>();
      resultList.add(nextTestFirstResult.getResult());

      for (ReferralResult referralResult : referralResults) {
        if (nextTestFirstResult.getTestId().equals(referralResult.getTestId())
            && !GenericValidator.isBlankOrNull(referralResult.getResult().getValue())) {
          resultList.add(referralResult.getResult());
          resultsForOtherTests.remove(referralResult);
        }
      }

      referralItem.setMultiSelectResultValues(
          ResultService.getJSONStringForMultiSelect(resultList));
    }

    return resultsForOtherTests;
  }