org.hl7.fhir.dstu3.model.ValueSet Java Examples

The following examples show how to use org.hl7.fhir.dstu3.model.ValueSet. 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: SimpleWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public void seeResource(String url, Resource r) throws FHIRException {
   if (r instanceof StructureDefinition)
     seeProfile(url, (StructureDefinition) r);
   else if (r instanceof ValueSet)
     seeValueSet(url, (ValueSet) r);
   else if (r instanceof CodeSystem)
     seeCodeSystem(url, (CodeSystem) r);
   else if (r instanceof OperationDefinition)
     seeOperationDefinition(url, (OperationDefinition) r);
   else if (r instanceof ConceptMap)
     maps.put(((ConceptMap) r).getUrl(), (ConceptMap) r);
   else if (r instanceof StructureMap)
     transforms.put(((StructureMap) r).getUrl(), (StructureMap) r);
   else if (r instanceof NamingSystem)
   	systems.add((NamingSystem) r);
}
 
Example #2
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValidationResult verifyCodeExternal(ValueSet vs, Coding coding, boolean tryCache)
  throws Exception {
  ValidationResult res = vs == null ? null : handleByCache(vs, coding, tryCache);
  if (res != null) {
    return res;
  }
  Parameters pin = new Parameters();
  pin.addParameter().setName("coding").setValue(coding);
  if (vs != null) {
    pin.addParameter().setName("valueSet").setResource(vs);
  }
  res = serverValidateCode(pin, vs == null);
  if (vs != null) {
    Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
    cache.put(cacheId(coding), res);
  }
  return res;
}
 
Example #3
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValueSet intersectByExpansion(ValueSet lvs, ValueSet rvs) {
  // this is pretty straight forward - we intersect the lists, and build a compose out of the intersection
  ValueSet vs = new ValueSet();
  vs.setStatus(PublicationStatus.DRAFT);
  
  Map<String, ValueSetExpansionContainsComponent> left = new HashMap<String, ValueSetExpansionContainsComponent>();
  scan(lvs.getExpansion().getContains(), left);
  Map<String, ValueSetExpansionContainsComponent> right = new HashMap<String, ValueSetExpansionContainsComponent>();
  scan(rvs.getExpansion().getContains(), right);
  Map<String, ConceptSetComponent> inc = new HashMap<String, ConceptSetComponent>();
  
  for (String s : left.keySet()) {
    if (right.containsKey(s)) {
      ValueSetExpansionContainsComponent cc = left.get(s);
      ConceptSetComponent c = inc.get(cc.getSystem());
      if (c == null) {
        c = vs.getCompose().addInclude().setSystem(cc.getSystem());
        inc.put(cc.getSystem(), c);
      }
      c.addConcept().setCode(cc.getCode()).setDisplay(cc.getDisplay());
    }
  }
  return vs;
}
 
Example #4
Source File: CodeSystemUpdateProvider.java    From cqf-ruler with Apache License 2.0 6 votes vote down vote up
/***
 * Perform union of codes within a ValueSet and CodeSystem
 *
 * @param valueSetCodes The codes contained within a ValueSet
 * @param codeSystem A CodeSystem resource
 * @return List of distinct codes strings
 */
private List<String> getUnionDistinctCodes(ValueSet.ConceptSetComponent valueSetCodes, CodeSystem codeSystem)
{
    if (!codeSystem.hasConcept())
    {
        return valueSetCodes.getConcept().stream().map(ValueSet.ConceptReferenceComponent::getCode).collect(Collectors.toList());
    }
    return Stream.concat(
            valueSetCodes.getConcept().stream().map(
                    ValueSet.ConceptReferenceComponent::getCode).collect(Collectors.toList()
            ).stream(),
            codeSystem.getConcept().stream().map(
                    CodeSystem.ConceptDefinitionComponent::getCode).collect(Collectors.toList()
            ).stream()
    )
            .distinct()
            .collect(Collectors.toList());
}
 
Example #5
Source File: ShExGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValueSet resolveBindingReference(DomainResource ctxt, Type reference) {
  if (reference instanceof UriType) {
    return context.fetchResource(ValueSet.class, ((UriType) reference).getValue().toString());
  }
  else if (reference instanceof Reference) {
    String s = ((Reference) reference).getReference();
    if (s.startsWith("#")) {
      for (Resource c : ctxt.getContained()) {
        if (c.getId().equals(s.substring(1)) && (c instanceof ValueSet))
          return (ValueSet) c;
      }
      return null;
    } else {
      return context.fetchResource(ValueSet.class, ((Reference) reference).getReference());
    }
  }
  else
    return null;
}
 
Example #6
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
private String describeValidationParameters(Parameters pin) {
  CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
  for (ParametersParameterComponent p : pin.getParameter()) {
    if (p.hasValue() && p.getValue() instanceof PrimitiveType) {
      b.append(p.getName() + "=" + ((PrimitiveType) p.getValue()).asStringValue());
    } else if (p.hasValue() && p.getValue() instanceof Coding) {
      b.append("system=" + ((Coding) p.getValue()).getSystem());
      b.append("code=" + ((Coding) p.getValue()).getCode());
      b.append("display=" + ((Coding) p.getValue()).getDisplay());
    } else if (p.hasValue() && p.getValue() instanceof CodeableConcept) {
      if (((CodeableConcept) p.getValue()).hasCoding()) {
        Coding c = ((CodeableConcept) p.getValue()).getCodingFirstRep();
        b.append("system=" + c.getSystem());
        b.append("code=" + c.getCode());
        b.append("display=" + c.getDisplay());
      } else if (((CodeableConcept) p.getValue()).hasText()) {
        b.append("text=" + ((CodeableConcept) p.getValue()).getText());
      }
    } else if (p.hasResource() && (p.getResource() instanceof ValueSet)) {
      b.append("valueset=" + getVSSummary((ValueSet) p.getResource()));
    }
  }
  return b.toString();
}
 
Example #7
Source File: ValueSetUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static void markStatus(ValueSet vs, String wg, String status, String fmm) {
  if (wg != null) {
    if (!ToolingExtensions.hasExtension(vs, ToolingExtensions.EXT_WORKGROUP) || 
        (Utilities.existsInList(ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP), "fhir", "vocab") && !Utilities.existsInList(wg, "fhir", "vocab"))) {
      ToolingExtensions.setCodeExtension(vs, ToolingExtensions.EXT_WORKGROUP, wg);
    }
  }
  if (status != null) {
    String ss = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_BALLOT_STATUS);
    if (Utilities.noString(ss) || ssval(ss) < ssval(status)) 
      ToolingExtensions.setStringExtension(vs, ToolingExtensions.EXT_BALLOT_STATUS, status);
  }
  if (fmm != null) {
    String sfmm = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_FMM_LEVEL);
    if (Utilities.noString(sfmm) || Integer.parseInt(sfmm) < Integer.parseInt(fmm)) 
      ToolingExtensions.setIntegerExtension(vs, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(fmm));
  }
  if (vs.hasUserData("cs"))
    CodeSystemUtilities.markStatus((CodeSystem) vs.getUserData("cs"), wg, status, fmm);
}
 
Example #8
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validateCode(String system, String code, String display, ValueSet vs) {
  try {
    if (system == null && display == null) {
      return verifyCodeInternal(vs, code);
    }
    if ((codeSystems.containsKey(system) && codeSystems.get(system) != null) || vs
      .hasExpansion()) {
      return verifyCodeInternal(vs, system, code, display);
    } else {
      return verifyCodeExternal(vs,
        new Coding().setSystem(system).setCode(code).setDisplay(display), true);
    }
  } catch (Exception e) {
    return new ValidationResult(IssueSeverity.FATAL,
      "Error validating code \"" + code + "\" in system \"" + system + "\": " + e.getMessage(),
      TerminologyServiceErrorClass.SERVER_ERROR);
  }
}
 
Example #9
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public ValueSetExpansionOutcome expandOnServer(ValueSet vs, String fn) throws Exception {
  if (noTerminologyServer) {
    return new ValueSetExpansionOutcome(
      "Error expanding ValueSet: running without terminology services",
      TerminologyServiceErrorClass.NOSERVICE);
  }
  if (expProfile == null) {
    throw new Exception("No ExpansionProfile provided");
  }

  try {
    Map<String, String> params = new HashMap<String, String>();
    params.put("_limit", Integer.toString(expandCodesLimit));
    params.put("_incomplete", "true");
    tlog("Terminology Server: $expand on " + getVSSummary(vs));
    ValueSet result = txServer.expandValueset(vs, expProfile.setIncludeDefinition(false), params);
    return new ValueSetExpansionOutcome(result);
  } catch (Exception e) {
    return new ValueSetExpansionOutcome(
      "Error expanding ValueSet \"" + vs.getUrl() + ": " + e.getMessage(),
      TerminologyServiceErrorClass.UNKNOWN);
  }
}
 
Example #10
Source File: ValueSetsTest.java    From bunsen with Apache License 2.0 6 votes vote down vote up
private static void checkValueSet(ValueSet valueSet, String url, String version) {

    Assert.assertNotNull(
        MessageFormat.format("Could not find value set for url {0} and version {1}", url, version),
        valueSet);

    Assert.assertEquals(url, valueSet.getUrl());
    Assert.assertEquals(version, valueSet.getVersion());

    ConceptSetComponent inclusion = valueSet.getCompose().getIncludeFirstRep();

    Assert.assertEquals("urn:cerner:system", inclusion.getSystem());
    Assert.assertEquals("1", inclusion.getVersion());
    Assert.assertEquals("a", inclusion.getConceptFirstRep().getCode());

    Assert.assertEquals(1, valueSet.getCompose().getInclude().size());
  }
 
Example #11
Source File: ISO21090Importer.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void generateValueSet(EnumValueSet evs) throws Exception {
  ValueSet bvs = ctxt.fetchResource(ValueSet.class, evs.template);
  if (bvs == null)
    throw new Exception("Did not find template value set "+evs.template);
  ValueSet vs = bvs.copy();
  vs.getCompose().getInclude().clear();
  vs.getIdentifier().clear();
  vs.setName("ISO 20190 "+evs.name+" Enumeration");
  vs.setId(evs.name);
  vs.setUrl("http://hl7.org/fhir/iso21090/ValueSet/"+vs.getId());
  vs.setDate(new Date());
  vs.setExperimental(false);
  ConceptSetComponent inc = vs.getCompose().addInclude().setSystem(evs.system);
  for (String code : evs.codes) {
    inc.addConcept().setCode(code);
  }
  new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("c:\\temp\\iso21090\\ValueSet-"+evs.name+".xml"), vs);
}
 
Example #12
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 #13
Source File: ValueSetExpansionCache.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void loadCache() throws FHIRFormatError, IOException {
 File[] files = new File(cacheFolder).listFiles();
  for (File f : files) {
    if (f.getName().endsWith(".xml")) {
      final FileInputStream is = new FileInputStream(f);
      try {	   
      Resource r = context.newXmlParser().setOutputStyle(OutputStyle.PRETTY).parse(is);
      if (r instanceof OperationOutcome) {
        OperationOutcome oo = (OperationOutcome) r;
        expansions.put(ToolingExtensions.getExtension(oo,VS_ID_EXT).getValue().toString(),
          new ValueSetExpansionOutcome(new XhtmlComposer(XhtmlComposer.XML).composePlainText(oo.getText().getDiv()), TerminologyServiceErrorClass.UNKNOWN));
      } else {
        ValueSet vs = (ValueSet) r; 
        expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs));
      }
      } finally {
        IOUtils.closeQuietly(is);
      }
    }
  }
}
 
Example #14
Source File: ValueSetsTest.java    From bunsen with Apache License 2.0 6 votes vote down vote up
@Test
public void testAppendValueSets() {
  ValueSets original = ValueSets.getEmpty(spark)
      .withValueSets(valueSet("urn:cerner:valueset:valueset1", "1"),
          valueSet("urn:cerner:valueset:valueset2", "1"));

  ValueSets valueSets = original.withValueSets(valueSet("urn:cerner:valueset:valueset3", "1"));

  Assert.assertEquals(2, original.getValues().count());
  Assert.assertEquals(3, valueSets.getValues().count());

  ValueSet firstValueSet = valueSets.getValueSet("urn:cerner:valueset:valueset1", "1");
  checkValueSet(firstValueSet, "urn:cerner:valueset:valueset1", "1");

  ValueSet secondValueSet = valueSets.getValueSet("urn:cerner:valueset:valueset2", "1");
  checkValueSet(secondValueSet, "urn:cerner:valueset:valueset2", "1");

  ValueSet newValueSet = valueSets.getValueSet("urn:cerner:valueset:valueset3", "1");
  checkValueSet(newValueSet, "urn:cerner:valueset:valueset3", "1");
}
 
Example #15
Source File: CodeSystemUpdateProvider.java    From cqf-ruler with Apache License 2.0 6 votes vote down vote up
/***
 * Update existing CodeSystems with the codes in all ValueSet resources.
 * System level CodeSystem update operation
 *
 * @return FHIR OperationOutcome detailing the success or failure of the operation
 */
@Operation(name = "$updateCodeSystems", idempotent = true)
public OperationOutcome updateCodeSystems()
{
    IBundleProvider valuesets = this.valueSetDao.search(new SearchParameterMap());
    OperationOutcome response = new OperationOutcome();

    OperationOutcome outcome;
    for (IBaseResource valueSet : valuesets.getResources(0, valuesets.size()))
    {
        outcome = this.performCodeSystemUpdate((ValueSet) valueSet);
        if (outcome.hasIssue())
        {
            for (OperationOutcome.OperationOutcomeIssueComponent issue : outcome.getIssue())
            {
                response.addIssue(issue);
            }
        }
    }

    return response;
}
 
Example #16
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ValidationResult verifyCodeInternal(ValueSet vs, CodeableConcept code) throws Exception {
  for (Coding c : code.getCoding()) {
    ValidationResult res = verifyCodeInternal(vs, c.getSystem(), c.getCode(), c.getDisplay());
    if (res.isOk()) {
      return res;
    }
  }
  if (code.getCoding().isEmpty()) {
    return new ValidationResult(IssueSeverity.ERROR, "None code provided");
  } else {
    return new ValidationResult(IssueSeverity.ERROR,
      "None of the codes are in the specified value set");
  }
}
 
Example #17
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void dropValueSet(String id) {
  ValueSet vs = valueSets.get(id);
  valueSets.remove(id);
  if (vs != null) {
    valueSets.remove(vs.getUrl());
  }
}
 
Example #18
Source File: ShExGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public ShExGenerator(IWorkerContext context) {
  super();
  this.context = context;
  innerTypes = new HashSet<Pair<StructureDefinition, ElementDefinition>>();
  emittedInnerTypes = new HashSet<Pair<StructureDefinition, ElementDefinition>>();
  datatypes = new HashSet<String>();
  emittedDatatypes = new HashSet<String>();
  references = new HashSet<String>();
  required_value_sets = new HashSet<ValueSet>();
  known_resources = new HashSet<String>();
}
 
Example #19
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean IsNotFixedExpansion(ValueSet vs) {
  if (vs.hasCompose())
    return false;


  // it's not fixed if it has any includes that are not version fixed
  for (ConceptSetComponent cc : vs.getCompose().getInclude()) {
    if (cc.hasValueSet())
      return true;
    if (!cc.hasVersion())
      return true;
  }
  return false;
}
 
Example #20
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean checkDoSystem(ValueSet vs, ValueSet src) {
  if (src != null)
    vs = src;
  if (vs.hasCompose())
    return true;
  return false;
}
 
Example #21
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean notcomplete(ValueSet vs) {
  if (!vs.hasExpansion()) {
    return true;
  }
  if (!vs.getExpansion()
    .getExtensionsByUrl("http://hl7.org/fhir/StructureDefinition/valueset-unclosed").isEmpty()) {
    return true;
  }
  if (!vs.getExpansion()
    .getExtensionsByUrl("http://hl7.org/fhir/StructureDefinition/valueset-toocostly").isEmpty()) {
    return true;
  }
  return false;
}
 
Example #22
Source File: ShExGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private String genValueSet(ValueSet vs) {
  ST vsd = tmplt(VALUE_SET_DEFINITION).add("vsuri", vsprefix(vs.getUrl())).add("comment", vs.getDescription());
  ValueSetExpander.ValueSetExpansionOutcome vse = context.expandVS(vs, true, false);
  List<String> valid_codes = new ArrayList<String>();
  if(vse != null &&
          vse.getValueset() != null &&
          vse.getValueset().hasExpansion() &&
          vse.getValueset().getExpansion().hasContains()) {
    for(ValueSet.ValueSetExpansionContainsComponent vsec : vse.getValueset().getExpansion().getContains())
      valid_codes.add("\"" + vsec.getCode() + "\"");
  }
  return vsd.add("val_list", valid_codes.size() > 0? " [" + StringUtils.join(valid_codes, " ") + ']' : " EXTERNAL").render();
}
 
Example #23
Source File: ValueSetsTest.java    From bunsen with Apache License 2.0 5 votes vote down vote up
@Test
public void testValueSetsIncludesNoConcepts() {

  ValueSets valueSets = ValueSets.getEmpty(spark)
      .withValueSets(valueSet("urn:cerner:valueset:valueset1", "1"),
          valueSet("urn:cerner:valueset:valueset2", "1"));

  valueSets.getValueSets()
      .collectAsList()
      .forEach(row -> ((ValueSet) valueSetRowConverter.rowToResource(row)).getCompose()
          .getInclude()
          .forEach(inclusion -> Assert.assertTrue(inclusion.getConcept().isEmpty())));
}
 
Example #24
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void generate(ResourceContext rcontext, ValueSet vs, ValueSet src, boolean header) throws FHIRException, IOException {
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  boolean hasExtensions;
  if (vs.hasExpansion()) {
    // for now, we just accept an expansion if there is one
    hasExtensions = generateExpansion(x, vs, src, header);
  } else {
    hasExtensions = generateComposition(rcontext, x, vs, header);
  }
  inject(vs, x, hasExtensions ? NarrativeStatus.EXTENSIONS :  NarrativeStatus.GENERATED);
}
 
Example #25
Source File: ValueSetsTest.java    From bunsen with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithValueSetsFromDirectoryXml() {

  ValueSets valueSets = ValueSets.getEmpty(spark)
      .withValueSetsFromDirectory("src/test/resources/xml/valuesets");

  ValueSet marriedValueSet = valueSets.getValueSet(
      "urn:cerner:bunsen:valueset:married_maritalstatus",
      "0.0.1");

  Assert.assertNotNull(marriedValueSet);
  Assert.assertEquals("urn:cerner:bunsen:valueset:married_maritalstatus",
      marriedValueSet.getUrl());
  Assert.assertEquals("0.0.1", marriedValueSet.getVersion());
}
 
Example #26
Source File: QuestionnaireBuilder.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ValueSet makeTypeList(StructureDefinition profile, List<TypeRefComponent> types, String path) {
  ValueSet vs = new ValueSet();
  vs.setName("Type options for "+path);
  vs.setDescription(vs.getName());
 vs.setStatus(PublicationStatus.ACTIVE);
  vs.setExpansion(new ValueSetExpansionComponent());
  vs.getExpansion().setIdentifier(Factory.createUUID());
  vs.getExpansion().setTimestampElement(DateTimeType.now());
  for (TypeRefComponent t : types) {
    ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
   if (t.getCode().equals("Reference") && (t.hasTargetProfile() && t.getTargetProfile().startsWith("http://hl7.org/fhir/StructureDefinition/"))) { 
     cc.setCode(t.getTargetProfile().substring(40));
      cc.setSystem("http://hl7.org/fhir/resource-types");
     cc.setDisplay(cc.getCode());
    } else {
      ProfileUtilities pu = new ProfileUtilities(context, null, null);
      StructureDefinition ps = null;
      if (t.hasTargetProfile()) 
        ps = pu.getProfile(profile, t.getTargetProfile());
      else if (t.hasProfile()) 
        ps = pu.getProfile(profile, t.getProfile());
      
      if (ps != null) {
       cc.setCode(t.getTargetProfile());
        cc.setDisplay(ps.getType());
        cc.setSystem("http://hl7.org/fhir/resource-types");
      } else {
       cc.setCode(t.getCode());
       cc.setDisplay(t.getCode());
        cc.setSystem("http://hl7.org/fhir/data-types");
      }
    }
   t.setUserData("text", cc.getCode());
  }

  return vs;
}
 
Example #27
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #28
Source File: QuestionnaireBuilder.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void addCodeQuestions(QuestionnaireItemComponent group, ElementDefinition element, String path, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups) throws FHIRException {
  ToolingExtensions.addFhirType(group, "code");
  ValueSet vs = resolveValueSet(null, element.hasBinding() ? element.getBinding() : null);
  addQuestion(group, QuestionnaireItemType.CHOICE, path, "value", unCamelCase(tail(element.getPath())), answerGroups, vs);
  group.setText(null);
  for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups)
    ag.setText(null);
}
 
Example #29
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean generateDefinition(XhtmlNode x, CodeSystem cs, boolean header) throws FHIRFormatError, DefinitionException, IOException {
    boolean hasExtensions = false;
    Map<ConceptMap, String> mymaps = new HashMap<ConceptMap, String>();
//    for (ConceptMap a : context.findMapsForSource(cs.getValueSet())) {
//      String url = "";
//      ValueSet vsr = context.fetchResource(ValueSet.class, ((Reference) a.getTarget()).getReference());
//      if (vsr != null)
//        url = (String) vsr.getUserData("filename");
//      mymaps.put(a, url);
//    }
    // also, look in the contained resources for a concept map
    for (Resource r : cs.getContained()) {
      if (r instanceof ConceptMap) {
        ConceptMap cm = (ConceptMap) r;
        if (((Reference) cm.getSource()).getReference().equals(cs.getValueSet())) {
          String url = "";
          ValueSet vsr = context.fetchResource(ValueSet.class, ((Reference) cm.getTarget()).getReference());
          if (vsr != null)
              url = (String) vsr.getUserData("filename");
        mymaps.put(cm, url);
        }
      }
    }
    List<String> langs = new ArrayList<String>();

    if (header) {
      XhtmlNode h = x.h2();
      h.addText(cs.hasTitle() ? cs.getTitle() : cs.getName());
      addMarkdown(x, cs.getDescription());
      if (cs.hasCopyright())
        generateCopyright(x, cs);
    }

    generateProperties(x, cs);
    generateFilters(x, cs);
    hasExtensions = generateCodeSystemContent(x, cs, hasExtensions, mymaps, langs);

    return hasExtensions;
  }
 
Example #30
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void seeValueSet(String url, ValueSet vs) throws Exception {
  if (valueSets.containsKey(vs.getUrl()) && !allowLoadingDuplicates) {
    throw new Exception("Duplicate value set " + vs.getUrl());
  }
  valueSets.put(vs.getId(), vs);
  valueSets.put(url, vs);
  valueSets.put(vs.getUrl(), vs);
}