Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable caching when making get requests to the fhir server. #1307

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading