Skip to content

Commit

Permalink
Disable caching when making get requests to the fhir server. (#1307)
Browse files Browse the repository at this point in the history
* Make it possible to add caching headers to fhir server service

* Hardcode cache headers on the fhirservice

* Fix test regressions
  • Loading branch information
peterMuriuki authored Dec 7, 2023
1 parent 63b4746 commit cd3facc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/react-utils/src/helpers/dataLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,16 @@ export class FHIRServiceClass<T extends IResource> {
const accessToken = await OpenSRPService.processAcessToken(this.accessTokenOrCallBack);
const queryStr = this.buildQueryParams(params);
const serve = FHIR.client(this.buildState(accessToken));
return serve.request<T>(queryStr);
return serve.request<T>({ url: queryStr, headers: { 'cache-control': 'no-cache' } });
}

public async read(id: string) {
const accessToken = await OpenSRPService.processAcessToken(this.accessTokenOrCallBack);
const serve = FHIR.client(this.buildState(accessToken));
return serve.request<T>(`${this.resourceType}/${id}`);
return serve.request<T>({
url: `${this.resourceType}/${id}`,
headers: { 'cache-control': 'no-cache' },
});
}

public async delete(id: string) {
Expand Down
22 changes: 20 additions & 2 deletions packages/react-utils/src/helpers/tests/dataLoaders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,16 @@ describe('dataloaders/FHIRService', () => {
const fhir = new FHIRServiceClass<fhirR4.CareTeam>('https://test.fhir.org', 'CareTeam');
const result = await fhir.list();
await flushPromises();
expect(requestMock.mock.calls).toEqual([['CareTeam']]);
expect(requestMock.mock.calls).toEqual([
[
{
headers: {
'cache-control': 'no-cache',
},
url: 'CareTeam',
},
],
]);
expect(result).toEqual(fixtures.careTeams);
// make sure every item of fhirlist returns the CareTeam
expect(result.entry.every((e) => e.resource.resourceType === 'CareTeam')).toBeTruthy();
Expand All @@ -239,7 +248,16 @@ describe('dataloaders/FHIRService', () => {
// without url params
const result = await fhir.list({ _count: '100' });
await flushPromises();
expect(requestMock.mock.calls).toEqual([['CareTeam/_search?_count=100']]);
expect(requestMock.mock.calls).toEqual([
[
{
headers: {
'cache-control': 'no-cache',
},
url: 'CareTeam/_search?_count=100',
},
],
]);
expect(result).toEqual(fixtures.careTeams);
// make sure every item of fhirlist returns the CareTeam
expect(result.entry.every((e) => e.resource.resourceType === 'CareTeam')).toBeTruthy();
Expand Down

0 comments on commit cd3facc

Please sign in to comment.