Search in sources :

Example 71 with System

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");
    }
}
Also used : HashSet(java.util.HashSet) IFhirResourceDaoValueSet(ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoValueSet) Set(java.util.Set) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) IFhirResourceDaoCodeSystem(ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) IFhirResourceDaoValueSet(ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoValueSet) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) HashMap(java.util.HashMap) Map(java.util.Map) SearchParameterMap(ca.uhn.fhir.jpa.searchparam.SearchParameterMap)

Example 72 with System

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;
}
Also used : IIdType(org.hl7.fhir.instance.model.api.IIdType) IdParam(ca.uhn.fhir.rest.annotation.IdParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Coding(org.hl7.fhir.dstu3.model.Coding) IdType(org.hl7.fhir.dstu3.model.IdType) Description(ca.uhn.fhir.model.api.annotation.Description) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Operation(ca.uhn.fhir.rest.annotation.Operation) Enumerations(org.hl7.fhir.dstu3.model.Enumerations) CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) Ids(org.opencds.cqf.ruler.utility.Ids) ArrayList(java.util.ArrayList) OperationProvider(org.opencds.cqf.ruler.api.OperationProvider) HashSet(java.util.HashSet) IFhirResourceDaoValueSet(ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoValueSet) Map(java.util.Map) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) SearchParameterMap(ca.uhn.fhir.jpa.searchparam.SearchParameterMap) Set(java.util.Set) UriParam(ca.uhn.fhir.rest.param.UriParam) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) IFhirResourceDaoCodeSystem(ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem) Collections(java.util.Collections) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IFhirResourceDaoValueSet(ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoValueSet) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) Description(ca.uhn.fhir.model.api.annotation.Description) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 73 with System

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()));
    }
}
Also used : IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 74 with System

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();
}
Also used : Identifier(org.hl7.fhir.dstu3.model.Identifier) ProcedureRequest(org.hl7.fhir.dstu3.model.ProcedureRequest) Test(org.testng.annotations.Test)

Example 75 with System

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();
}
Also used : Identifier(org.hl7.fhir.dstu3.model.Identifier) Observation(org.hl7.fhir.dstu3.model.Observation) Test(org.testng.annotations.Test)

Aggregations

Test (org.junit.jupiter.api.Test)92 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)75 ArrayList (java.util.ArrayList)70 Coding (org.hl7.fhir.r4.model.Coding)70 Identifier (org.hl7.fhir.r4.model.Identifier)62 FHIRException (org.hl7.fhir.exceptions.FHIRException)45 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)45 Resource (org.hl7.fhir.r4.model.Resource)45 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 Test (org.junit.Test)37 Coding (org.hl7.fhir.dstu3.model.Coding)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32 HashMap (java.util.HashMap)30 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)28 List (java.util.List)27 IOException (java.io.IOException)26 Bundle (org.hl7.fhir.r4.model.Bundle)26 Patient (org.hl7.fhir.r4.model.Patient)25 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)24 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)21