Package org.openmrs.module.htmlformentry

Examples of org.openmrs.module.htmlformentry.FormSubmissionError


      List<FormSubmissionError> ret = new ArrayList<FormSubmissionError>();
      try {
      if (drugWidget != null && drugWidget.getValue(context, submission) != null && ((String) drugWidget.getValue(context, submission)).equals("~"))
          throw new IllegalArgumentException("htmlformentry.error.cannotChooseADrugHeader");
      } catch (Exception ex){
          ret.add(new FormSubmissionError(context
                        .getFieldName(drugErrorWidget), Context
                        .getMessageSourceService().getMessage(ex.getMessage())));
      }
      //if no drug specified, then don't do anything.
      if (drugWidget != null && drugWidget.getValue(context, submission) != null && !((String) drugWidget.getValue(context, submission)).trim().equals("") && !((String) drugWidget.getValue(context, submission)).trim().equals("~")){
          try {
            if (doseWidget != null) {
              Double dose = (Double) doseWidget.getValue(context, submission);
              if (dose == null)
                throw new Exception("htmlformentry.error.required");
             
              // min max
              if (validateDose) {
                String drugID = (String) drugWidget.getValue(context, submission);
                Drug drug = Context.getConceptService().getDrug(drugID);
                if ((drug.getMinimumDailyDose() != null && dose < drug.getMinimumDailyDose()) || (drug.getMaximumDailyDose() != null && dose > drug.getMaximumDailyDose())) {
                  throw new IllegalArgumentException("htmlformentry.error.doseOutOfRange");
                }             
              }
            }
          } catch (Exception ex) {
            ret.add(new FormSubmissionError(context
                .getFieldName(doseErrorWidget), Context
                .getMessageSourceService().getMessage(ex.getMessage())));
          }
          try {
            if (startDateWidget != null) {
              Date dateCreated = startDateWidget.getValue(context, submission);
              if (dateCreated == null)
                throw new Exception("htmlformentry.error.required");
            }
          } catch (Exception ex) {
            ret.add(new FormSubmissionError(context
                .getFieldName(startDateErrorWidget), Context
                .getMessageSourceService().getMessage(ex.getMessage())));
          }
          try {
                    if (startDateWidget != null && discontinuedDateWidget != null) {
                        Date startDate = startDateWidget.getValue(context, submission);
                        Date endDate = discontinuedDateWidget.getValue(context, submission);
                        if (startDate != null && endDate != null
                                && startDate.getTime() > endDate.getTime())
                            throw new Exception("htmlformentry.error.discontinuedDateBeforeStartDate");
                    }
                } catch (Exception ex) {
                    ret.add(new FormSubmissionError(context
                            .getFieldName(discontinuedDateErrorWidget), Context
                            .getMessageSourceService().getMessage(ex.getMessage())));
                }
                try {
                    if (discontinuedReasonWidget != null && discontinuedDateWidget != null) {
                        String discReason = (String) discontinuedReasonWidget.getValue(context, submission);
                        Date endDate = discontinuedDateWidget.getValue(context, submission);
                        if (endDate == null && !StringUtils.isEmpty(discReason))
                            throw new Exception("htmlformentry.error.discontinuedReasonEnteredWithoutDate");
                    }
                } catch (Exception ex) {
                    ret.add(new FormSubmissionError(context
                            .getFieldName(discontinuedReasonErrorWidget), Context
                            .getMessageSourceService().getMessage(ex.getMessage())));
                }
                try {
                    if (orderDurationWidget != null && orderDurationWidget.getValue(context, submission) != null) {
                        String orderDurationVal = (String) orderDurationWidget.getValue(context, submission);
                        if (!orderDurationVal.equals("")){
                            try {
                                Integer.valueOf(orderDurationVal);
                            } catch (Exception ex){
                                throw new Exception("htmlformentry.error.durationMustBeEmptyOrNumeric");
                            }
                        }   
                    }
                } catch (Exception ex) {
                    ret.add(new FormSubmissionError(context
                            .getFieldName(orderDurationErrorWidget), Context
                            .getMessageSourceService().getMessage(ex.getMessage())));
                }
      }
     
View Full Code Here


    validateMandatoryField(context, request, identifierLocationWidget, identifierLocationErrorWidget, ret);

    if(nameWidget != null){
      PersonName personName = nameWidget.getValue(context, request);
      if(!StringUtils.hasText(personName.getGivenName()) || !StringUtils.hasText(personName.getFamilyName())){
        ret.add(new FormSubmissionError(context.getFieldName(nameErrorWidget), Context.getMessageSourceService().getMessage("htmlformentry.error.name.required")));
      }
    }
   
    if (ageWidget != null && validateMandatoryField(context, request, ageWidget, ageErrorWidget, ageOrBirthdDateErrorMessage)) {
      try {
        Number value = (Number) ageWidget.getValue(context, request);
      }
      catch (Exception e) {
        ret.add(new FormSubmissionError(context.getFieldName(ageErrorWidget), e.getMessage()));
      }
    }

    if (birthDateWidget != null
        && validateMandatoryField(context, request, birthDateWidget, birthDateErrorWidget, ageOrBirthdDateErrorMessage)) {
      try {
        if (birthDateWidget.getValue(context, request) != null
            && OpenmrsUtil.compare((Date) birthDateWidget.getValue(context, request), new Date()) > 0) {
          ret.add(new FormSubmissionError(context.getFieldName(birthDateErrorWidget), Context.getMessageSourceService().getMessage(
              "htmlformentry.error.cannotBeInFuture")));
        }
      }
      catch (Exception e) {
        ret.add(new FormSubmissionError(context.getFieldName(birthDateErrorWidget), e.getMessage()));
      }
    }

    if (ageWidget != null && birthDateWidget != null) {
      if (ageOrBirthdDateErrorMessage.size() > 1) {
        ret.add(new FormSubmissionError(context.getFieldName(ageErrorWidget), Context.getMessageSourceService().getMessage(
            "Person.birthdate.required")));
      }
    }
    else {
      ret.addAll(ageOrBirthdDateErrorMessage);
    }

    if (identifierTypeWidget != null && identifierTypeValueWidget != null) {
      String identifierTypeId = (String) identifierTypeWidget.getValue(context, request);
      String identifierValue = (String) identifierTypeValueWidget.getValue(context, request);
      if(StringUtils.hasText(identifierValue)){
        try {
          validateIdentifier(Integer.getInteger(identifierTypeId), identifierValue);
        }
        catch (Exception e) {
          ret.add(new FormSubmissionError(context.getFieldName(identifierTypeValueErrorWidget), e.getMessage()));
        }
      }
    }

    return ret;
View Full Code Here

          throw new Exception("htmlformentry.error.required");
        }
      }
    }
    catch (Exception ex) {
      ret.add(new FormSubmissionError(context.getFieldName(errorWidget), Context.getMessageSourceService().getMessage(ex.getMessage())));
      return false;
    }

    return true;
  }
View Full Code Here

        List<FormSubmissionError> ret = new ArrayList<FormSubmissionError>();
        Object value = null;
        try {
            value = valueWidget.getValue(context, submission);
        } catch (Exception ex) {
            ret.add(new FormSubmissionError(valueWidget, ex.getMessage()));
        }

        if (required) {
            if (value == null) {
                ret.add(new FormSubmissionError(valueWidget, Context.getMessageSourceService().getMessage("htmlformentry.error.required")));
            } else if (value instanceof String) {
                String valueStr = (String) value;
                if (StringUtils.isEmpty(valueStr)) {
                    ret.add(new FormSubmissionError(valueWidget, Context.getMessageSourceService().getMessage("htmlformentry.error.required")));
                }
            }
        }
       
        return ret;
View Full Code Here

        if (dateWidget != null) {
            exitDate = dateWidget.getValue(context, submission);
            if (exitDate != null) {
                if (OpenmrsUtil.compare(exitDate, new Date()) > 0) {
                    ret.add(new FormSubmissionError(context.getFieldName(dateErrorWidget), Context.getMessageSourceService()
                            .getMessage("htmlformentry.error.cannotBeInFuture")));

                }
            }

            if (obsList != null && obsList.size() == 0) {
                if (exitDate == null) {
                    if (reasonForExitWidget != null &&
                            HtmlFormEntryUtil.convertToType(reasonForExitWidget.getValue(context, submission).toString().trim(), Concept.class) != null) {
                        ret.add(new FormSubmissionError(context.getFieldName(dateErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.required")));
                    }
                }
            }
        }

        if (reasonForExitWidget != null) {
            Object value = reasonForExitWidget.getValue(context, submission);
            exitReasonAnswerConcept = (Concept) HtmlFormEntryUtil.convertToType(value.toString().trim(), Concept.class);
            if (obsList != null && obsList.size() == 0) {
                if (exitReasonAnswerConcept == null) {
                    if (dateWidget != null && dateWidget.getValue(context, submission) != null) {
                        ret.add(new FormSubmissionError(context.getFieldName(reasonForExitErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.required")));
                    }
                } else if (exitReasonAnswerConcept != null && exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
                    if (causeOfDeathWidget == null ||
                            HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) == null) {
                        ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.required")));
                    }
                } else if (exitReasonAnswerConcept != null && !exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
                    if (causeOfDeathWidget != null &&
                            HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) != null) {
                        ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.cannotEnterAValue")));
                    }
                }
            }
        }

        if (causeOfDeathWidget != null) {
            Object value = causeOfDeathWidget.getValue(context, submission);
            causeOfDeathAnswerConcept = (Concept) HtmlFormEntryUtil.convertToType(value.toString().trim(), Concept.class);
            String valueString = otherReasonWidget.getValue(context, submission);

            if (obsDeath != null && obsDeath.size() == 0) {
                if (causeOfDeathAnswerConcept == null) {
                    if (otherReasonWidget != null && !valueString.equals("")) {
                        ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.cannotEnterAValue")));
                    }
                } else if (causeOfDeathAnswerConcept != null && causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
                    if (otherReasonWidget == null || valueString.equals("")) {
                        ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.required")));
                    }
                } else if (causeOfDeathAnswerConcept != null && !causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
                    if (otherReasonWidget != null && !valueString.equals("")) {
                        ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.cannotEnterAValue")));
                    }
                }
            }
        }

        // this validation is added to avoid user resetting the 'exit from care'
        if (obsList != null && obsList.size() == 1) {
            if (exitDate == null) {
                ret.add(new FormSubmissionError(context.getFieldName(dateErrorWidget), Context.getMessageSourceService()
                        .getMessage("htmlformentry.error.required")));
            } else if (exitReasonAnswerConcept == null) {
                ret.add(new FormSubmissionError(context.getFieldName(reasonForExitErrorWidget), Context.getMessageSourceService()
                        .getMessage("htmlformentry.error.required")));
            } else if (exitReasonAnswerConcept != null && exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
                if (causeOfDeathWidget == null ||
                        HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) == null) {
                    ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
                            .getMessage("htmlformentry.error.required")));
                }
            } else if (exitReasonAnswerConcept != null && !exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
                if (causeOfDeathWidget != null &&
                        HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) != null) {
                    ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
                            .getMessage("htmlformentry.error.cannotEnterAValue")));
                }
            }
        }

        // this validation is added to avoid user resetting the 'patient died' incident
        String valueString = otherReasonWidget.getValue(context, submission);

        if (obsDeath != null && obsDeath.size() == 1) {
            if (causeOfDeathAnswerConcept != null && causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
                if (otherReasonWidget == null || valueString.equals("")) {
                    ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
                            .getMessage("htmlformentry.error.required")));
                }
            } else if (causeOfDeathAnswerConcept != null && !causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
                if (otherReasonWidget != null && !valueString.equals("")) {
                    ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
                            .getMessage("htmlformentry.error.cannotEnterAValue")));
                }
            }
        }
View Full Code Here

          Date dateCreated = startDateWidget.getValue(context, submission);
          if (dateCreated == null)
            throw new Exception("htmlformentry.error.required");
        }
      } catch (Exception ex) {
        ret.add(new FormSubmissionError(context
            .getFieldName(startDateErrorWidget), Context
            .getMessageSourceService().getMessage(ex.getMessage())));
      }
      try {
                if (startDateWidget != null && discontinuedDateWidget != null) {
                    Date startDate = startDateWidget.getValue(context, submission);
                    Date endDate = discontinuedDateWidget.getValue(context, submission);
                    if (startDate != null && endDate != null
                            && startDate.getTime() > endDate.getTime())
                        throw new Exception("htmlformentry.error.discontinuedDateBeforeStartDate");
                }
            } catch (Exception ex) {
                ret.add(new FormSubmissionError(context
                        .getFieldName(discontinuedDateErrorWidget), Context
                        .getMessageSourceService().getMessage(ex.getMessage())));
            }
            try {
                if (discontinuedReasonWidget != null && discontinuedDateWidget != null) {
                    String discReason = (String) discontinuedReasonWidget.getValue(context, submission);
                    Date endDate = discontinuedDateWidget.getValue(context, submission);
                    if (endDate == null && !StringUtils.isEmpty(discReason))
                        throw new Exception("htmlformentry.error.discontinuedReasonEnteredWithoutDate");
                }
            } catch (Exception ex) {
                ret.add(new FormSubmissionError(context
                        .getFieldName(discontinuedReasonErrorWidget), Context
                        .getMessageSourceService().getMessage(ex.getMessage())));
            }
    }
   
View Full Code Here

                if (required && !relationshipWidget.isAllRelationshipsFullfilled() && (personStubWidget.getValue(context, submission) == null || personStubWidget.getValue(context, submission).toString().trim().length() == 0)) {
                    throw new Exception("htmlformentry.error.required");
                }
            }
        } catch (Exception ex) {
            ret.add(new FormSubmissionError(context
                    .getFieldName(personErrorWidget), Context
                    .getMessageSourceService().getMessage(ex.getMessage())));
        }

        return ret;
View Full Code Here

                    throw new Exception("htmlformentry.error.required");
                if (OpenmrsUtil.compare((Date) date, new Date()) > 0)
                    throw new Exception("htmlformentry.error.cannotBeInFuture");
            }
        } catch (Exception ex) {
            ret.add(new FormSubmissionError(context.getFieldName(dateErrorWidget), Context.getMessageSourceService()
                    .getMessage(ex.getMessage())));
        }

        try {
            if (providerWidget != null) {
                Object value = providerWidget.getValue(context, submission);
                Person provider = (Person) convertValueToProvider(value);
                if (provider == null)
                    throw new Exception("required");
            }
        } catch (Exception ex) {
            ret.add(new FormSubmissionError(context.getFieldName(providerErrorWidget), Context.getMessageSourceService()
                    .getMessage(ex.getMessage())));
        }

        try {
            if (locationWidget != null) {
                Object value = locationWidget.getValue(context, submission);
                Location location = (Location) HtmlFormEntryUtil.convertToType(value.toString().trim(), Location.class);
                if (location == null)
                    throw new Exception("required");
            }
        } catch (Exception ex) {
            ret.add(new FormSubmissionError(context.getFieldName(locationErrorWidget), Context.getMessageSourceService()
                    .getMessage(ex.getMessage())));
        }
        try {
            if (encounterTypeWidget != null) {
                Object encounterType = encounterTypeWidget.getValue(context, submission);
                if (encounterType == null)
                    throw new Exception("required");
            }
        } catch (Exception ex) {
            ret.add(new FormSubmissionError(context.getFieldName(encounterTypeErrorWidget), Context
                        .getMessageSourceService().getMessage(ex.getMessage())));
        }
        return ret;
    }
View Full Code Here

   
    try {
      value = valueWidget.getValue(context, submission);
    }
    catch (Exception ex) {
      ret.add(new FormSubmissionError(valueWidget, ex.getMessage()));
    }
   
    try {
      if (dateWidget != null)
        date = dateWidget.getValue(context, submission);
    }
    catch (Exception ex) {
      ret.add(new FormSubmissionError(dateWidget, ex.getMessage()));
    }
   
    if (value == null && date != null)
      ret.add(new FormSubmissionError(valueWidget, Context.getMessageSourceService().getMessage(
          "htmlformentry.error.dateWithoutValue")));
   
    if (date != null && OpenmrsUtil.compare((Date) date, new Date()) > 0)
      ret.add(new FormSubmissionError(dateWidget, Context.getMessageSourceService().getMessage(
          "htmlformentry.error.cannotBeInFuture")));
   
    if (value instanceof Date && !allowFutureDates && OpenmrsUtil.compare((Date) value, new Date()) > 0) {
      ret.add(new FormSubmissionError(valueWidget, Context.getMessageSourceService().getMessage(
          "htmlformentry.error.cannotBeInFuture")));
    }
   
    if (required) {
      if (value == null) {
        ret.add(new FormSubmissionError(valueWidget, Context.getMessageSourceService().getMessage(
            "htmlformentry.error.required")));
      } else if (value instanceof String) {
        String valueStr = (String) value;
        if (StringUtils.isEmpty(valueStr)) {
          ret.add(new FormSubmissionError(valueWidget, Context.getMessageSourceService().getMessage(
              "htmlformentry.error.required")));
        }
      }
    }
   
View Full Code Here

TOP

Related Classes of org.openmrs.module.htmlformentry.FormSubmissionError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.