Exemplo n.º 1
0
 protected Validator createDataElementInFormDefinitionValidator() {
   ValidatorFormDefinitionContainsDataElement v = new ValidatorFormDefinitionContainsDataElement();
   String elemCui =
       DetService.SINGLETON
           .getDataElementTaxonomy()
           .getDataElement(getDataElement().getCuiOrSystemName())
           .getCui();
   v.setValue(elemCui);
   v.setFormDefinition(getFormDefinition());
   return v;
 }
Exemplo n.º 2
0
  protected Validator createDataElementValuesValidator() {
    DetValueSet standardValues =
        DetService.SINGLETON.getDataElementTaxonomy().getSystemStandardValues();
    ValidatorCollectionProceeding validator = new ValidatorCollectionProceeding();

    DetDataElement deMetadata =
        DetService.SINGLETON
            .getDataElementTaxonomy()
            .getDataElement(getDataElement().getCuiOrSystemName());

    ValidatorElementValues multiValuedValidator = new ValidatorElementValues();
    // extract the PropertyDisplayName from the Form Def or DET
    multiValuedValidator.setPropertyDisplayName(
        KcUtils.getDescription(getDataElement(), getFormDefinition()));
    multiValuedValidator.setElement(getDataElement());
    multiValuedValidator.setElementMetadata(deMetadata);
    validator.addValidator(multiValuedValidator);

    // for each value of the DataElem we need to check that value provided is usable
    DataElementValue[] devs = getDataElement().getDataElementValues();
    for (int i = 0; i < devs.length; i++) {
      DataElementValue dev = devs[i];
      ValidatorCollectionProceeding v = new ValidatorCollectionProceeding();
      ElementValidatorContext context = new ElementValidatorContext();
      // extract the PropertyDisplayName from the Form Def or DET
      context.setPropertyDisplayName(KcUtils.getDescription(getDataElement(), getFormDefinition()));
      context.setDataElement(getDataElement());
      context.setElementValue(dev);
      context.setElementMetadata(deMetadata);
      v.setValidatorContext(context);

      // validate value conforms to the format of its datatype and can be converted
      v.addValidator(
          new ValidatorElementValue(),
          new ValidatorInput[] {
            new ValidatorInput("elementValue", "elementValue"),
            new ValidatorInput("elementMetadata", "elementMetadata"),
            new ValidatorInput("propertyDisplayName", "propertyDisplayName")
          });

      // Validate note length.
      ValidatorStringLength vNote = new ValidatorStringLength();
      vNote.setMaxLength(4000);
      vNote.addValidatorErrorListener(
          new ValidatorErrorListener() {
            public boolean validatorError(Validator v, String errorKey) {
              ValidatorStringLength v1 = (ValidatorStringLength) v;
              v1.addErrorMessage("errors.cirNoteLength", "4000");
              return true;
            }
          },
          ValidatorStringLength.ERROR_KEY_TOO_LONG);
      v.addValidator(
          vNote,
          new ValidatorInput[] {
            new ValidatorInput("value", "dataElement.valueNote"),
            new ValidatorInput("propertyDisplayName", "propertyDisplayName")
          });

      // validate use of "See Note"
      if (standardValues.containsValue(dev.getValue())) {
        v.addValidator(
            new ValidatorSeeNote(),
            new ValidatorInput[] {
              new ValidatorInput("cui", "elementValue.value"),
              new ValidatorInput("seeNoteCui", "seeNoteCui"),
              new ValidatorInput("valueNote", "dataElement.valueNote"),
              new ValidatorInput("propertyDisplayName", "propertyDisplayName")
            });
      }

      // validate use of ADE
      if (dev.getAde() != null) {
        v.addValidator(
            new ValidatorAde(),
            new ValidatorInput[] {
              new ValidatorInput("dataElementValue", "elementValue"),
              new ValidatorInput("dataElementMetadata", "elementMetadata")
            });
      }

      validator.addValidator(v);
    }
    return validator;
  }