Search in sources :

Example 1 with IBundleProvider

use of ca.uhn.fhir.rest.api.server.IBundleProvider 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 2 with IBundleProvider

use of ca.uhn.fhir.rest.api.server.IBundleProvider 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 3 with IBundleProvider

use of ca.uhn.fhir.rest.api.server.IBundleProvider in project ipf by oehf.

the class Iti67ResourceProvider method documentReferenceSearch.

@SuppressWarnings("unused")
@Search(type = DocumentReference.class)
public IBundleProvider documentReferenceSearch(@RequiredParam(name = DocumentReference.SP_PATIENT, chainWhitelist = { "", Patient.SP_IDENTIFIER }) ReferenceParam patient, @OptionalParam(name = DocumentReference.SP_STATUS) TokenOrListParam status, @OptionalParam(name = DocumentReference.SP_IDENTIFIER) TokenParam identifier, @OptionalParam(name = DocumentReference.SP_DATE) DateRangeParam date, @OptionalParam(name = STU3_INDEXED) DateRangeParam indexed, @OptionalParam(name = DocumentReference.SP_AUTHOR, chainWhitelist = { Practitioner.SP_FAMILY, Practitioner.SP_GIVEN }) ReferenceAndListParam author, @OptionalParam(name = DocumentReference.SP_CATEGORY) TokenOrListParam category, @OptionalParam(name = STU3_CLASS) TokenOrListParam class_, @OptionalParam(name = DocumentReference.SP_TYPE) TokenOrListParam type, @OptionalParam(name = DocumentReference.SP_SETTING) TokenOrListParam setting, @OptionalParam(name = DocumentReference.SP_PERIOD) DateRangeParam period, @OptionalParam(name = DocumentReference.SP_FACILITY) TokenOrListParam facility, @OptionalParam(name = DocumentReference.SP_EVENT) TokenOrListParam event, @OptionalParam(name = DocumentReference.SP_SECURITY_LABEL) TokenOrListParam securityLabel, @OptionalParam(name = STU3_SECURITY_LABEL) TokenOrListParam label, @OptionalParam(name = DocumentReference.SP_FORMAT) TokenOrListParam format, @OptionalParam(name = DocumentReference.SP_RELATED, chainWhitelist = { "", DocumentReference.SP_IDENTIFIER }) ReferenceOrListParam related, // -> related.identifier
@OptionalParam(name = STU3_RELATED_ID) TokenOrListParam relatedId, // -> related
@OptionalParam(name = STU3_RELATED_REF) ReferenceOrListParam relatedRef, // Extension to ITI-67
@OptionalParam(name = IAnyResource.SP_RES_ID) TokenParam resourceId, @Sort SortSpec sortSpec, @IncludeParam Set<Include> includeSpec, RequestDetails requestDetails, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    // Be graceful and accept STU3 parameters as well
    var dateParam = date != null ? date : indexed;
    var categoryParam = category != null ? category : class_;
    var securityLabelParam = securityLabel != null ? securityLabel : label;
    // Handle "related" parameters
    ReferenceOrListParam relatedParam = new ReferenceOrListParam();
    TokenOrListParam relatedIdParam = new TokenOrListParam();
    if (relatedRef != null) {
        relatedParam = relatedRef;
    } else if (relatedId != null) {
        relatedIdParam = relatedId;
    } else if (related != null) {
        related.getValuesAsQueryTokens().stream().filter(referenceParam -> !DocumentReference.SP_IDENTIFIER.equals(referenceParam.getChain())).forEach(relatedParam::addOr);
        related.getValuesAsQueryTokens().stream().filter(referenceParam -> DocumentReference.SP_IDENTIFIER.equals(referenceParam.getChain())).map(referenceParam -> referenceParam.toTokenParam(getFhirContext())).forEach(relatedIdParam::addOr);
    }
    var searchParameters = Iti67SearchParameters.builder().status(status).identifier(identifier).date(dateParam).category(categoryParam).type(type).setting(setting).period(period).facility(facility).event(event).securityLabel(securityLabelParam).format(format).related(relatedParam).relatedId(relatedIdParam)._id(resourceId).sortSpec(sortSpec).includeSpec(includeSpec).fhirContext(getFhirContext()).build();
    searchParameters.setAuthor(author);
    var patientChain = patient.getChain();
    if (Patient.SP_IDENTIFIER.equals(patientChain)) {
        searchParameters.setPatientIdentifier(patient.toTokenParam(getFhirContext()));
    } else if (patientChain == null || patientChain.isEmpty()) {
        searchParameters.setPatientReference(patient);
    }
    // Run down the route
    return requestBundleProvider(null, searchParameters, ResourceType.DocumentReference.name(), httpServletRequest, httpServletResponse, requestDetails);
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) IncludeParam(ca.uhn.fhir.rest.annotation.IncludeParam) AbstractPlainProvider(org.openehealth.ipf.commons.ihe.fhir.AbstractPlainProvider) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Search(ca.uhn.fhir.rest.annotation.Search) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Patient(org.hl7.fhir.r4.model.Patient) Read(ca.uhn.fhir.rest.annotation.Read) Practitioner(org.hl7.fhir.r4.model.Practitioner) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Sort(ca.uhn.fhir.rest.annotation.Sort) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Include(ca.uhn.fhir.model.api.Include) IdType(org.hl7.fhir.r4.model.IdType) TokenParam(ca.uhn.fhir.rest.param.TokenParam) ResourceType(org.hl7.fhir.r4.model.ResourceType) SortSpec(ca.uhn.fhir.rest.api.SortSpec) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Search(ca.uhn.fhir.rest.annotation.Search)

Example 4 with IBundleProvider

use of ca.uhn.fhir.rest.api.server.IBundleProvider in project hapi-fhir-jpaserver-starter by hapifhir.

the class RepositoryValidationInterceptorFactoryR5 method buildUsingStoredStructureDefinitions.

public RepositoryValidatingInterceptor buildUsingStoredStructureDefinitions() {
    IBundleProvider results = structureDefinitionResourceProvider.search(new SearchParameterMap().add(StructureDefinition.SP_KIND, new TokenParam("resource")));
    Map<String, List<StructureDefinition>> structureDefintions = results.getResources(0, results.size()).stream().map(StructureDefinition.class::cast).collect(Collectors.groupingBy(StructureDefinition::getType));
    structureDefintions.entrySet().forEach(structureDefinitionListEntry -> {
        String[] urls = structureDefinitionListEntry.getValue().stream().map(StructureDefinition::getUrl).toArray(String[]::new);
        repositoryValidatingRuleBuilder.forResourcesOfType(structureDefinitionListEntry.getKey()).requireAtLeastOneProfileOf(urls).and().requireValidationToDeclaredProfiles();
    });
    List<IRepositoryValidatingRule> rules = repositoryValidatingRuleBuilder.build();
    return new RepositoryValidatingInterceptor(fhirContext, rules);
}
Also used : RepositoryValidatingInterceptor(ca.uhn.fhir.jpa.interceptor.validation.RepositoryValidatingInterceptor) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) List(java.util.List) IRepositoryValidatingRule(ca.uhn.fhir.jpa.interceptor.validation.IRepositoryValidatingRule) SearchParameterMap(ca.uhn.fhir.jpa.searchparam.SearchParameterMap)

Example 5 with IBundleProvider

use of ca.uhn.fhir.rest.api.server.IBundleProvider in project openmrs-module-fhir2 by openmrs.

the class ConditionSearchQueryTest method searchForObsConditions_shouldSearchForConditionsByMultiplePatientGivenNameOr.

@Test
public void searchForObsConditions_shouldSearchForConditionsByMultiplePatientGivenNameOr() {
    ReferenceAndListParam referenceParam = new ReferenceAndListParam();
    ReferenceParam patient = new ReferenceParam();
    patient.setValue(PATIENT_GIVEN_NAME);
    patient.setChain(Patient.SP_GIVEN);
    ReferenceParam badPatient = new ReferenceParam();
    badPatient.setValue(PATIENT_WRONG_GIVEN_NAME);
    badPatient.setChain(Patient.SP_GIVEN);
    referenceParam.addValue(new ReferenceOrListParam().add(patient).add(badPatient));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, referenceParam);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertEquals(resultList.size(), 2);
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)1139 Test (org.junit.Test)1117 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)802 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)745 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)613 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)360 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)360 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)360 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)343 TokenParam (ca.uhn.fhir.rest.param.TokenParam)310 StringParam (ca.uhn.fhir.rest.param.StringParam)248 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)232 HashSet (java.util.HashSet)181 Include (ca.uhn.fhir.model.api.Include)174 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)162 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)135 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)117 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)110 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)99 Patient (org.hl7.fhir.r4.model.Patient)64