Search in sources :

Example 46 with Patient

use of org.hl7.fhir.r5.model.Patient in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProviderIT method searchForExistingPatientByMbiHashWithPaging.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.R4PatientResourceProvider#searchByIdentifier(ca.uhn.fhir.rest.param.TokenParam)}
 * works as expected for a {@link Patient} that does exist in the DB, with paging.
 */
@Test
public void searchForExistingPatientByMbiHashWithPaging() {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
    Bundle searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH, beneficiary.getMbiHash().get())).count(1).returnBundle(Bundle.class).execute();
    assertNotNull(searchResults);
    assertEquals(1, searchResults.getTotal());
    Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
    comparePatient(beneficiary, patientFromSearchResult, getRHwithIncldAddrFldHdr("false"));
    /*
     * Verify that only the first and last paging links exist, since there should
     * only be one page.
     */
    assertNotNull(searchResults.getLink(Constants.LINK_FIRST));
    assertNull(searchResults.getLink(Constants.LINK_NEXT));
    assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
    assertNotNull(searchResults.getLink(Constants.LINK_LAST));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) Date(java.util.Date) ExtraParamsInterceptor(gov.cms.bfd.server.war.stu3.providers.ExtraParamsInterceptor) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Constants(ca.uhn.fhir.rest.api.Constants) Identifier(org.hl7.fhir.r4.model.Identifier) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) Patient(org.hl7.fhir.r4.model.Patient) Iterator(java.util.Iterator) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Bundle(org.hl7.fhir.r4.model.Bundle) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 47 with Patient

use of org.hl7.fhir.r5.model.Patient in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProviderIT method searchForMissingPatientByLogicalId.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.R4PatientResourceProvider#searchByLogicalId(ca.uhn.fhir.rest.param.TokenParam)}
 * works as expected for a {@link Patient} that does not exist in the DB.
 */
@Test
public void searchForMissingPatientByLogicalId() {
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    // No data is loaded, so this should return 0 matches.
    Bundle searchResults = fhirClient.search().forResource(Patient.class).where(Patient.RES_ID.exactly().systemAndIdentifier(null, "foo")).returnBundle(Bundle.class).execute();
    assertNotNull(searchResults);
    assertEquals(0, searchResults.getTotal());
}
Also used : IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) Test(org.junit.jupiter.api.Test)

Example 48 with Patient

use of org.hl7.fhir.r5.model.Patient in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProviderIT method searchForExistingPatientByPartDContractNumIncludeIdentifiersTrueAndMultipleMbis.

/**
 * Regression test for part of BFD-525, which verifies that duplicate entries are not returned
 * when 1) plain-text identifiers are requested, 2) a beneficiary has multiple historical
 * identifiers, and 3) paging is not requested. (This oddly specific combo had been bugged earlier
 * and was quite tricky to resolve).
 */
@Test
public void searchForExistingPatientByPartDContractNumIncludeIdentifiersTrueAndMultipleMbis() {
    ServerTestUtils.get().loadData(Arrays.asList(StaticRifResource.SAMPLE_A_BENES, StaticRifResource.SAMPLE_A_MEDICARE_BENEFICIARY_ID_HISTORY, StaticRifResource.SAMPLE_A_MEDICARE_BENEFICIARY_ID_HISTORY_EXTRA));
    IGenericClient fhirClient = createFhirClient("mbi", "true");
    // Should return a single match
    Bundle searchResults = fhirClient.search().forResource(Patient.class).where(new TokenClientParam("_has:Coverage.extension").exactly().systemAndIdentifier(CCWUtils.calculateVariableReferenceUrl(CcwCodebookVariable.PTDCNTRCT01), "S4607")).where(new TokenClientParam("_has:Coverage.rfrncyr").exactly().systemAndIdentifier(CCWUtils.calculateVariableReferenceUrl(CcwCodebookVariable.RFRNC_YR), "2018")).returnBundle(Bundle.class).execute();
    // Verify that the bene wasn't duplicated.
    assertNotNull(searchResults);
    assertEquals(1, searchResults.getEntry().size());
    // Double-check that the bene has multiple identifiers.
    Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
    assertEquals(// was 4
    1, patientFromSearchResult.getIdentifier().stream().filter(i -> TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED.equals(i.getSystem())).count());
}
Also used : TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) Test(org.junit.jupiter.api.Test)

Example 49 with Patient

use of org.hl7.fhir.r5.model.Patient in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProviderIT method searchForPatientByLogicalIdWithPaging.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.R4PatientResourceProvider#searchByLogicalId(ca.uhn.fhir.rest.param.TokenParam)}
 * works as expected for a {@link Patient} that does exist in the DB, with paging.
 */
@Test
public void searchForPatientByLogicalIdWithPaging() {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
    Bundle searchResults = fhirClient.search().forResource(Patient.class).where(Patient.RES_ID.exactly().systemAndIdentifier(null, beneficiary.getBeneficiaryId())).count(1).returnBundle(Bundle.class).execute();
    assertNotNull(searchResults);
    assertEquals(1, searchResults.getTotal());
    /*
     * Verify that only the first and last paging links exist, since there should
     * only be one page.
     */
    assertNotNull(searchResults.getLink(Constants.LINK_FIRST));
    assertNull(searchResults.getLink(Constants.LINK_NEXT));
    assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
    assertNotNull(searchResults.getLink(Constants.LINK_LAST));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) Date(java.util.Date) ExtraParamsInterceptor(gov.cms.bfd.server.war.stu3.providers.ExtraParamsInterceptor) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Constants(ca.uhn.fhir.rest.api.Constants) Identifier(org.hl7.fhir.r4.model.Identifier) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) Patient(org.hl7.fhir.r4.model.Patient) Iterator(java.util.Iterator) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Bundle(org.hl7.fhir.r4.model.Bundle) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 50 with Patient

use of org.hl7.fhir.r5.model.Patient in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProviderIT method testLastUpdatedUrls.

/**
 * Test the set of lastUpdated values
 *
 * @param fhirClient to use
 * @param id the beneficiary id to use
 * @param urls is a list of lastUpdate values to test to find
 * @param expectedValue number of matches
 */
private void testLastUpdatedUrls(IGenericClient fhirClient, String id, List<String> urls, int expectedValue) {
    String baseResourceUrl = "Patient?_id=" + id + "&_format=application%2Fjson%2Bfhir";
    // Search for each lastUpdated value
    for (String lastUpdatedValue : urls) {
        String theSearchUrl = baseResourceUrl + "&" + lastUpdatedValue;
        Bundle searchResults = fhirClient.search().byUrl(theSearchUrl).returnBundle(Bundle.class).execute();
        assertEquals(expectedValue, searchResults.getTotal(), String.format("Expected %s to filter resources using lastUpdated correctly", lastUpdatedValue));
    }
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle)

Aggregations

Test (org.junit.Test)576 Test (org.junit.jupiter.api.Test)442 Patient (org.hl7.fhir.r4.model.Patient)437 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)255 HashMap (java.util.HashMap)251 Patient (org.hl7.fhir.dstu3.model.Patient)249 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)228 Bundle (org.hl7.fhir.r4.model.Bundle)203 Path (javax.ws.rs.Path)188 Date (java.util.Date)171 Produces (javax.ws.rs.Produces)163 ArrayList (java.util.ArrayList)156 JsonObject (javax.json.JsonObject)141 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)140 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)138 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)137 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)128 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)128 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)125 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)120