Esempio n. 1
0
  /**
   * Creates a table with the given indicator
   *
   * @param indicator The indicator
   * @param i18n i18n object
   * @param expressionService The expression service
   * @param HEADER3 The header3 font
   * @param ITALIC The italic font
   * @param TEXT The text font
   * @param keepTogether Indicates whether the table could be broken across multiple pages or should
   *     be kept at one page.
   * @param columnWidths The column widths.
   */
  public static PdfPTable printIndicator(
      Indicator indicator,
      I18n i18n,
      ExpressionService expressionService,
      boolean keepTogether,
      float... columnWidths) {
    PdfPTable table = getPdfPTable(keepTogether, columnWidths);

    table.addCell(getHeaderCell(indicator.getName(), 2));

    table.addCell(getEmptyCell(2, 15));

    table.addCell(getItalicCell(i18n.getString("short_name")));
    table.addCell(getTextCell(indicator.getShortName()));

    if (nullIfEmpty(indicator.getCode()) != null) {
      table.addCell(getItalicCell(i18n.getString("code")));
      table.addCell(getTextCell(indicator.getCode()));
    }
    if (nullIfEmpty(indicator.getDescription()) != null) {
      table.addCell(getItalicCell(i18n.getString("description")));
      table.addCell(getTextCell(indicator.getDescription()));
    }

    table.addCell(getItalicCell(i18n.getString("annualized")));
    table.addCell(getTextCell(i18n.getString(getBoolean().get(indicator.isAnnualized()))));

    table.addCell(getItalicCell(i18n.getString("indicator_type")));
    table.addCell(getTextCell(indicator.getIndicatorType().getName()));

    table.addCell(getItalicCell(i18n.getString("numerator_description")));
    table.addCell(getTextCell(indicator.getNumeratorDescription()));

    table.addCell(getItalicCell(i18n.getString("numerator_formula")));
    table.addCell(
        getTextCell(expressionService.getExpressionDescription(indicator.getNumerator())));

    table.addCell(getItalicCell(i18n.getString("denominator_description")));
    table.addCell(getTextCell(indicator.getDenominatorDescription()));

    table.addCell(getItalicCell(i18n.getString("denominator_formula")));
    table.addCell(
        getTextCell(expressionService.getExpressionDescription(indicator.getDenominator())));

    for (AttributeValue value : indicator.getAttributeValues()) {
      table.addCell(getItalicCell(value.getAttribute().getName()));
      table.addCell(getTextCell(value.getValue()));
    }

    table.addCell(getEmptyCell(2, 30));

    return table;
  }
Esempio n. 2
0
  @Override
  public String execute() throws Exception {
    name = name.trim();

    Program match = programService.getProgramByName(name);

    if (match != null && (id == null || match.getId() != id.intValue())) {
      message = i18n.getString("duplicate_names");

      return ERROR;
    }

    message = i18n.getString("everything_is_ok");

    return SUCCESS;
  }
  public String execute() throws Exception {
    // System.out.println("Inside validateInvenotryTypeAttribute ");

    name = name.trim();

    EquipmentTypeAttribute match =
        equipmentTypeAttributeService.getEquipmentTypeAttributeByName(name);

    if (match != null && (id == null || match.getId() != id.intValue())) {
      message = i18n.getString("name_in_use");

      return INPUT;
    }

    message = i18n.getString("everything_is_ok");

    return SUCCESS;
  }
Esempio n. 4
0
  /**
   * Writes a "Data Elements" title in front of page
   *
   * @param dataElementIds the identifier list of Data
   * @param i18n The i18n object
   * @param format The i18nFormat object
   */
  public static void printObjectFrontPage(
      Document document,
      Collection<?> objects,
      I18n i18n,
      I18nFormat format,
      String frontPageLabel) {
    if (objects == null || objects.size() > 0) {
      String title = i18n.getString(frontPageLabel);

      printFrontPage(document, title, i18n, format);
    }
  }
Esempio n. 5
0
  /**
   * Creates a table with the given validation rule
   *
   * @param validationRule The validation rule
   * @param i18n i18n object
   * @param expressionService The expression service
   * @param HEADER3 The header3 font
   * @param ITALIC The italic font
   * @param TEXT The text font
   * @param keepTogether Indicates whether the table could be broken across multiple pages or should
   *     be kept at one page.
   * @param columnWidths The column widths.
   */
  public static PdfPTable printValidationRule(
      ValidationRule validationRule,
      I18n i18n,
      ExpressionService expressionService,
      boolean keepTogether,
      float... columnWidths) {
    PdfPTable table = getPdfPTable(keepTogether, columnWidths);

    table.addCell(getHeaderCell(validationRule.getName(), 2));

    table.addCell(getEmptyCell(2, 15));

    if (nullIfEmpty(validationRule.getDescription()) != null) {
      table.addCell(getItalicCell(i18n.getString("description")));
      table.addCell(getTextCell(validationRule.getDescription()));
    }

    table.addCell(getItalicCell(i18n.getString("operator")));
    table.addCell(getTextCell(i18n.getString(validationRule.getOperator().toString())));

    table.addCell(getItalicCell(i18n.getString("left_side_of_expression")));
    table.addCell(
        getTextCell(
            expressionService.getExpressionDescription(
                validationRule.getLeftSide().getExpression())));

    table.addCell(getItalicCell(i18n.getString("left_side_description")));
    table.addCell(getTextCell(validationRule.getLeftSide().getDescription()));

    table.addCell(getItalicCell(i18n.getString("right_side_of_expression")));
    table.addCell(
        getTextCell(
            expressionService.getExpressionDescription(
                validationRule.getRightSide().getExpression())));

    table.addCell(getItalicCell(i18n.getString("right_side_description")));
    table.addCell(getTextCell(validationRule.getRightSide().getDescription()));

    table.addCell(getItalicCell(i18n.getString("period_type")));
    table.addCell(getTextCell(i18n.getString(validationRule.getPeriodType().getName())));

    table.addCell(getEmptyCell(2, 30));

    return table;
  }
  public String execute() {
    try {
      DataElementCategory category = dataElementCategoryService.getDataElementCategory(id);

      dataElementCategoryService.deleteDataElementCategory(category);
    } catch (DeleteNotAllowedException ex) {
      if (ex.getErrorCode().equals(DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS)) {
        message =
            i18n.getString("object_not_deleted_associated_by_objects") + " " + ex.getMessage();

        return ERROR;
      }
    }

    return SUCCESS;
  }
  public String execute() throws Exception {
    // ---------------------------------------------------------------------
    // Name
    // ---------------------------------------------------------------------

    if (name == null) {
      message = i18n.getString("specify_name");

      return INPUT;
    } else {
      name = name.trim();

      if (name.length() == 0) {
        message = i18n.getString("specify_name");

        return INPUT;
      }

      DeTarget match = deTargetService.getDeTargetByName(name);

      if (match != null && (deTargetId == null || match.getId() != deTargetId)) {
        message = i18n.getString("duplicate_names");

        return INPUT;
      }
    }
    // ---------------------------------------------------------------------
    // Short name
    // ---------------------------------------------------------------------

    if (shortName == null) {
      message = i18n.getString("specify_short_name");

      return INPUT;
    } else {
      shortName = shortName.trim();

      if (shortName.length() == 0) {
        message = i18n.getString("specify_short_name");

        return INPUT;
      }

      DeTarget match = deTargetService.getDeTargetByShortName(shortName);

      if (match != null && (deTargetId == null || match.getId() != deTargetId)) {
        message = i18n.getString("duplicate_short_names");

        return INPUT;
      }
    }

    message = "validation success";
    return SUCCESS;
  }
  public String execute() {
    if (name != null) {
      DataElementCategoryOption match =
          dataElementCategoryService.getDataElementCategoryOptionByName(name);

      if (match != null && (id == null || match.getId() != id)) {
        message = i18n.getString("name_in_use");

        return ERROR;
      }
    }

    message = "ok";

    return SUCCESS;
  }
  public String execute() {
    // ---------------------------------------------------------------------
    // Validate values
    // ---------------------------------------------------------------------
    if (name != null) {
      OrganisationUnitGroup match =
          organisationUnitGroupService.getOrganisationUnitGroupByName(name);

      if (match != null && (id == null || match.getId() != id)) {
        message = i18n.getString("name_is_already_in_use");

        return ERROR;
      }
    }

    message = "OK";

    return SUCCESS;
  }
Esempio n. 10
0
  /**
   * Writes a DHIS 2 title in front of page
   *
   * @param document The document
   * @param exportParams the exporting params
   */
  private static void printFrontPage(
      Document document, String title, I18n i18n, I18nFormat format) {
    PdfPTable table = getPdfPTable(true, 1.00f);

    table.addCell(getTitleCell(i18n.getString("district_health_information_software"), 1));

    table.addCell(getEmptyCell(1, 40));

    table.addCell(getSubtitleCell(title, 1));

    table.addCell(getEmptyCell(1, 40));

    String date = format.formatDate(Calendar.getInstance().getTime());

    table.addCell(getSubtitleCell(date, 1));

    addTableToDocument(document, table);

    moveToNewPage(document);
  }
Esempio n. 11
0
  /**
   * Creates a table with the given unit
   *
   * @param unit The organization unit
   * @param i18n i18n object
   * @param format
   * @param HEADER3 The header3 font
   * @param ITALIC The italic font
   * @param TEXT The text font
   * @param keepTogether Indicates whether the table could be broken across multiple pages or should
   *     be kept at one page.
   * @param columnWidths The column widths.
   */
  public static PdfPTable printOrganisationUnit(
      OrganisationUnit unit,
      I18n i18n,
      I18nFormat format,
      boolean keepTogether,
      float... columnWidths) {
    PdfPTable table = getPdfPTable(keepTogether, columnWidths);

    table.addCell(getHeaderCell(unit.getName(), 2));

    table.addCell(getEmptyCell(2, 15));

    table.addCell(getItalicCell(i18n.getString("short_name")));
    table.addCell(getTextCell(unit.getShortName()));

    if (nullIfEmpty(unit.getCode()) != null) {
      table.addCell(getItalicCell(i18n.getString("code")));
      table.addCell(getTextCell(unit.getCode()));
    }

    table.addCell(getItalicCell(i18n.getString("opening_date")));
    table.addCell(
        getTextCell(
            unit.getOpeningDate() != null ? format.formatDate(unit.getOpeningDate()) : EMPTY));

    if (unit.getClosedDate() != null) {
      table.addCell(getItalicCell(i18n.getString("closed_date")));
      table.addCell(getTextCell(format.formatDate(unit.getClosedDate())));
    }

    table.addCell(getItalicCell(i18n.getString("active")));

    if (nullIfEmpty(unit.getComment()) != null) {
      table.addCell(getItalicCell(i18n.getString("comment")));
      table.addCell(getTextCell(unit.getComment()));
    }

    for (AttributeValue value : unit.getAttributeValues()) {
      table.addCell(getItalicCell(value.getAttribute().getName()));
      table.addCell(getTextCell(value.getValue()));
    }

    table.addCell(getEmptyCell(2, 30));

    return table;
  }
  @Override
  public String execute() {
    DataElementCategoryCombo categoryCombo =
        dataElementCategoryService.getDataElementCategoryCombo(id);

    DataElementCategoryCombo defaultCategoryCombo =
        dataElementCategoryService.getDataElementCategoryComboByName(
            DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);

    if (!categoryCombo.equals(defaultCategoryCombo)) {
      try {
        dataElementCategoryService.deleteDataElementCategoryCombo(categoryCombo);
      } catch (DeleteNotAllowedException ex) {
        if (ex.getErrorCode().equals(DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS)) {
          message =
              i18n.getString("object_not_deleted_associated_by_objects") + " " + ex.getMessage();
          return ERROR;
        }
      }
    }

    return SUCCESS;
  }
Esempio n. 13
0
  /**
   * Creates a table with the given data element
   *
   * @param element The data element
   * @param i18n i18n object
   * @param HEADER3 The header3 font
   * @param ITALIC The italic font
   * @param TEXT The text font
   * @param keepTogether Indicates whether the table could be broken across multiple pages or should
   *     be kept at one page.
   * @param columnWidths The column widths.
   */
  public static PdfPTable printDataElement(
      DataElement element, I18n i18n, boolean keepTogether, float... columnWidths) {
    PdfPTable table = getPdfPTable(keepTogether, columnWidths);

    table.addCell(getHeaderCell(element.getName(), 2));

    table.addCell(getEmptyCell(2, 15));

    table.addCell(getItalicCell(i18n.getString("short_name")));
    table.addCell(getTextCell(element.getShortName()));

    if (nullIfEmpty(element.getCode()) != null) {
      table.addCell(getItalicCell(i18n.getString("code")));
      table.addCell(getTextCell(element.getCode()));
    }
    if (nullIfEmpty(element.getDescription()) != null) {
      table.addCell(getItalicCell(i18n.getString("description")));
      table.addCell(getTextCell(element.getDescription()));
    }

    if (nullIfEmpty(element.getType()) != null) {
      table.addCell(getItalicCell(i18n.getString("value_type")));
      table.addCell(getTextCell(i18n.getString(getType().get(element.getType()))));
    }
    if (nullIfEmpty(element.getAggregationOperator()) != null) {
      table.addCell(getItalicCell(i18n.getString("aggregation_operator")));
      table.addCell(
          getTextCell(
              i18n.getString(getAggregationOperator().get(element.getAggregationOperator()))));
    }

    for (AttributeValue value : element.getAttributeValues()) {
      table.addCell(getItalicCell(value.getAttribute().getName()));
      table.addCell(getTextCell(value.getValue()));
    }

    table.addCell(getEmptyCell(2, 30));

    return table;
  }
  public String execute() throws Exception {
    // ---------------------------------------------------------------------
    // Name
    // ---------------------------------------------------------------------

    // System.out.println("Validating ID : \t" + lineListElementId);
    // System.out.println("Validatied Name : \t" + name);

    if (name == null) {
      message = i18n.getString("specify_name");

      return INPUT;
    } else {
      name = name.trim();

      if (name.length() == 0) {
        message = i18n.getString("specify_name");

        return INPUT;
      }

      LineListElement match = lineListService.getLineListElementByName(name);

      if (match != null && (lineListElementId == null || match.getId() != lineListElementId)) {
        message = i18n.getString("duplicate_names");

        return INPUT;
      }
    }

    // ---------------------------------------------------------------------
    // Short name
    // ---------------------------------------------------------------------

    if (shortName == null) {
      message = i18n.getString("specify_short_name");

      return INPUT;
    } else {
      shortName = shortName.trim();

      if (shortName.length() == 0) {
        message = i18n.getString("specify_short_name");

        return INPUT;
      }
      if (shortName.length() > 25) {
        message = "Short name too long, please give 25 characters ";

        return INPUT;
      }

      LineListElement match = lineListService.getLineListElementByShortName(shortName);

      if (match != null && (lineListElementId == null || match.getId() != lineListElementId)) {
        message = i18n.getString("short_name_in_use");

        return INPUT;
      }
    }

    // ---------------------------------------------------------------------
    // Data Type
    // ---------------------------------------------------------------------

    if (dataType == null) {
      message = "Please Select Data Type";

      return INPUT;
    } else {
      dataType = dataType.trim();

      if (dataType.length() == 0) {
        message = "Please Select Data Type";

        return INPUT;
      }
    }

    // ---------------------------------------------------------------------
    // Presentation Type
    // ---------------------------------------------------------------------

    if (presentationType == null) {
      message = "Please Select Presentation Type";

      return INPUT;
    } else {
      presentationType = presentationType.trim();

      if (presentationType.length() == 0) {
        message = "Please Select Presentation Type";

        return INPUT;
      }
    }

    return SUCCESS;
  }
  @SuppressWarnings("unchecked")
  public String execute() {
    gatewayId = transportService.getDefaultGateway();

    if (gatewayId == null || gatewayId.trim().length() == 0) {
      message = i18n.getString("please_select_a_gateway_type_to_send_sms");

      return ERROR;
    }

    if (smsMessage == null || smsMessage.trim().length() == 0) {
      message = i18n.getString("no_message");

      return ERROR;
    }

    User currentUser = currentUserService.getCurrentUser();

    if (sendTarget != null && sendTarget.equals("phone")) {
      try {
        ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY);
        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        recipients = mapper.readValue(recipients.iterator().next(), Set.class);
      } catch (JsonParseException e) {
        e.printStackTrace();
      } catch (JsonMappingException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }

      message =
          messageSender.sendMessage(
              smsSubject, smsMessage, currentUser, true, recipients, gatewayId);
    } else if (sendTarget.equals("userGroup")) {
      UserGroup group = userGroupService.getUserGroup(userGroup);

      if (group == null) {
        message = i18n.getString("selected_user_group_is_unavailable");

        return ERROR;
      }

      if (group.getMembers() == null || group.getMembers().isEmpty()) {
        message = i18n.getString("selected_user_group_has_no_member");

        return ERROR;
      }

      message =
          messageSender.sendMessage(
              smsSubject, smsMessage, currentUser, false, group.getMembers(), gatewayId);
    } else if (sendTarget.equals("user")) {
      Collection<OrganisationUnit> units =
          selectionTreeManager.getReloadedSelectedOrganisationUnits();

      if (units != null && !units.isEmpty()) {
        Set<User> users = new HashSet<User>();

        for (OrganisationUnit unit : units) {
          users.addAll(unit.getUsers());
        }

        if (users.isEmpty()) {
          message = i18n.getString("there_is_no_user_assigned_to_selected_units");

          return ERROR;
        }

        message =
            messageSender.sendMessage(smsSubject, smsMessage, currentUser, false, users, gatewayId);
      }
    } else if (sendTarget.equals("unit")) {
      for (OrganisationUnit unit : selectionTreeManager.getSelectedOrganisationUnits()) {
        if (unit.getPhoneNumber() != null && !unit.getPhoneNumber().isEmpty()) {
          recipients.add(unit.getPhoneNumber());
        }
      }

      if (recipients.isEmpty()) {
        message = i18n.getString("selected_units_have_no_phone_number");

        return ERROR;
      }

      message =
          messageSender.sendMessage(
              smsSubject, smsMessage, currentUser, true, recipients, gatewayId);
    } else {
      Patient patient = null;
      Set<String> phones = new HashSet<String>();

      try {
        ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY);
        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        recipients = mapper.readValue(recipients.iterator().next(), Set.class);
      } catch (JsonParseException e) {
        e.printStackTrace();
      } catch (JsonMappingException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }

      for (String patientId : recipients) {
        patient = patientService.getPatient(Integer.parseInt(patientId));

        if (patient != null
            && patient.getPhoneNumber() != null
            && !patient.getPhoneNumber().isEmpty()) {
          phones.add(patient.getPhoneNumber());
        }
      }

      if (phones.isEmpty()) {
        message = i18n.getString("selected_persons_have_no_phone_number");

        return ERROR;
      }

      message =
          messageSender.sendMessage(smsSubject, smsMessage, currentUser, true, phones, gatewayId);
    }

    if (message != null && !message.equals("success")) {
      message = i18n.getString(message);

      return ERROR;
    }

    return SUCCESS;
  }
Esempio n. 16
0
  /**
   * Creates a table with the given validation rule
   *
   * @param user The User
   * @param i18n i18n object
   * @param format I18nFormat object
   * @param keepTogether Indicates whether the table could be broken across multiple pages or should
   *     be kept at one page.
   * @param columnWidths The column widths.
   */
  public static PdfPTable printUser(
      UserCredentials userCredentials,
      I18n i18n,
      I18nFormat format,
      boolean keepTogether,
      float... columnWidths) {
    User user = userCredentials.getUser();

    PdfPTable table = getPdfPTable(keepTogether, columnWidths);

    table.addCell(getHeaderCell(user.getFirstName() + ", " + user.getSurname(), 2));

    table.addCell(getEmptyCell(2, 15));

    table.addCell(getItalicCell(i18n.getString("username")));
    table.addCell(getTextCell(userCredentials.getUsername()));

    if (nullIfEmpty(user.getEmail()) != null) {
      table.addCell(getItalicCell(i18n.getString("email")));
      table.addCell(getTextCell(user.getEmail()));
    }

    if (nullIfEmpty(user.getPhoneNumber()) != null) {
      table.addCell(getItalicCell(i18n.getString("phone_number")));
      table.addCell(getTextCell(user.getPhoneNumber()));
    }

    table.addCell(getItalicCell(i18n.getString("last_login")));
    table.addCell(
        getTextCell(
            userCredentials.getLastLogin() != null
                ? format.formatDate(userCredentials.getLastLogin())
                : EMPTY));

    String temp = "";

    for (OrganisationUnit unit : user.getOrganisationUnits()) {
      temp += unit.getName().concat(", ");
    }

    temp = temp.trim();
    temp = temp.substring(0, temp.isEmpty() ? 0 : temp.length() - 1);

    table.addCell(getItalicCell(i18n.getString("organisation_units")));
    table.addCell(getTextCell(temp));

    temp = "";

    for (UserAuthorityGroup role : userCredentials.getUserAuthorityGroups()) {
      temp += role.getName().concat(", ");
    }

    temp = temp.trim();
    temp = temp.substring(0, temp.isEmpty() ? 0 : temp.length() - 1);

    table.addCell(getItalicCell(i18n.getString("roles")));
    table.addCell(getTextCell(temp));

    for (AttributeValue value : user.getAttributeValues()) {
      table.addCell(getItalicCell(value.getAttribute().getName()));
      table.addCell(getTextCell(value.getValue()));
    }

    table.addCell(getEmptyCell(2, 30));

    return table;
  }
Esempio n. 17
0
  /**
   * Writes a "Data dictionary" title in front of page
   *
   * @param document The document
   * @param i18n The i18n object
   * @param format The i18nFormat object
   */
  public static void printDocumentFrontPage(Document document, I18n i18n, I18nFormat format) {
    String title = i18n.getString("data_dictionary");

    printFrontPage(document, title, i18n, format);
  }