use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System 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.gravity.refimpl.sdohexchange.sdohmappings.System 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;
}
use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project cqf-ruler by DBCG.
the class JpaTerminologyProvider method expand.
@Override
public Iterable<Code> expand(ValueSetInfo valueSet) throws ResourceNotFoundException {
// This could possibly be refactored into a single call to the underlying HAPI
// Terminology service. Need to think through that..,
IBaseResource vs;
if (hasUrlId(valueSet)) {
if (hasVersion(valueSet) || hasVersionedCodeSystem(valueSet)) {
throw new UnsupportedOperationException(String.format("Could not expand value set %s; version and code system bindings are not supported at this time.", valueSet.getId()));
}
IBundleProvider bundleProvider = search(getClass("ValueSet"), Searches.byUrl(valueSet.getId()), myRequestDetails);
List<IBaseResource> valueSets = bundleProvider.getAllResources();
if (valueSets.isEmpty()) {
throw new IllegalArgumentException(String.format("Could not resolve value set %s.", valueSet.getId()));
} else if (valueSets.size() == 1) {
vs = valueSets.get(0);
} else {
throw new IllegalArgumentException("Found more than 1 ValueSet with url: " + valueSet.getId());
}
} else {
vs = read(Ids.newId(this.myTerminologySvc.getFhirContext(), "ValueSet", valueSet.getId()), myRequestDetails);
if (vs == null) {
throw new IllegalArgumentException(String.format("Could not resolve value set %s.", valueSet.getId()));
}
}
// relies heavily on reflection.
switch(vs.getStructureFhirVersionEnum()) {
case DSTU3:
return getCodes((org.hl7.fhir.dstu3.model.ValueSet) vs);
case R4:
return getCodes((org.hl7.fhir.r4.model.ValueSet) vs);
case R5:
return getCodes((org.hl7.fhir.r5.model.ValueSet) vs);
default:
throw new IllegalArgumentException(String.format("expand does not support FHIR version %s", vs.getStructureFhirVersionEnum().getFhirVersionString()));
}
}
use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method procedureWrongIdentifier.
@Test(expectedExceptions = BadRequestException.class, expectedExceptionsMessageRegExp = "Could not find Bridge user ID.")
public void procedureWrongIdentifier() throws Exception {
when(mockRequest.getHeader(AUTHORIZATION)).thenReturn(AUTHORIZATION_HEADER_VALUE);
when(mockAccountService.authenticate(any(), any())).thenReturn(account);
when(mockAccountService.getAccount(ACCOUNT_ID)).thenReturn(Optional.of(account));
Identifier identifier = new Identifier();
identifier.setSystem("wrong-system");
identifier.setValue(TEST_USER_ID);
ProcedureRequest procedure = new ProcedureRequest();
procedure.addIdentifier(identifier);
String json = FHIR_CONTEXT.newJsonParser().encodeResourceToString(procedure);
mockRequestBody(mockRequest, json);
controller.postProcedureRequest();
}
use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method operationWrongIdentifier.
@Test(expectedExceptions = BadRequestException.class, expectedExceptionsMessageRegExp = "Could not find Bridge user ID.")
public void operationWrongIdentifier() throws Exception {
when(mockRequest.getHeader(AUTHORIZATION)).thenReturn(AUTHORIZATION_HEADER_VALUE);
when(mockAccountService.authenticate(any(), any())).thenReturn(account);
when(mockAccountService.getAccount(ACCOUNT_ID)).thenReturn(Optional.of(account));
Identifier identifier = new Identifier();
identifier.setSystem("wrong-system");
identifier.setValue(TEST_USER_ID);
Observation observation = new Observation();
observation.addIdentifier(identifier);
String json = FHIR_CONTEXT.newJsonParser().encodeResourceToString(observation);
mockRequestBody(mockRequest, json);
controller.postObservation();
}
Aggregations