Search in sources :

Example 6 with PatientLinkBuilder

use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProvider method searchByCoverageContractByFieldName.

public Bundle searchByCoverageContractByFieldName(// of relational search is more common.
TokenParam coverageId, String cursor, RequestDetails requestDetails) {
    checkCoverageId(coverageId);
    RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(requestDetails);
    PatientLinkBuilder paging = new PatientLinkBuilder(requestDetails.getCompleteUrl());
    Operation operation = new Operation(Operation.Endpoint.V2_PATIENT);
    operation.setOption("by", "coverageContract");
    requestHeader.getNVPairs().forEach((n, v) -> operation.setOption(n, v.toString()));
    operation.publishOperationName();
    List<Beneficiary> matchingBeneficiaries = fetchBeneficiaries(coverageId, requestHeader, paging);
    boolean hasAnotherPage = matchingBeneficiaries.size() > paging.getPageSize();
    if (hasAnotherPage) {
        matchingBeneficiaries = matchingBeneficiaries.subList(0, paging.getPageSize());
        paging = new PatientLinkBuilder(paging, hasAnotherPage);
    }
    List<IBaseResource> patients = matchingBeneficiaries.stream().map(beneficiary -> {
        // Null out the unhashed HICNs
        beneficiary.setHicnUnhashed(Optional.empty());
        Patient patient = BeneficiaryTransformerV2.transform(metricRegistry, beneficiary, requestHeader);
        return patient;
    }).collect(Collectors.toList());
    Bundle bundle = TransformerUtilsV2.createBundle(patients, paging, loadedFilterManager.getTransactionTime());
    TransformerUtilsV2.workAroundHAPIIssue1585(requestDetails);
    return bundle;
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) Arrays(java.util.Arrays) PatientLinkBuilder(gov.cms.bfd.server.war.commons.PatientLinkBuilder) Description(ca.uhn.fhir.model.api.annotation.Description) Identifier(org.hl7.fhir.r4.model.Identifier) NoResultException(javax.persistence.NoResultException) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Predicate(javax.persistence.criteria.Predicate) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) LoadedFilterManager(gov.cms.bfd.server.war.commons.LoadedFilterManager) Patient(org.hl7.fhir.r4.model.Patient) SingularAttribute(javax.persistence.metamodel.SingularAttribute) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdDt(ca.uhn.fhir.model.primitive.IdDt) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) BeneficiaryMonthly_(gov.cms.bfd.model.rif.BeneficiaryMonthly_) QueryHints(org.hibernate.jpa.QueryHints) Collectors(java.util.stream.Collectors) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) Objects(java.util.Objects) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) BeneficiaryHistory_(gov.cms.bfd.model.rif.BeneficiaryHistory_) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Year(java.time.Year) LocalDate(java.time.LocalDate) Timer(com.codahale.metrics.Timer) Optional(java.util.Optional) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) QueryUtils(gov.cms.bfd.server.war.commons.QueryUtils) Trace(com.newrelic.api.agent.Trace) HashMap(java.util.HashMap) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) TypedQuery(javax.persistence.TypedQuery) Beneficiary_(gov.cms.bfd.model.rif.Beneficiary_) ArrayList(java.util.ArrayList) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Search(ca.uhn.fhir.rest.annotation.Search) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) CommonHeaders(gov.cms.bfd.server.war.commons.CommonHeaders) LinkedList(java.util.LinkedList) Root(javax.persistence.criteria.Root) Read(ca.uhn.fhir.rest.annotation.Read) OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) MetricRegistry(com.codahale.metrics.MetricRegistry) Operation(gov.cms.bfd.server.war.Operation) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) IdType(org.hl7.fhir.r4.model.IdType) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Component(org.springframework.stereotype.Component) MDC(org.slf4j.MDC) YearMonth(java.time.YearMonth) Bundle(org.hl7.fhir.r4.model.Bundle) Collections(java.util.Collections) PatientLinkBuilder(gov.cms.bfd.server.war.commons.PatientLinkBuilder) Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) Operation(gov.cms.bfd.server.war.Operation) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Beneficiary(gov.cms.bfd.model.rif.Beneficiary)

Example 7 with PatientLinkBuilder

use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.

the class PatientLinkBuilderTest method noCountTest.

@Test
public void noCountTest() {
    PatientLinkBuilder paging = new PatientLinkBuilder(TEST_CONTRACT_URL);
    assertFalse(paging.isPagingRequested());
    assertTrue(paging.isFirstPage());
    assertEquals(PatientLinkBuilder.MAX_PAGE_SIZE, paging.getPageSize());
    Bundle bundle = new Bundle();
    assertTrue(bundle.getLink().isEmpty());
    paging.addLinks(bundle);
    assertTrue(bundle.getLink().isEmpty());
}
Also used : PatientLinkBuilder(gov.cms.bfd.server.war.commons.PatientLinkBuilder) Bundle(org.hl7.fhir.dstu3.model.Bundle) Test(org.junit.jupiter.api.Test)

Example 8 with PatientLinkBuilder

use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.

the class PatientLinkBuilderTest method testMdcLogsInAddResourcesToBundle.

@Test
public void testMdcLogsInAddResourcesToBundle() {
    PatientLinkBuilder paging = new PatientLinkBuilder(TEST_CONTRACT_URL + "&_count=10");
    assertTrue(paging.isPagingRequested());
    assertTrue(paging.isFirstPage());
    assertEquals(10, paging.getPageSize());
    Bundle bundle = new Bundle();
    TransformerUtils.addResourcesToBundle(bundle, Collections.singletonList(new Patient().setId("Id")));
    assertTrue(bundle.getLink().isEmpty());
    paging.addLinks(bundle);
    assertNotNull(bundle.getLink(Constants.LINK_SELF));
    assertNotNull(bundle.getLink(Constants.LINK_FIRST));
    UriComponents firstLink = UriComponentsBuilder.fromUriString(bundle.getLink(Constants.LINK_FIRST).getUrl()).build();
    assertEquals("10", firstLink.getQueryParams().getFirst(Constants.PARAM_COUNT));
    assertNull(bundle.getLink(Constants.LINK_NEXT));
    bundle = new Bundle();
    TransformerUtils.addResourcesToBundle(bundle, Collections.singletonList(new Coverage().setBeneficiary(new Reference("Patient/Id"))));
    assertTrue(bundle.getLink().isEmpty());
    paging.addLinks(bundle);
    assertNotNull(bundle.getLink(Constants.LINK_SELF));
    assertNotNull(bundle.getLink(Constants.LINK_FIRST));
    firstLink = UriComponentsBuilder.fromUriString(bundle.getLink(Constants.LINK_FIRST).getUrl()).build();
    assertEquals("10", firstLink.getQueryParams().getFirst(Constants.PARAM_COUNT));
    assertNull(bundle.getLink(Constants.LINK_NEXT));
    bundle = new Bundle();
    TransformerUtils.addResourcesToBundle(bundle, Collections.singletonList(new ExplanationOfBenefit().setPatient(new Reference("Patient/Id"))));
    assertTrue(bundle.getLink().isEmpty());
    paging.addLinks(bundle);
    assertNotNull(bundle.getLink(Constants.LINK_SELF));
    assertNotNull(bundle.getLink(Constants.LINK_FIRST));
    firstLink = UriComponentsBuilder.fromUriString(bundle.getLink(Constants.LINK_FIRST).getUrl()).build();
    assertEquals("10", firstLink.getQueryParams().getFirst(Constants.PARAM_COUNT));
    assertNull(bundle.getLink(Constants.LINK_NEXT));
}
Also used : PatientLinkBuilder(gov.cms.bfd.server.war.commons.PatientLinkBuilder) UriComponents(org.springframework.web.util.UriComponents) Bundle(org.hl7.fhir.dstu3.model.Bundle) Reference(org.hl7.fhir.dstu3.model.Reference) Patient(org.hl7.fhir.dstu3.model.Patient) Coverage(org.hl7.fhir.dstu3.model.Coverage) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) Test(org.junit.jupiter.api.Test)

Example 9 with PatientLinkBuilder

use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.

the class PatientLinkBuilderTest method fullPageTest.

@Test
public void fullPageTest() {
    // test a page with a page size of 1 and 1 patient in the result
    PatientLinkBuilder paging = new PatientLinkBuilder(TEST_CONTRACT_URL + "&_count=1");
    assertTrue(paging.isPagingRequested());
    assertTrue(paging.isFirstPage());
    assertEquals(1, paging.getPageSize());
    Bundle bundle = new Bundle();
    Patient patient = new Patient();
    patient.setId("1");
    TransformerUtils.addResourcesToBundle(bundle, Collections.singletonList(patient));
    assertTrue(bundle.getLink().isEmpty());
    paging.addLinks(bundle);
    assertNotNull(bundle.getLink(Constants.LINK_SELF));
    assertNotNull(bundle.getLink(Constants.LINK_FIRST));
    assertNull(bundle.getLink(Constants.LINK_NEXT));
}
Also used : PatientLinkBuilder(gov.cms.bfd.server.war.commons.PatientLinkBuilder) Bundle(org.hl7.fhir.dstu3.model.Bundle) Patient(org.hl7.fhir.dstu3.model.Patient) Test(org.junit.jupiter.api.Test)

Example 10 with PatientLinkBuilder

use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.

the class PatientLinkBuilderTest method emptyCursorTest.

@Test
public void emptyCursorTest() {
    PatientLinkBuilder paging = new PatientLinkBuilder(TEST_CONTRACT_URL + "&_count=10&cursor=");
    assertTrue(paging.isPagingRequested());
    assertTrue(paging.isFirstPage());
    assertEquals(10, paging.getPageSize());
}
Also used : PatientLinkBuilder(gov.cms.bfd.server.war.commons.PatientLinkBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

PatientLinkBuilder (gov.cms.bfd.server.war.commons.PatientLinkBuilder)11 Bundle (org.hl7.fhir.dstu3.model.Bundle)8 Test (org.junit.jupiter.api.Test)8 Patient (org.hl7.fhir.dstu3.model.Patient)5 Description (ca.uhn.fhir.model.api.annotation.Description)3 IdDt (ca.uhn.fhir.model.primitive.IdDt)3 IdParam (ca.uhn.fhir.rest.annotation.IdParam)3 OptionalParam (ca.uhn.fhir.rest.annotation.OptionalParam)3 Read (ca.uhn.fhir.rest.annotation.Read)3 RequiredParam (ca.uhn.fhir.rest.annotation.RequiredParam)3 Search (ca.uhn.fhir.rest.annotation.Search)3 RequestDetails (ca.uhn.fhir.rest.api.server.RequestDetails)3 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)3 TokenParam (ca.uhn.fhir.rest.param.TokenParam)3 IResourceProvider (ca.uhn.fhir.rest.server.IResourceProvider)3 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)3 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)3 MetricRegistry (com.codahale.metrics.MetricRegistry)3 Timer (com.codahale.metrics.Timer)3 Strings (com.google.common.base.Strings)3