Ejemplo n.º 1
0
 private ValidationResult verifyCodeInternal(ValueSet vs, String code)
     throws FileNotFoundException, ETooCostly, IOException, FHIRException {
   if (vs.hasExpansion()) return verifyCodeInExpansion(vs, code);
   else {
     ValueSetExpansionOutcome vse = expansionCache.getExpander().expand(vs, null);
     if (vse.getValueset() == null)
       return new ValidationResult(IssueSeverity.ERROR, vse.getError(), vse.getErrorClass());
     else return verifyCodeInExpansion(vse.getValueset(), code);
   }
 }
Ejemplo n.º 2
0
 private ValidationResult verifyCodeInternal(
     ValueSet vs, String system, String code, String display) throws Exception {
   if (vs.hasExpansion()) return verifyCodeInExpansion(vs, system, code, display);
   else {
     ValueSetExpansionOutcome vse = expansionCache.getExpander().expand(vs, null);
     if (vse.getValueset() != null)
       return verifyCodeExternal(
           vs, new Coding().setSystem(system).setCode(code).setDisplay(display), false);
     else return verifyCodeInExpansion(vse.getValueset(), system, code, display);
   }
 }
Ejemplo n.º 3
0
 @Override
 public ValueSetExpansionComponent expandVS(ConceptSetComponent inc, boolean heirachical)
     throws TerminologyServiceException {
   ValueSet vs = new ValueSet();
   vs.setCompose(new ValueSetComposeComponent());
   vs.getCompose().getInclude().add(inc);
   ValueSetExpansionOutcome vse = expandVS(vs, true, heirachical);
   ValueSet valueset = vse.getValueset();
   if (valueset == null)
     throw new TerminologyServiceException("Error Expanding ValueSet: " + vse.getError());
   return valueset.getExpansion();
 }
  private ValueSet doExpand(ValueSet theSource) {

    validateIncludes("include", theSource.getCompose().getInclude());
    validateIncludes("exclude", theSource.getCompose().getExclude());

    HapiWorkerContext workerContext = new HapiWorkerContext(getContext(), myValidationSupport);

    ValueSetExpansionOutcome outcome = workerContext.expand(theSource);
    ValueSetExpansionComponent expansion = outcome.getValueset().getExpansion();

    ValueSet retVal = new ValueSet();
    retVal.getMeta().setLastUpdated(new Date());
    retVal.setExpansion(expansion);
    return retVal;
  }
Ejemplo n.º 5
0
  private ValidationResult handleByCache(ValueSet vs, Coding coding, boolean tryCache) {
    String cacheId = cacheId(coding);
    Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
    if (cache == null) {
      cache = new HashMap<String, IWorkerContext.ValidationResult>();
      validationCache.put(vs.getUrl(), cache);
    }
    if (cache.containsKey(cacheId)) return cache.get(cacheId);
    if (!tryCache) return null;
    if (!cacheValidation) return null;
    if (failed.contains(vs.getUrl())) return null;
    ValueSetExpansionOutcome vse = expandVS(vs, true, false);
    if (vse.getValueset() == null || notcomplete(vse.getValueset())) {
      failed.add(vs.getUrl());
      return null;
    }

    ValidationResult res = validateCode(coding, vse.getValueset());
    cache.put(cacheId, res);
    return res;
  }
Ejemplo n.º 6
0
 @Override
 public ValidationResult validateCode(CodeableConcept code, ValueSet vs) {
   try {
     if (vs.hasExpansion()) return verifyCodeInternal(vs, code);
     else {
       // we'll try expanding first; if that doesn't work, then we'll just pass it to the server to
       // validate
       // ... could be a problem if the server doesn't have the code systems we have locally, so we
       // try not to depend on the server
       try {
         ValueSetExpansionOutcome vse = expandVS(vs, true, false);
         if (vse.getValueset() != null) return verifyCodeInternal(vse.getValueset(), code);
       } catch (Exception e) {
         // failed? we'll just try the server
       }
       return verifyCodeExternal(vs, code, true);
     }
   } catch (Exception e) {
     return new ValidationResult(
         IssueSeverity.FATAL,
         "Error validating code \"" + code.toString() + "\": " + e.getMessage(),
         TerminologyServiceErrorClass.SERVER_ERROR);
   }
 }
Ejemplo n.º 7
0
 @Override
 public ValueSetExpansionOutcome expandVS(ValueSet vs, boolean cacheOk, boolean heirarchical) {
   try {
     if (vs.hasExpansion()) {
       return new ValueSetExpansionOutcome(vs.copy());
     }
     String cacheFn = null;
     if (cache != null) {
       cacheFn = Utilities.path(cache, determineCacheId(vs, heirarchical) + ".json");
       if (new File(cacheFn).exists()) return loadFromCache(vs.copy(), cacheFn);
     }
     if (cacheOk && vs.hasUrl()) {
       if (expProfile == null) throw new Exception("No ExpansionProfile provided");
       ValueSetExpansionOutcome vse =
           expansionCache.getExpander().expand(vs, expProfile.setExcludeNested(!heirarchical));
       if (vse.getValueset() != null) {
         if (cache != null) {
           FileOutputStream s = new FileOutputStream(cacheFn);
           newJsonParser().compose(new FileOutputStream(cacheFn), vse.getValueset());
           s.close();
         }
       }
       return vse;
     } else {
       ValueSetExpansionOutcome res = expandOnServer(vs, cacheFn);
       if (cacheFn != null) {
         if (res.getValueset() != null) {
           saveToCache(res.getValueset(), cacheFn);
         } else {
           OperationOutcome oo = new OperationOutcome();
           oo.addIssue().getDetails().setText(res.getError());
           saveToCache(oo, cacheFn);
         }
       }
       return res;
     }
   } catch (NoTerminologyServiceException e) {
     return new ValueSetExpansionOutcome(
         e.getMessage() == null ? e.getClass().getName() : e.getMessage(),
         TerminologyServiceErrorClass.NOSERVICE);
   } catch (Exception e) {
     return new ValueSetExpansionOutcome(
         e.getMessage() == null ? e.getClass().getName() : e.getMessage(),
         TerminologyServiceErrorClass.UNKNOWN);
   }
 }