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

The following examples show how to use org.hl7.fhir.dstu3.model.ValueSet. These examples are extracted from open source projects. 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 Project: org.hl7.fhir.core   Source File: ISO21090Importer.java    License: 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 2
Source Project: bunsen   Source File: ValueSetsTest.java    License: 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 3
Source Project: org.hl7.fhir.core   Source File: ValueSetExpansionCache.java    License: 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 4
Source Project: org.hl7.fhir.core   Source File: ValueSetUtilities.java    License: 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 5
Source Project: cqf-ruler   Source File: CodeSystemUpdateProvider.java    License: 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 6
Source Project: org.hl7.fhir.core   Source File: ProfileComparer.java    License: 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 7
Source Project: org.hl7.fhir.core   Source File: ShExGenerator.java    License: 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 8
Source Project: bunsen   Source File: ValueSetsTest.java    License: 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 9
Source Project: org.hl7.fhir.core   Source File: BaseWorkerContext.java    License: 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 Project: org.hl7.fhir.core   Source File: BaseWorkerContext.java    License: 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 11
Source Project: org.hl7.fhir.core   Source File: BaseWorkerContext.java    License: 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 12
Source Project: org.hl7.fhir.core   Source File: BaseWorkerContext.java    License: 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 13
Source Project: org.hl7.fhir.core   Source File: BaseWorkerContext.java    License: 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 14
Source Project: cqf-ruler   Source File: CodeSystemUpdateProvider.java    License: 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 15
Source Project: org.hl7.fhir.core   Source File: SimpleWorkerContext.java    License: 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 16
Source Project: bunsen   Source File: ValueSetsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithValueSetsFromDirectoryJson() {

  ValueSets valueSets = ValueSets.getEmpty(spark)
      .withValueSetsFromDirectory("src/test/resources/json/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 17
Source Project: org.hl7.fhir.core   Source File: R2ToR3Loader.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void handleCodeSystem(CodeSystem cs, ValueSet vs) {
  cs.setId(vs.getId());
  cs.setValueSet(vs.getUrl());
  cslist.add(cs);
  
}
 
Example 18
Source Project: cqf-ruler   Source File: CodeSystemUpdateProvider.java    License: Apache License 2.0 5 votes vote down vote up
public OperationOutcome performCodeSystemUpdate(ValueSet vs)
{
    OperationOutcomeBuilder responseBuilder = new OperationOutcomeBuilder();

    List<String> codeSystems = new ArrayList<>();
    if (vs.hasCompose() && vs.getCompose().hasInclude())
    {
        CodeSystem codeSystem;
        for (ValueSet.ConceptSetComponent csc : vs.getCompose().getInclude())
        {
            if (!csc.hasSystem()) continue;

            codeSystem = getCodeSystemByUrl(csc.getSystem());

            if (!csc.hasConcept()) continue;

            updateCodeSystem(
                    codeSystem.setUrl(csc.getSystem()),
                    getUnionDistinctCodes(csc, codeSystem)
            );

            codeSystems.add(codeSystem.getUrl());
        }
    }

    return responseBuilder.buildIssue(
            "information",
            "informational",
            "Successfully updated the following CodeSystems: " + String.join(", ", codeSystems)
    ).build();
}
 
Example 19
Source Project: org.hl7.fhir.core   Source File: ValueSetExpander.java    License: Apache License 2.0 5 votes vote down vote up
public ValueSetExpansionOutcome(ValueSet valueset, String error, TerminologyServiceErrorClass errorClass) {
  super();
  this.valueset = valueset;
  this.service = null;
  this.error = error;
  this.errorClass = errorClass;
}
 
Example 20
Source Project: cqf-ruler   Source File: CodeSystemUpdateProvider.java    License: Apache License 2.0 5 votes vote down vote up
/***
 * Update existing CodeSystems with the codes in the specified ValueSet.
 *
 * This is for development environment purposes to enable ValueSet expansion and validation
 * without complete CodeSystems.
 *
 * @param theId the id of the ValueSet
 * @return FHIR OperationOutcome detailing the success or failure of the operation
 */
@Operation(name = "$updateCodeSystems", idempotent = true, type = ValueSet.class)
public OperationOutcome updateCodeSystems(@IdParam IdType theId)
{
    ValueSet vs = this.valueSetDao.read(theId);

    OperationOutcomeBuilder responseBuilder = new OperationOutcomeBuilder();
    if (vs == null)
    {
        return responseBuilder.buildIssue("error", "notfound", "Unable to find Resource: " + theId.getId()).build();
    }

    return performCodeSystemUpdate(vs);
}
 
Example 21
Source Project: synthea   Source File: ValidationSupportSTU3.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Loads the structure definitions from the given directory.
 * @param rootDir the directory to load structure definitions from
 * @return a list of structure definitions
 * @throws Throwable when there is an error reading the structure definitions.
 */
private void loadFromDirectory(String rootDir) throws Throwable {

  IParser jsonParser = FhirContext.forDstu3().newJsonParser();
  jsonParser.setParserErrorHandler(new StrictErrorHandler());

  URL profilesFolder = ClassLoader.getSystemClassLoader().getResource(rootDir);
  Path path = Paths.get(profilesFolder.toURI());
  Files.walk(path, Integer.MAX_VALUE).filter(Files::isReadable).filter(Files::isRegularFile)
      .filter(p -> p.toString().endsWith(".json")).forEach(f -> {
        try {
          IBaseResource resource = jsonParser.parseResource(new FileReader(f.toFile()));
          resources.add(resource);
          if (resource instanceof CodeSystem) {
            CodeSystem cs = (CodeSystem) resource;
            resourcesMap.put(cs.getUrl(), cs);
            codeSystemMap.put(cs.getUrl(), cs);
          } else if (resource instanceof ValueSet) {
            ValueSet vs = (ValueSet) resource;
            resourcesMap.put(vs.getUrl(), vs);
          } else if (resource instanceof StructureDefinition) {
            StructureDefinition sd = (StructureDefinition) resource;
            resourcesMap.put(sd.getUrl(), sd);
            definitions.add(sd);
            definitionsMap.put(sd.getUrl(), sd);
          }
        } catch (FileNotFoundException e) {
          throw new RuntimeException(e);
        }
      });
}
 
Example 22
Source Project: org.hl7.fhir.core   Source File: ValueSetUtilities.java    License: Apache License 2.0 5 votes vote down vote up
public static String getOID(ValueSet vs) {
  for (Identifier id : vs.getIdentifier()) {
    if ("urn:ietf:rfc:3986".equals(id.getSystem()) && id.hasValue() && id.getValue().startsWith("urn:oid:"))
      return id.getValue().substring(8);
  }
  return null;
}
 
Example 23
Source Project: org.hl7.fhir.core   Source File: ProfileComparer.java    License: Apache License 2.0 5 votes vote down vote up
private ValueSet resolveVS(StructureDefinition ctxtLeft, Type vsRef) {
  if (vsRef == null)
    return null;
  if (vsRef instanceof UriType)
    return null;
  else {
    Reference ref = (Reference) vsRef;
    if (!ref.hasReference())
      return null;
    return context.fetchResource(ValueSet.class, ref.getReference());
  }
}
 
Example 24
Source Project: org.hl7.fhir.core   Source File: ShExGenerator.java    License: 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 25
Source Project: org.hl7.fhir.core   Source File: ShExGenerator.java    License: 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 26
Source Project: bunsen   Source File: ValueSetsTest.java    License: 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 27
Source Project: org.hl7.fhir.core   Source File: QuestionnaireBuilder.java    License: 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 28
Source Project: org.hl7.fhir.core   Source File: QuestionnaireBuilder.java    License: 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 Project: org.hl7.fhir.core   Source File: NarrativeGenerator.java    License: 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 Project: org.hl7.fhir.core   Source File: NarrativeGenerator.java    License: 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);
}