use of org.hl7.fhir.r4.model.ValueSet in project cqf-ruler by DBCG.
the class DiscoveryResolutionStu3 method resolveValueSetCodes.
public List<String> resolveValueSetCodes(String valueSetId) {
ValueSet valueSet = this.search(ValueSet.class, Searches.byCanonical(valueSetId)).firstOrNull();
List<String> result = new ArrayList<>();
StringBuilder codes = new StringBuilder();
if (valueSet.hasExpansion() && valueSet.getExpansion().hasContains()) {
for (ValueSet.ValueSetExpansionContainsComponent contains : valueSet.getExpansion().getContains()) {
String system = contains.getSystem();
String code = contains.getCode();
codes = getCodesStringBuilder(result, codes, system, code);
}
} else if (valueSet.hasCompose() && valueSet.getCompose().hasInclude()) {
for (ValueSet.ConceptSetComponent concepts : valueSet.getCompose().getInclude()) {
String system = concepts.getSystem();
if (concepts.hasConcept()) {
for (ValueSet.ConceptReferenceComponent concept : concepts.getConcept()) {
String code = concept.getCode();
codes = getCodesStringBuilder(result, codes, system, code);
}
}
}
}
result.add(codes.toString());
return result;
}
use of org.hl7.fhir.r4.model.ValueSet in project cqf-ruler by DBCG.
the class CacheValueSetsProvider method cacheValuesets.
/**
* Using basic authentication this {@link Operation Operation} will update
* any {@link ValueSet Valueset} listed given the {@link Endpoint Endpoint}
* provided.
* Any Valuesets that require expansion will be expanded.
*
* @param details the {@link RequestDetails RequestDetails}
* @param endpointId the {@link Endpoint Endpoint} id
* @param valuesets the {@link StringAndListParam list} of {@link ValueSet
* Valueset} ids
* @param userName the userName
* @param password the password
* @return the {@link OperationOutcome OperationOutcome} or the resulting
* {@link Bundle Bundle}
*/
@Description(shortDefinition = "$cache-valuesets", value = "Using basic authentication this Operation will update any Valueset listed given the Endpoint provided. Any Valuesets that require expansion will be expanded.", example = "Endpoint/example-id/$cache-valuesets?valuesets=valuesetId1&valuesets=valuesetId2&user=user&password=password")
@Operation(name = "$cache-valuesets", idempotent = true, type = Endpoint.class)
public Resource cacheValuesets(RequestDetails details, @IdParam IdType endpointId, @OperationParam(name = "valuesets") StringAndListParam valuesets, @OperationParam(name = "user") String userName, @OperationParam(name = "pass") String password) {
Endpoint endpoint = null;
try {
endpoint = this.endpointDao.read(endpointId);
if (endpoint == null) {
return createErrorOutcome("Could not find Endpoint/" + endpointId);
}
} catch (Exception e) {
return createErrorOutcome("Could not find Endpoint/" + endpointId + "\n" + e);
}
IGenericClient client = Clients.forEndpoint(ourCtx, endpoint);
if (userName != null || password != null) {
if (userName == null) {
return createErrorOutcome("Password was provided, but not a user name.");
} else if (password == null) {
return createErrorOutcome("User name was provided, but not a password.");
}
BasicAuthInterceptor basicAuth = new BasicAuthInterceptor(userName, password);
client.registerInterceptor(basicAuth);
// TODO - more advanced security like bearer tokens, etc...
}
try {
Bundle bundleToPost = new Bundle();
for (StringOrListParam params : valuesets.getValuesAsQueryTokens()) {
for (StringParam valuesetId : params.getValuesAsQueryTokens()) {
bundleToPost.addEntry().setRequest(new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.PUT).setUrl("ValueSet/" + valuesetId.getValue())).setResource(resolveValueSet(client, valuesetId.getValue()));
}
}
return (Resource) systemDao.transaction(details, bundleToPost);
} catch (Exception e) {
return createErrorOutcome(e.getMessage());
}
}
use of org.hl7.fhir.r4.model.ValueSet in project cqf-ruler by DBCG.
the class CacheValueSetsProvider method getCachedValueSet.
private ValueSet getCachedValueSet(ValueSet expandedValueSet) {
ValueSet clean = expandedValueSet.copy().setExpansion(null);
Map<String, ValueSet.ConceptSetComponent> concepts = new HashMap<>();
for (ValueSet.ValueSetExpansionContainsComponent expansion : expandedValueSet.getExpansion().getContains()) {
if (!expansion.hasSystem()) {
continue;
}
if (concepts.containsKey(expansion.getSystem())) {
concepts.get(expansion.getSystem()).addConcept(new ValueSet.ConceptReferenceComponent().setCode(expansion.hasCode() ? expansion.getCode() : null).setDisplay(expansion.hasDisplay() ? expansion.getDisplay() : null));
} else {
concepts.put(expansion.getSystem(), new ValueSet.ConceptSetComponent().setSystem(expansion.getSystem()).addConcept(new ValueSet.ConceptReferenceComponent().setCode(expansion.hasCode() ? expansion.getCode() : null).setDisplay(expansion.hasDisplay() ? expansion.getDisplay() : null)));
}
}
clean.setCompose(new ValueSet.ValueSetComposeComponent().setInclude(new ArrayList<>(concepts.values())));
return clean;
}
use of org.hl7.fhir.r4.model.ValueSet in project cqf-ruler by DBCG.
the class CodeSystemUpdateProvider method performCodeSystemUpdate.
public OperationOutcome performCodeSystemUpdate(List<ValueSet> valueSets) {
OperationOutcome response = new OperationOutcome();
List<String> codeSystems = new ArrayList<>();
// Possible for this to run out of memory with really large ValueSets and
// CodeSystems.
Map<String, Set<String>> codesBySystem = new HashMap<>();
for (ValueSet vs : valueSets) {
if (vs.hasCompose() && vs.getCompose().hasInclude()) {
for (ValueSet.ConceptSetComponent csc : vs.getCompose().getInclude()) {
if (!csc.hasSystem() || !csc.hasConcept()) {
continue;
}
String system = csc.getSystem();
if (!codesBySystem.containsKey(system)) {
codesBySystem.put(system, new HashSet<>());
}
Set<String> codes = codesBySystem.get(system);
codes.addAll(csc.getConcept().stream().map(ValueSet.ConceptReferenceComponent::getCode).collect(Collectors.toList()));
}
}
}
for (Map.Entry<String, Set<String>> entry : codesBySystem.entrySet()) {
String system = entry.getKey();
CodeSystem codeSystem = getCodeSystemByUrl(system);
updateCodeSystem(codeSystem.setUrl(system), getUnionDistinctCodes(entry.getValue(), codeSystem));
codeSystems.add(codeSystem.getUrl());
}
if (codeSystems.size() > 0) {
return buildIssue(response, "information", "informational", "Successfully updated the following CodeSystems: " + String.join(", ", codeSystems));
} else {
return buildIssue(response, "information", "informational", "No code systems were updated");
}
}
use of org.hl7.fhir.r4.model.ValueSet in project cqf-ruler by DBCG.
the class CodeSystemUpdateProvider method updateCodeSystems.
/**
* Update existing {@link CodeSystem CodeSystems} with the codes in all
* {@link ValueSet ValueSet} resources.
* System level CodeSystem update operation
*
* @return FHIR {@link OperationOutcome OperationOutcome} detailing the success
* or failure of the
* operation
*/
@Description(shortDefinition = "$updateCodeSystems", value = "Update existing CodeSystems with the codes in all ValueSet resources. System level CodeSystem update operation", example = "$updateCodeSystems")
@Operation(name = "$updateCodeSystems", idempotent = true)
public OperationOutcome updateCodeSystems() {
IBundleProvider valuesets = this.myValueSetDaoDSTU3.search(SearchParameterMap.newSynchronous());
List<ValueSet> valueSets = valuesets.getAllResources().stream().map(x -> (ValueSet) x).collect(Collectors.toList());
OperationOutcome outcome = this.performCodeSystemUpdate(valueSets);
OperationOutcome response = new OperationOutcome();
if (outcome.hasIssue()) {
for (OperationOutcome.OperationOutcomeIssueComponent issue : outcome.getIssue()) {
response.addIssue(issue);
}
}
return response;
}
Aggregations