Java Code Examples for org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity#WARNING

The following examples show how to use org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity#WARNING . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CareConnectProfileValidationSupport.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay) {
  CodeSystem cs = fetchCodeSystem(theContext, theCodeSystem);
  logD("CareConnect validateCode system = "+ theCodeSystem);

  if (cs != null) {
    boolean caseSensitive = true;
    if (cs.hasCaseSensitive()) {
      caseSensitive = cs.getCaseSensitive();
    }

    CodeValidationResult retVal = testIfConceptIsInList(theCode, cs.getConcept(), caseSensitive);

    if (retVal != null) {
      return retVal;
    }
  }

  return new CodeValidationResult(IssueSeverity.WARNING, "CareConnect Unknown code: " + theCodeSystem + " / " + theCode);
}
 
Example 2
Source File: SNOMEDUKMockValidationSupport.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay) {
  CodeSystem cs = fetchCodeSystem(theContext, theCodeSystem);
  logD("SNOMEDMOCK validateCode system = "+ theCodeSystem);

  if (cs != null) {
    boolean caseSensitive = true;
    if (cs.hasCaseSensitive()) {
      caseSensitive = cs.getCaseSensitive();
    }

    CodeValidationResult retVal = testIfConceptIsInList(theCode, cs.getConcept(), caseSensitive);

    if (retVal != null) {
      return retVal;
    }
  }

  return new CodeValidationResult(IssueSeverity.WARNING, "SNOMEDMOCK Unknown code: " + theCodeSystem + " / " + theCode);
}
 
Example 3
Source File: CareConnectProfileValidationSupport.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay) {
  CodeSystem cs = fetchCodeSystem(theContext, theCodeSystem);
  logD("CareConnect validateCode system = "+ theCodeSystem);

  if (cs != null) {
    boolean caseSensitive = true;
    if (cs.hasCaseSensitive()) {
      caseSensitive = cs.getCaseSensitive();
    }

    CodeValidationResult retVal = testIfConceptIsInList(theCode, cs.getConcept(), caseSensitive);

    if (retVal != null) {
      return retVal;
    }
  }

  return new CodeValidationResult(IssueSeverity.WARNING, "CareConnect Unknown code: " + theCodeSystem + " / " + theCode);
}
 
Example 4
Source File: DefaultProfileValidationSupportStu3AsR4.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext r4Context, String theCodeSystem, String theCode, String theDisplay) {
    CodeSystem cs = fetchCodeSystem(r4Context, theCodeSystem);
    if (cs != null) {
        boolean caseSensitive = true;
        if (cs.hasCaseSensitive()) {
            caseSensitive = cs.getCaseSensitive();
        }

        CodeValidationResult retVal = testIfConceptIsInList(theCode, cs.getConcept(), caseSensitive);

        if (retVal != null) {
            return retVal;
        }
    }

    return new CodeValidationResult(IssueSeverity.WARNING, "Unknown code: " + theCodeSystem + " / " + theCode);
}
 
Example 5
Source File: SNOMEDUKMockValidationSupport.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay) {
  CodeSystem cs = fetchCodeSystem(theContext, theCodeSystem);
  logD("SNOMEDMOCK validateCode system = "+ theCodeSystem);

  if (cs != null) {
    boolean caseSensitive = true;
    if (cs.hasCaseSensitive()) {
      caseSensitive = cs.getCaseSensitive();
    }

    CodeValidationResult retVal = testIfConceptIsInList(theCode, cs.getConcept(), caseSensitive);

    if (retVal != null) {
      return retVal;
    }
  }

  return new CodeValidationResult(IssueSeverity.WARNING, "SNOMEDMOCK Unknown code: " + theCodeSystem + " / " + theCode);
}
 
Example 6
Source File: SNOMEDUKDbValidationSupportSTU3.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay) {
  CodeSystem cs = fetchCodeSystem(theContext, theCodeSystem);
  logD("SNOMEDValidator validateCode system = "+ theCodeSystem);

  if (cs != null) {
    boolean caseSensitive = true;
    if (cs.hasCaseSensitive()) {
      caseSensitive = cs.getCaseSensitive();
    }

    CodeValidationResult retVal = testIfConceptIsInList(theCode, cs.getConcept(), caseSensitive);

    if (retVal != null) {
      return retVal;
    }
  }

  return new CodeValidationResult(IssueSeverity.WARNING, "SNOMEDValidator Unknown code: " + theCodeSystem + " / " + theCode);
}
 
Example 7
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValidationResult verifyCodeInExpansion(ValueSet vs, String system, String code,
  String display) {
  ValueSetExpansionContainsComponent cc = findCode(vs.getExpansion().getContains(), code);
  if (cc == null) {
    return new ValidationResult(IssueSeverity.ERROR,
      "Unknown Code " + code + " in " + vs.getUrl());
  }
  if (display == null) {
    return new ValidationResult(
      new ConceptDefinitionComponent().setCode(code).setDisplay(cc.getDisplay()));
  }
  if (cc.hasDisplay()) {
    if (display.equalsIgnoreCase(cc.getDisplay())) {
      return new ValidationResult(
        new ConceptDefinitionComponent().setCode(code).setDisplay(cc.getDisplay()));
    }
    return new ValidationResult(IssueSeverity.WARNING,
      "Display Name for " + code + " must be '" + cc.getDisplay() + "'",
      new ConceptDefinitionComponent().setCode(code).setDisplay(cc.getDisplay()));
  }
  return null;
}
 
Example 8
Source File: CareConnectProfileDbValidationSupportSTU3.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay) {
  CodeSystem cs = fetchCodeSystem(theContext, theCodeSystem);
  logD("CareConnect validateCode system = "+ theCodeSystem);

  if (cs != null) {
    boolean caseSensitive = true;
    if (cs.hasCaseSensitive()) {
      caseSensitive = cs.getCaseSensitive();
    }

    CodeValidationResult retVal = testIfConceptIsInList(theCode, cs.getConcept(), caseSensitive);

    if (retVal != null) {
      return retVal;
    }
  }

  return new CodeValidationResult(IssueSeverity.WARNING, "CareConnect Unknown code: " + theCodeSystem + " / " + theCode);
}
 
Example 9
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static IssueSeverity mapSeverity(org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity severity) {
  switch (severity) {
  case ERROR: return IssueSeverity.ERROR;
  case FATAL: return IssueSeverity.FATAL;
  case INFORMATION: return IssueSeverity.INFORMATION;
  case WARNING: return IssueSeverity.WARNING;
  default: return null;
  }
}
 
Example 10
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public String getWarningCount() {
  int c = 0;
  for (ValidationMessage vm : messages)
    if (vm.getLevel() == IssueSeverity.WARNING)
      c++;
  return Integer.toString(c);
}
 
Example 11
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ValidationResult verifyCodeInCodeSystem(CodeSystem cs, String system, String code,
  String display) throws Exception {
  ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code);
  if (cc == null) {
    if (cs.getContent().equals(CodeSystem.CodeSystemContentMode.COMPLETE)) {
      return new ValidationResult(IssueSeverity.ERROR,
        "Unknown Code " + code + " in " + cs.getUrl());
    } else if (!cs.getContent().equals(CodeSystem.CodeSystemContentMode.NOTPRESENT)) {
      return new ValidationResult(IssueSeverity.WARNING,
        "Unknown Code " + code + " in partial code list of " + cs.getUrl());
    } else {
      return verifyCodeExternal(null,
        new Coding().setSystem(system).setCode(code).setDisplay(display), false);
    }
  }
  //
  //        return new ValidationResult(IssueSeverity.WARNING, "A definition was found for "+cs.getUrl()+", but it has no codes in the definition");
  //      return new ValidationResult(IssueSeverity.ERROR, "Unknown Code "+code+" in "+cs.getUrl());
  if (display == null) {
    return new ValidationResult(cc);
  }
  CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
  if (cc.hasDisplay()) {
    b.append(cc.getDisplay());
    if (display.equalsIgnoreCase(cc.getDisplay())) {
      return new ValidationResult(cc);
    }
  }
  for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
    b.append(ds.getValue());
    if (display.equalsIgnoreCase(ds.getValue())) {
      return new ValidationResult(cc);
    }
  }
  return new ValidationResult(IssueSeverity.WARNING,
    "Display Name for " + code + " must be one of '" + b.toString() + "'", cc);
}
 
Example 12
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void saveToCache(ValidationResult res, String cacheName) throws IOException {
  if (cacheName == null) {
    return;
  }
  if (res.getDisplay() != null) {
    TextFile.stringToFile(res.getDisplay(), cacheName);
  } else if (res.getMessage() != null) {
    if (res.getSeverity() == IssueSeverity.WARNING) {
      TextFile.stringToFile("!warning: " + res.getMessage(), cacheName);
    } else {
      TextFile.stringToFile("!error: " + res.getMessage(), cacheName);
    }
  }
}
 
Example 13
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public String getWarningCount() {
  int c = 0;
  for (ValidationMessage vm : messages)
    if (vm.getLevel() == IssueSeverity.WARNING)
      c++;
  return Integer.toString(c);
}
 
Example 14
Source File: BaseValidator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Test a rule and add a {@link IssueSeverity#WARNING} validation message if the validation fails
 * 
 * @param thePass
 *          Set this parameter to <code>false</code> if the validation does not pass
 * @return Returns <code>thePass</code> (in other words, returns <code>true</code> if the rule did not fail validation)
 */
protected boolean warning(List<ValidationMessage> errors, IssueType type, int line, int col, String path, boolean thePass, String msg, Object... theMessageArguments) {
  if (!thePass) {
    String nmsg = context.formatMessage(msg, theMessageArguments);
    IssueSeverity severity = IssueSeverity.WARNING;
    addValidationMessage(errors, type, line, col, path, nmsg, severity, msg);
  }
  return thePass;

}
 
Example 15
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static IssueSeverity mapSeverity(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity severity) {
  switch (severity) {
  case ERROR: return IssueSeverity.ERROR;
  case FATAL: return IssueSeverity.FATAL;
  case INFORMATION: return IssueSeverity.INFORMATION;
  case WARNING: return IssueSeverity.WARNING;
  default: return null;
  }
}
 
Example 16
Source File: ValueSetCheckerSimple.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public ValidationResult validateCode(Coding code) throws FHIRException {
  String warningMessage = null;
  // first, we validate the concept itself
  
  String system = code.hasSystem() ? code.getSystem() : getValueSetSystem();
  if (system == null && !code.hasDisplay()) { // dealing with just a plain code (enum)
    system = systemForCodeInValueSet(code.getCode());
  }
  if (!code.hasSystem())
    code.setSystem(system);
  boolean inExpansion = checkExpansion(code);
  CodeSystem cs = context.fetchCodeSystem(system);
  if (cs == null) {
    warningMessage = "Unable to resolve system "+system+" - system is not specified or implicit";
    if (!inExpansion)
      throw new FHIRException(warningMessage);
  }
  if (cs!=null && cs.getContent() != CodeSystemContentMode.COMPLETE) {
    warningMessage = "Unable to resolve system "+system+" - system is not complete";
    if (!inExpansion)
      throw new FHIRException(warningMessage);
  }
  
  ValidationResult res =null;
  if (cs!=null)
    res = validateCode(code, cs);
    
  // then, if we have a value set, we check it's in the value set
  if ((res==null || res.isOk()) && valueset != null && !codeInValueSet(system, code.getCode())) {
    if (!inExpansion)
      res.setMessage("Not in value set "+valueset.getUrl()).setSeverity(IssueSeverity.ERROR);
    else if (warningMessage!=null)
      res = new ValidationResult(IssueSeverity.WARNING, "Code found in expansion, however: " + warningMessage);
    else
      res.setMessage("Code found in expansion, however: " + res.getMessage());
  }
  return res;
}
 
Example 17
Source File: IWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public boolean isOk() {
  return severity == null || severity == IssueSeverity.INFORMATION || severity == IssueSeverity.WARNING;
}
 
Example 18
Source File: IWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public boolean isOk() {
  return severity == null || severity == IssueSeverity.INFORMATION || severity == IssueSeverity.WARNING;
}
 
Example 19
Source File: ValueSetCheckerSimple.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public ValidationResult validateCode(Coding code) throws FHIRException {
  String warningMessage = null;
  // first, we validate the concept itself

  ValidationResult res =null;
  boolean inExpansion = false;
  String system = code.hasSystem() ? code.getSystem() : getValueSetSystem();
  if (options.getValueSetMode() != ValueSetMode.CHECK_MEMERSHIP_ONLY) {
    if (system == null && !code.hasDisplay()) { // dealing with just a plain code (enum)
      system = systemForCodeInValueSet(code.getCode());
    }
    if (!code.hasSystem()) {
      if (options.isGuessSystem() && system == null && Utilities.isAbsoluteUrl(code.getCode())) {
        system = "urn:ietf:rfc:3986"; // this arises when using URIs bound to value sets
      }
      code.setSystem(system);
    }
    inExpansion = checkExpansion(code);
    CodeSystem cs = context.fetchCodeSystem(system);
    if (cs == null) {
      cs = findSpecialCodeSystem(system);
    }
    if (cs == null) {
      warningMessage = "Unable to resolve system "+system;
      if (!inExpansion)
        throw new FHIRException(warningMessage);
    }
    if (cs!=null && cs.getContent() != CodeSystemContentMode.COMPLETE) {
      warningMessage = "Unable to resolve system "+system+" - system is not complete";
      if (!inExpansion && cs.getContent() != CodeSystemContentMode.FRAGMENT) // we're going to give it a go if it's a fragment
        throw new FHIRException(warningMessage);
    }

    if (cs!=null) {
      res = validateCode(code, cs);
    } else {
      // it's in the expansion, but we could find it in a code system
      res = findCodeInExpansion(code);
    }
  } else {
    inExpansion = checkExpansion(code);
  }

  // then, if we have a value set, we check it's in the value set
  if (valueset != null && options.getValueSetMode() != ValueSetMode.NO_MEMBERSHIP_CHECK) {
    if ((res==null || res.isOk()) && !codeInValueSet(system, code.getCode())) {
      if (!inExpansion)
        res.setMessage("Not in value set "+valueset.getUrl()).setSeverity(IssueSeverity.ERROR);
      else if (warningMessage!=null)
        res = new ValidationResult(IssueSeverity.WARNING, context.formatMessage(I18nConstants.CODE_FOUND_IN_EXPANSION_HOWEVER_, warningMessage));
      else
        res.setMessage("Code found in expansion, however: " + res.getMessage());
    }
  }
  return res;
}
 
Example 20
Source File: ValidationSupportSTU3.java    From synthea with Apache License 2.0 4 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem,
    String theCode, String theDisplay, String theValueSetUrl) {
  IssueSeverity severity = IssueSeverity.WARNING;
  String message = "Unsupported CodeSystem";

  if (isCodeSystemSupported(theContext, theCodeSystem)) {
    severity = IssueSeverity.ERROR;
    message = "Code not found";

    CodeSystem cs = codeSystemMap.get(theCodeSystem);
    for (ConceptDefinitionComponent def : cs.getConcept()) {
      if (def.getCode().equals(theCode)) {
        if (def.getDisplay() != null && theDisplay != null) {
          if (def.getDisplay().equals(theDisplay)) {
            severity = IssueSeverity.INFORMATION;
            message = "Validated Successfully";
          } else {
            severity = IssueSeverity.WARNING;
            message = "Validated Code; Display mismatch";
          }
        } else {
          severity = IssueSeverity.WARNING;
          message = "Validated Code; No display";
        }
      }
    }
  }

  ValueSet vs = fetchValueSet(theContext, theValueSetUrl);
  if (vs != null && vs.hasCompose() && vs.getCompose().hasExclude()) {
    for (ConceptSetComponent exclude : vs.getCompose().getExclude()) {
      if (exclude.getSystem().equals(theCodeSystem) && exclude.hasConcept()) {
        for (ConceptReferenceComponent concept : exclude.getConcept()) {
          if (concept.getCode().equals(theCode)) {
            severity = IssueSeverity.ERROR;
            message += "; Code Excluded from ValueSet";
          }
        }
      }
    }
  }

  return new CodeValidationResult(severity, message);
}