@Override public ValueSetExpansionComponent expandValueSet(FhirContext theCtx, ConceptSetComponent theInclude) { for (IValidationSupport next : myChain) { if (isNotBlank(theInclude.getSystem())) { if (next.isCodeSystemSupported(theCtx, theInclude.getSystem())) { return next.expandValueSet(theCtx, theInclude); } } for (UriType nextValueSet : theInclude.getValueSet()) { ValueSetExpansionComponent retVal = next.expandValueSet(theCtx, theInclude); if (retVal != null && retVal.getContains().size() > 0) { return retVal; } } } return myChain.get(0).expandValueSet(theCtx, theInclude); }
@Override public ValueSetExpansionComponent expandValueSet(FhirContext theContext, ConceptSetComponent theInclude) { ValueSetExpansionComponent retVal = new ValueSetExpansionComponent(); Set<String> wantCodes = new HashSet<>(); for (ConceptReferenceComponent next : theInclude.getConcept()) { wantCodes.add(next.getCode()); } CodeSystem system = fetchCodeSystem(theContext, theInclude.getSystem()); if (system != null) { List<ConceptDefinitionComponent> concepts = system.getConcept(); addConcepts(theInclude, retVal, wantCodes, concepts); } for (UriType next: theInclude.getValueSet()) { ValueSet vs = myValueSets.get(defaultString(next.getValueAsString())); if (vs != null) { for (ConceptSetComponent nextInclude : vs.getCompose().getInclude()) { ValueSetExpansionComponent contents = expandValueSet(theContext, nextInclude); retVal.getContains().addAll(contents.getContains()); } } } return retVal; }
private void addConcepts(ConceptSetComponent theInclude, ValueSetExpansionComponent theRetVal, Set<String> theWantCodes, List<ConceptDefinitionComponent> theConcepts) { for (ConceptDefinitionComponent next : theConcepts) { if (theWantCodes.isEmpty() || theWantCodes.contains(next.getCode())) { theRetVal .addContains() .setSystem(theInclude.getSystem()) .setCode(next.getCode()) .setDisplay(next.getDisplay()); } addConcepts(theInclude, theRetVal, theWantCodes, next.getConcept()); } }
private boolean inComponent(ConceptSetComponent vsi, String system, String code) throws Exception { if (vsi.hasSystem() && !vsi.getSystem().equals(system)) return false;
private ValueSet doExpand(ValueSet theSource) { validateIncludes("include", theSource.getCompose().getInclude()); validateIncludes("exclude", theSource.getCompose().getExclude()); /* * If all of the code systems are supported by the HAPI FHIR terminology service, let's * use that as it's more efficient. */ boolean allSystemsAreSuppportedByTerminologyService = true; for (ConceptSetComponent next : theSource.getCompose().getInclude()) { if (!myTerminologySvc.supportsSystem(next.getSystem())) { allSystemsAreSuppportedByTerminologyService = false; } } for (ConceptSetComponent next : theSource.getCompose().getExclude()) { if (!myTerminologySvc.supportsSystem(next.getSystem())) { allSystemsAreSuppportedByTerminologyService = false; } } if (allSystemsAreSuppportedByTerminologyService) { return (ValueSet) myTerminologySvc.expandValueSet(theSource); } HapiWorkerContext workerContext = new HapiWorkerContext(getContext(), myValidationSupport); ValueSetExpansionOutcome outcome = workerContext.expand(theSource, null); ValueSet retVal = outcome.getValueset(); retVal.setStatus(PublicationStatus.ACTIVE); return retVal; }
@Override public ValueSetExpansionComponent expandValueSet(FhirContext theContext, ConceptSetComponent theInclude) { ValueSetExpansionComponent retVal = new ValueSetExpansionComponent(); Set<String> wantCodes = new HashSet<>(); for (ConceptReferenceComponent next : theInclude.getConcept()) { wantCodes.add(next.getCode()); } CodeSystem system = fetchCodeSystem(theContext, theInclude.getSystem()); if (system != null) { List<ConceptDefinitionComponent> concepts = system.getConcept(); addConcepts(theInclude, retVal, wantCodes, concepts); } for (UriType next: theInclude.getValueSet()) { ValueSet vs = myValueSets.get(defaultString(next.getValueAsString())); if (vs != null) { for (ConceptSetComponent nextInclude : vs.getCompose().getInclude()) { ValueSetExpansionComponent contents = expandValueSet(theContext, nextInclude); retVal.getContains().addAll(contents.getContains()); } } } return retVal; }
private void excludeCodes(ConceptSetComponent exc, List<ValueSetExpansionParameterComponent> params) throws TerminologyServiceException { if (exc.hasSystem() && exc.getConcept().size() == 0 && exc.getFilter().size() == 0) { excludeSystems.add(exc.getSystem()); } if (exc.hasValueSet()) throw new Error("Processing Value set references in exclude is not yet done"); // importValueSet(imp.getValue(), params, profile); CodeSystem cs = context.fetchCodeSystem(exc.getSystem()); if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(exc.getSystem())) { excludeCodes(context.expandVS(exc, false), params); return; } for (ConceptReferenceComponent c : exc.getConcept()) { excludeCode(exc.getSystem(), c.getCode()); } if (exc.getFilter().size() > 0) throw new NotImplementedException("not done yet"); }
@Override public ValueSetExpansionComponent expandValueSet(FhirContext theCtx, ConceptSetComponent theInclude) { for (IValidationSupport next : myChain) { if (isNotBlank(theInclude.getSystem())) { if (next.isCodeSystemSupported(theCtx, theInclude.getSystem())) { return next.expandValueSet(theCtx, theInclude); } } for (UriType nextValueSet : theInclude.getValueSet()) { ValueSetExpansionComponent retVal = next.expandValueSet(theCtx, theInclude); if (retVal != null && retVal.getContains().size() > 0) { return retVal; } } } return myChain.get(0).expandValueSet(theCtx, theInclude); }
public org.hl7.fhir.instance.model.ValueSet.ValueSetComposeComponent convertValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent src, String noSystem) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.ValueSet.ValueSetComposeComponent tgt = new org.hl7.fhir.instance.model.ValueSet.ValueSetComposeComponent(); copyElement(src, tgt); for (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent t : src.getInclude()) { for (org.hl7.fhir.dstu3.model.UriType ti : t.getValueSet()) tgt.addImport(ti.getValue()); if (noSystem == null || !t.getSystem().equals(noSystem)) tgt.addInclude(convertConceptSetComponent(t)); } for (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent t : src.getExclude()) tgt.addExclude(convertConceptSetComponent(t)); return tgt; }
private static Iterator<Value> expandValuesIterator(ValueSet valueSet) { List<Value> values = new ArrayList<>(); ValueSetComposeComponent compose = valueSet.getCompose(); for (ConceptSetComponent inclusion: compose.getInclude()) { for (ConceptReferenceComponent concept: inclusion.getConcept()) { Value value = new Value(); value.setValueSetUri(valueSet.getUrl()); value.setValueSetVersion(valueSet.getVersion()); value.setSystem(inclusion.getSystem()); value.setVersion(inclusion.getVersion()); value.setValue(concept.getCode()); values.add(value); } } return values.iterator(); }
public static org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent convertConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent tgt = new org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent(); copyElement(src, tgt); tgt.setSystem(src.getSystem()); if (src.hasVersion()) tgt.setVersion(src.getVersion()); for (org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent t : src.getConcept()) tgt.addConcept(convertConceptReferenceComponent(t)); for (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent t : src.getFilter()) tgt.addFilter(convertConceptSetFilterComponent(t)); return tgt; }
public org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent convertConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent tgt = new org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent(); copyElement(src, tgt); tgt.setSystem(src.getSystem()); tgt.setVersion(src.getVersion()); for (org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent t : src.getConcept()) tgt.addConcept(convertConceptReferenceComponent(t)); for (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent t : src.getFilter()) tgt.addFilter(convertConceptSetFilterComponent(t)); return tgt; }
private void addConcepts(ConceptSetComponent theInclude, ValueSetExpansionComponent theRetVal, Set<String> theWantCodes, List<ConceptDefinitionComponent> theConcepts) { for (ConceptDefinitionComponent next : theConcepts) { if (theWantCodes.isEmpty() || theWantCodes.contains(next.getCode())) { theRetVal .addContains() .setSystem(theInclude.getSystem()) .setCode(next.getCode()) .setDisplay(next.getDisplay()); } addConcepts(theInclude, theRetVal, theWantCodes, next.getConcept()); } }
private void validateIncludes(String name, List<ConceptSetComponent> listToValidate) { for (ConceptSetComponent nextExclude : listToValidate) { if (isBlank(nextExclude.getSystem()) && !ElementUtil.isEmpty(nextExclude.getConcept(), nextExclude.getFilter())) { throw new InvalidRequestException("ValueSet contains " + name + " criteria with no system defined"); } } }
private ValueSet doExpand(ValueSet theSource) { validateIncludes("include", theSource.getCompose().getInclude()); validateIncludes("exclude", theSource.getCompose().getExclude()); /* * If all of the code systems are supported by the HAPI FHIR terminology service, let's * use that as it's more efficient. */ boolean allSystemsAreSuppportedByTerminologyService = true; for (ConceptSetComponent next : theSource.getCompose().getInclude()) { if (!myTerminologySvc.supportsSystem(next.getSystem())) { allSystemsAreSuppportedByTerminologyService = false; } } for (ConceptSetComponent next : theSource.getCompose().getExclude()) { if (!myTerminologySvc.supportsSystem(next.getSystem())) { allSystemsAreSuppportedByTerminologyService = false; } } if (allSystemsAreSuppportedByTerminologyService) { return (ValueSet) myTerminologySvc.expandValueSet(theSource); } HapiWorkerContext workerContext = new HapiWorkerContext(getContext(), myValidationSupport); ValueSetExpansionOutcome outcome = workerContext.expand(theSource, null); ValueSet retVal = outcome.getValueset(); retVal.setStatus(PublicationStatus.ACTIVE); return retVal; }
public static org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent convertConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent tgt = new org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent(); copyElement(src, tgt); tgt.setSystem(src.getSystem()); if (src.hasVersion()) tgt.setVersion(src.getVersion()); for (org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent t : src.getConcept()) tgt.addConcept(convertConceptReferenceComponent(t)); for (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent t : src.getFilter()) tgt.addFilter(convertConceptSetFilterComponent(t)); return tgt; }
public org.hl7.fhir.instance.model.ValueSet.ValueSetComposeComponent convertValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent src, String noSystem) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.ValueSet.ValueSetComposeComponent tgt = new org.hl7.fhir.instance.model.ValueSet.ValueSetComposeComponent(); copyElement(src, tgt); for (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent t : src.getInclude()) { for (org.hl7.fhir.dstu3.model.UriType ti : t.getValueSet()) tgt.addImport(ti.getValue()); if (noSystem == null || !t.getSystem().equals(noSystem)) tgt.addInclude(convertConceptSetComponent(t)); } for (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent t : src.getExclude()) tgt.addExclude(convertConceptSetComponent(t)); return tgt; }
public org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent convertConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent tgt = new org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent(); copyElement(src, tgt); tgt.setSystem(src.getSystem()); tgt.setVersion(src.getVersion()); for (org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent t : src.getConcept()) tgt.addConcept(convertConceptReferenceComponent(t)); for (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent t : src.getFilter()) tgt.addFilter(convertConceptSetFilterComponent(t)); return tgt; }
private void validateIncludes(String name, List<ConceptSetComponent> listToValidate) { for (ConceptSetComponent nextExclude : listToValidate) { if (isBlank(nextExclude.getSystem()) && !ElementUtil.isEmpty(nextExclude.getConcept(), nextExclude.getFilter())) { throw new InvalidRequestException("ValueSet contains " + name + " criteria with no system defined"); } } }