@Override public Base setProperty(String name, Base value) throws FHIRException { if (name.equals("system")) { this.system = castToUri(value); // UriType } else if (name.equals("version")) { this.version = castToString(value); // StringType } else if (name.equals("concept")) { this.getConcept().add((ConceptReferenceComponent) value); } else if (name.equals("filter")) { this.getFilter().add((ConceptSetFilterComponent) value); } else if (name.equals("valueSet")) { this.getValueSet().add(castToUri(value)); } else return super.setProperty(name, value); return value; }
@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; }
/** * @return The first repetition of repeating field {@link #concept}, creating it if it does not already exist */ public ConceptReferenceComponent getConceptFirstRep() { if (getConcept().isEmpty()) { addConcept(); } return getConcept().get(0); }
private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params, ExpansionProfile profile) throws ETooCostly, FileNotFoundException, IOException, FHIRException { List<ValueSet> imports = new ArrayList<ValueSet>(); for (UriType imp : inc.getValueSet()) imports.add(importValueSet(imp.getValue(), params, profile)); if (!inc.hasSystem()) { if (imports.isEmpty()) // though this is not supposed to be the case return; copyImportContains(base.getExpansion().getContains(), null, profile, imports); } else { CodeSystem cs = context.fetchCodeSystem(inc.getSystem()); if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(inc.getSystem())) { addCodes(context.expandVS(inc, canBeHeirarchy), params, profile, imports); return; throw new NoTerminologyServiceException("unable to find code system " + inc.getSystem().toString()); else throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString()); throw new TerminologyServiceException("Code system " + inc.getSystem().toString() + " is incomplete"); if (cs.hasVersion()) if (!existsInParams(params, "version", new UriType(cs.getUrl() + "|" + cs.getVersion()))) params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "|" + cs.getVersion()))); if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) { addCodeAndDescendents(cs, inc.getSystem(), def, null, profile, imports); if (!inc.getConcept().isEmpty()) {
if (isBlank(theSystem) || theSystem.equals(next.getSystem())) { for (ConceptReferenceComponent nextCode : next.getConcept()) { if (theCode.equals(nextCode.getCode())) { CodeType code = new CodeType(theCode); ValueSet expansion = new ValueSet(); for (ConceptSetComponent nextInclude : theVs.getCompose().getInclude()) { for (ConceptReferenceComponent nextConcept : nextInclude.getConcept()) { expansion.getExpansion().addContains().setCode(nextConcept.getCode()).setDisplay(nextConcept.getDisplay());
|| !value.getSystem().equals(currentInclusion.getSystem()) || !value.getVersion().equals(currentInclusion.getVersion())) { if (value.getSystem().equals(candidate.getSystem()) && value.getVersion().equals(candidate.getVersion())) { currentInclusion.setConcept(new ArrayList<>(currentInclusion.getConcept())); currentInclusion.setSystem(value.getSystem()); currentInclusion.setVersion(value.getVersion()); concept = currentInclusion.addConcept(); concept.setCode(value.getValue());
ConceptSetComponent inclusionWithoutConcepts = inclusion.copy(); inclusionWithoutConcepts.setConcept(new ArrayList<>()); updatedInclusions.add(inclusionWithoutConcepts);
private boolean inComponent(ConceptSetComponent vsi, String system, String code) throws Exception { if (vsi.hasSystem() && !vsi.getSystem().equals(system)) return false; for (UriType uri : vsi.getValueSet()) { if (!inImport(uri.getValue(), system, code)) return false; if (!vsi.hasSystem()) return false; for (ConceptReferenceComponent cc : vsi.getConcept()) if (cc.getCode().equals(code)) { return true; if (!def.getCaseSensitive()) { for (ConceptReferenceComponent cc : vsi.getConcept()) if (cc.getCode().equalsIgnoreCase(code)) { return false; if (vsi.getConcept().isEmpty() && vsi.getFilter().isEmpty()) { return codeInDefine(def.getConcept(), code, def.getCaseSensitive()); for (ConceptSetFilterComponent f: vsi.getFilter()) throw new Error("not done yet: "+f.getValue());
@Override public ValueSet expandByIdentifier(String theUri, String theFilter) { if (isBlank(theUri)) { throw new InvalidRequestException("URI must not be blank or missing"); } ValueSet source = new ValueSet(); source.getCompose().addInclude().addValueSet(theUri); if (isNotBlank(theFilter)) { ConceptSetComponent include = source.getCompose().addInclude(); ConceptSetFilterComponent filter = include.addFilter(); filter.setProperty("display"); filter.setOp(FilterOperator.EQUAL); filter.setValue(theFilter); } ValueSet retVal = doExpand(source); return retVal; // if (defaultValueSet != null) { // source = getContext().newJsonParser().parseResource(ValueSet.class, getContext().newJsonParser().encodeResourceToString(defaultValueSet)); // } else { // IBundleProvider ids = search(ValueSet.SP_URL, new UriParam(theUri)); // if (ids.size() == 0) { // throw new InvalidRequestException("Unknown ValueSet URI: " + theUri); // } // source = (ValueSet) ids.getResources(0, 1).get(0); // } // // return expand(defaultValueSet, theFilter); }
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; }
public ConceptSetComponent copy() { ConceptSetComponent dst = new ConceptSetComponent(); copyValues(dst); dst.system = system == null ? null : system.copy(); dst.version = version == null ? null : version.copy(); if (concept != null) { dst.concept = new ArrayList<ConceptReferenceComponent>(); for (ConceptReferenceComponent i : concept) dst.concept.add(i.copy()); }; if (filter != null) { dst.filter = new ArrayList<ConceptSetFilterComponent>(); for (ConceptSetFilterComponent i : filter) dst.filter.add(i.copy()); }; if (valueSet != null) { dst.valueSet = new ArrayList<UriType>(); for (UriType i : valueSet) dst.valueSet.add(i.copy()); }; return dst; }
@Override public Base setProperty(int hash, String name, Base value) throws FHIRException { switch (hash) { case -887328209: // system this.system = castToUri(value); // UriType return value; case 351608024: // version this.version = castToString(value); // StringType return value; case 951024232: // concept this.getConcept().add((ConceptReferenceComponent) value); // ConceptReferenceComponent return value; case -1274492040: // filter this.getFilter().add((ConceptSetFilterComponent) value); // ConceptSetFilterComponent return value; case -1410174671: // valueSet this.getValueSet().add(castToUri(value)); // UriType return value; default: return super.setProperty(hash, name, value); } }
@Override public Base addChild(String name) throws FHIRException { if (name.equals("system")) { throw new FHIRException("Cannot call addChild on a primitive type ValueSet.system"); } else if (name.equals("version")) { throw new FHIRException("Cannot call addChild on a primitive type ValueSet.version"); } else if (name.equals("concept")) { return addConcept(); } else if (name.equals("filter")) { return addFilter(); } else if (name.equals("valueSet")) { throw new FHIRException("Cannot call addChild on a primitive type ValueSet.valueSet"); } else return super.addChild(name); }
public ValueSetComposeComponent copy() { ValueSetComposeComponent dst = new ValueSetComposeComponent(); copyValues(dst); dst.lockedDate = lockedDate == null ? null : lockedDate.copy(); dst.inactive = inactive == null ? null : inactive.copy(); if (include != null) { dst.include = new ArrayList<ConceptSetComponent>(); for (ConceptSetComponent i : include) dst.include.add(i.copy()); }; if (exclude != null) { dst.exclude = new ArrayList<ConceptSetComponent>(); for (ConceptSetComponent i : exclude) dst.exclude.add(i.copy()); }; return dst; }
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); }
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 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 static org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetComposeComponent convertValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetComposeComponent tgt = new org.hl7.fhir.dstu2016may.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()); tgt.addInclude(convertConceptSetComponent(t)); } for (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent t : src.getExclude()) tgt.addExclude(convertConceptSetComponent(t)); return tgt; }