department-of-veterans-affairs / va.gov-team

Public resources for building on and in support of VA.gov. Visit complete Knowledge Hub:
https://depo-platform-documentation.scrollhelp.site/index.html
284 stars 206 forks source link

CES-457: CES: Use mobile-mvi-service cache-control headers to retrieve cached patient identifiers #82548

Closed BrittanySFowler closed 5 months ago

BrittanySFowler commented 6 months ago

CES-457: https://issues.mobilehealth.va.gov/browse/CES-457

As a Developer, I want to improve the latency and reliability of patient and staff identifier retrieval from Mobile MVI Service.

Mobile MVI Service 1.28+ now supports Cache-Control headers to optionally retrieve cached identifiers, and to return cached identifiers in the case of an error response from MVI:

    final ResponseEntity<List<PersonIdentifier>> staffIdentifiersResponse = mviApi
            .getStaffIdentifiersWithHttpInfo(
                    idType,
                    id,
                    SENDER_ID,
                    null,
                    null,
                    CacheControl
                            .maxAge(Duration.ofHours(1))
                            .staleIfError(Duration.ofHours(12))
                            .getHeaderValue()
            );

    // example of getting the data age:
    final List<String> ageHeader = staffIdentifiersResponse.getHeaders().get(HttpHeaders.AGE);
    int ageSeconds = 0;
    if (isNotEmpty(ageHeader)) {
        ageSeconds = Integer.parseInt(ageHeader.get(0));
    }

Acceptance Criteria:

Any time that CES retrieves patient identifiers from Mobile MVI Service, it requests a response from cache first if the data was cached within the last 6 hours, then falls back to live MPI data, then falls back to the cache if the live call fails and the data was cached within the last 48 hours. Uses a cache-control header value of "max-age: 21600, stale-if-error: 172800" Allow overriding the default max age with MVI_PATIENT_IDS_CACHE_MAX_AGE Allow overriding the default stale-if-error with MVI_PATIENT_IDS_CACHE_STALE_IF_ERROR Any time that CES retrieves staff identifiers from Mobile MVI Service, it requests a response from cache first if the data was cached within the last 2 hours, then falls back to live MPI data, then falls back to the cache if the live call fails and the data was cached within the last 48 hours. Uses a cache-control header value of "max-age: 7200, stale-if-error: 172800" Allow overriding the default max age with MVI_STAFF_IDS_CACHE_MAX_AGE Allow overriding the default stale-if-error with MVI_STAFF_IDS_CACHE_STALE_IF_ERROR

BrittanySFowler commented 6 months ago

This work is blocked by CES-318 and we will do it in the upcoming sprint