Search in sources :

Example 46 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.

the class MedicationRequestSearchQueryTest method searchForMedicationRequest_shouldReturnMedicationRequestByMedication.

@Test
public void searchForMedicationRequest_shouldReturnMedicationRequestByMedication() {
    ReferenceAndListParam medicationReference = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(MEDICATION_UUID)));
    SearchParameterMap theParams = new SearchParameterMap();
    theParams.addParameter(FhirConstants.MEDICATION_REFERENCE_SEARCH_HANDLER, medicationReference);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    List<MedicationRequest> resultList = get(results);
    assertThat(resultList, notNullValue());
    assertThat(resultList, hasItem(hasProperty("id", equalTo(MEDICATION_REQUEST_UUID))));
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) 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)

Example 47 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.

the class MedicationRequestSearchQueryTest method searchForMedicationRequests_shouldReturnEmptyListOfMedicationRequestsByMultipleParticipantGivenNameAnd.

@Test
public void searchForMedicationRequests_shouldReturnEmptyListOfMedicationRequestsByMultipleParticipantGivenNameAnd() {
    ReferenceAndListParam participantReference = new ReferenceAndListParam();
    ReferenceParam participant = new ReferenceParam();
    participant.setValue(PARTICIPANT_GIVEN_NAME);
    participant.setChain(Practitioner.SP_GIVEN);
    ReferenceParam badParticipant = new ReferenceParam();
    badParticipant.setValue(WRONG_GIVEN_NAME);
    badParticipant.setChain(Practitioner.SP_GIVEN);
    participantReference.addValue(new ReferenceOrListParam().add(participant)).addAnd(new ReferenceOrListParam().add(badParticipant));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, participantReference);
    IBundleProvider results = search(theParams);
    List<MedicationRequest> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, empty());
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) 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)

Example 48 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.

the class MedicationRequestSearchQueryTest method searchForMedicationRequests_shouldAddPractitionersForRequesterInclude.

@Test
public void searchForMedicationRequests_shouldAddPractitionersForRequesterInclude() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(MEDICATION_REQUEST_UUID));
    HashSet<Include> includes = new HashSet<>();
    includes.add(new Include("MedicationRequest:requester"));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
    IBundleProvider results = search(theParams);
    assertThat(results.size(), equalTo(1));
    assertThat(results, notNullValue());
    List<IBaseResource> resultList = results.getResources(0, 10);
    assertThat(resultList, not(empty()));
    // included resource added as part of the result list
    assertThat(resultList.size(), equalTo(2));
    assertThat(((MedicationRequest) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID));
    MedicationRequest returnedMedicationRequest = (MedicationRequest) resultList.iterator().next();
    assertThat(resultList, hasItem(allOf(is(instanceOf(Practitioner.class)), hasProperty("id", equalTo(returnedMedicationRequest.getRequester().getReferenceElement().getIdPart())))));
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 49 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.

the class MedicationRequestSearchQueryTest method searchForMedicationRequests_shouldReturnEmptyListOfMedicationRequestsByMultipleParticipantNameAnd.

@Test
public void searchForMedicationRequests_shouldReturnEmptyListOfMedicationRequestsByMultipleParticipantNameAnd() {
    ReferenceAndListParam participantReference = new ReferenceAndListParam();
    ReferenceParam participant = new ReferenceParam();
    participant.setValue(PATIENT_GIVEN_NAME + " " + PARTICIPANT_FAMILY_NAME);
    participant.setChain(Practitioner.SP_NAME);
    ReferenceParam badParticipant = new ReferenceParam();
    badParticipant.setValue(WRONG_NAME);
    badParticipant.setChain(Practitioner.SP_NAME);
    participantReference.addValue(new ReferenceOrListParam().add(participant)).addAnd(new ReferenceOrListParam().add(badParticipant));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, participantReference);
    IBundleProvider results = search(theParams);
    List<MedicationRequest> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(0));
    assertThat(resultList, empty());
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) 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)

Example 50 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.

the class MedicationRequestSearchQueryTest method searchForMedicationRequest_shouldSearchForMedicationRequestByConceptUuid.

@Test
public void searchForMedicationRequest_shouldSearchForMedicationRequestByConceptUuid() {
    TokenAndListParam code = new TokenAndListParam();
    TokenParam codingToken = new TokenParam();
    codingToken.setValue(MEDICATION_REQUEST_CONCEPT_UUID);
    code.addAnd(codingToken);
    SearchParameterMap theParams = new SearchParameterMap();
    theParams.addParameter(FhirConstants.CODED_SEARCH_HANDLER, code);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    List<MedicationRequest> resultList = get(results);
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasItem(hasProperty("id", equalTo(MEDICATION_REQUEST_UUID))));
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)128 Test (org.junit.Test)128 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)78 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)58 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)48 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)44 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)44 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)44 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)36 Test (org.junit.jupiter.api.Test)35 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)33 Resource (org.hl7.fhir.r4.model.Resource)31 MedicationRequest (org.hl7.fhir.dstu3.model.MedicationRequest)26 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)23 TokenParam (ca.uhn.fhir.rest.param.TokenParam)23 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)23 ArrayList (java.util.ArrayList)19 Include (ca.uhn.fhir.model.api.Include)15 HashSet (java.util.HashSet)15