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

Fhir api tests #65

Merged
merged 44 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4129434
trying new tests (weird results)
acholyn Sep 28, 2022
682e51f
Don't mock fetch in api tests
stefpiatek Sep 28, 2022
20c6cb8
Merge pull request #55 from gosh-dre/dont_mock_fetch
acholyn Sep 29, 2022
7025eb6
allowing cascading deletes and minimising cache
acholyn Oct 3, 2022
accb875
updates to tests: checking api empty before each & checking correct p…
acholyn Oct 3, 2022
f27156c
abstracted deletion method to accept bundle or string id
acholyn Oct 4, 2022
5c918c5
attempt to fix iffy pass/fail - await
acholyn Oct 4, 2022
e773148
adding quotes to true value
acholyn Oct 5, 2022
3c6c4f8
fixes and updates to make deletion more stable
acholyn Oct 5, 2022
feef93f
updating getPatients method
acholyn Oct 5, 2022
031f8f9
test to check updated info persists
acholyn Oct 6, 2022
bb735bc
updating comments
acholyn Oct 6, 2022
a0d3707
updated info persists, tests are happy
acholyn Oct 6, 2022
7827074
updating bundle type info
acholyn Oct 6, 2022
9ca3d35
Merge branch 'main' into fhir-api-tests
acholyn Oct 6, 2022
dcf24b4
fixing typing errors
acholyn Oct 6, 2022
0acc63d
adding small timeout to bundle sending
acholyn Oct 6, 2022
c74bd48
increasing timeout
acholyn Oct 6, 2022
52fd57a
increasing timeout further
acholyn Oct 6, 2022
dcb50ef
Debug and allow jest to set longer timeout
stefpiatek Oct 6, 2022
2d620aa
Cascade awaits and expand else branches
stefpiatek Oct 6, 2022
d7b104b
Add typing to help with debugging
stefpiatek Oct 6, 2022
6dffaa1
Add curl to check fhir api is ready for use in CI
stefpiatek Oct 6, 2022
5c875d5
Slim down delete bundle while fixing typing
stefpiatek Oct 6, 2022
a947b9d
Try setting env variable for fhir url during tests
stefpiatek Oct 6, 2022
34758bd
Debug output of json response
stefpiatek Oct 6, 2022
1dbb82d
Debug output of json response
stefpiatek Oct 6, 2022
9af80fd
trim down getPatients
acholyn Oct 6, 2022
3a43d58
Ensure organisation is before patient in bundle
stefpiatek Oct 6, 2022
8095e0f
Merge remote-tracking branch 'origin/fhir-api-tests' into fhir-api-tests
stefpiatek Oct 6, 2022
8f476ac
removing lines from debugging
acholyn Oct 6, 2022
a747e9c
removing unnecessary code
acholyn Oct 6, 2022
b748896
updated checkResponseOK
acholyn Oct 7, 2022
9529e29
Merge branch 'fhir-api-tests' of github.com:gosh-dre/gmsa_genomic_fhi…
acholyn Oct 7, 2022
3391b4d
allow response status not to exist
acholyn Oct 7, 2022
9720a0b
cleaning up unused imports
acholyn Oct 7, 2022
5413f24
attending to ci error
acholyn Oct 7, 2022
b648ffb
updated error searching
acholyn Oct 10, 2022
3e8ae00
updated if in checkResponseOK
acholyn Oct 10, 2022
a922a69
moved if earlier to break faster
acholyn Oct 10, 2022
e487890
increasing timeout for ci
acholyn Oct 10, 2022
5975f32
moved BundleResponse to types.ts
acholyn Oct 10, 2022
6f9cc97
Update src/fhir/api.test.ts
acholyn Oct 10, 2022
bc627fc
consolidating divergent branches
acholyn Oct 10, 2022
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
2 changes: 2 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ services:
hapi.fhir.client_id_strategy: ANY
hapi.fhir.cors.allowed_origin: "*"
hapi.fhir.fhir_version: R4
hapi.fhir.allow_cascading_deletes: true
hapi.fhir.reuse_cached_search_results_millis: -1
fhir-db:
image: postgres:latest
volumes:
Expand Down
88 changes: 86 additions & 2 deletions src/fhir/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,92 @@ import { geneCoding } from "../code_systems/hgnc";
const fhir = new Fhir();

const reportedGenes = [geneCoding("HGNC:4389", "GNA01")];
const FHIR_URL = process.env.REACT_APP_FHIR_URL || "";

const getPatients = async () => {
const url = `${FHIR_URL}/Patient`;
const response = await fetch(url);
if (!response.ok) {
console.error(response.statusText);
console.error(response.body);
throw new Error(response.statusText);
}
return await response.json();
};

const check = async (response: any) => {
// would like to figure out which type response should be
const r = await response.json();
console.error(r.body);
};

const deletePatients = async (patientId?: string) => {
/**
* This method can take a string to delete a particular patient's records
* or it can accept a bundle with a number of entries from which
* it will extract the ID(s) and delete the patient(s)
*/
const baseURL = `${FHIR_URL}/Patient`;
const patientData = await getPatients();
if (!("entry" in patientData)) {
return;
}

const deletePatientEntry = async (entry: any) => {
let id;
if (typeof entry === "string") {
console.info("entry is string", patientId);
return (id = patientId);
}
id = entry[0].resource.id;
console.info("deleting records related to " + id);
const response = await fetch(`${baseURL}/${id}?_cascade=delete`, {
method: "DELETE",
});
if (!response.ok) {
console.error(response.statusText);
console.error(response.body);
}
check(response);
await new Promise((r) => setTimeout(r, 1500));
};

const patientEntry = patientData.entry;
deletePatientEntry(patientEntry);
};

describe("FHIR resources", () => {
beforeEach(async () => {
fetchMock.dontMock();
await deletePatients();
});

test("database is clear on setup", async () => {
/**
* Before doing tests on the database, we want to clear all its data
*/

const postDelete = await getPatients();
expect("entry" in postDelete).toBeFalsy();
});

test("bundle creates patient", async () => {
const bundle = createBundle(initialValues, reportedGenes);

const createPatient = await fetch(`${FHIR_URL}/`, {
method: "POST",
body: JSON.stringify(bundle),
headers: {
"Content-Type": "application/json",
},
});

check(createPatient);
const patientData = await getPatients();
expect("entry" in patientData).toBeTruthy();
expect(patientData.entry[0].resource.identifier[0].value).toEqual(initialValues.patient.mrn);
});

/**
* Given that form data has been correctly populated
* When a FHIR bundle is created
Expand All @@ -19,7 +103,7 @@ describe("FHIR resources", () => {

const output = fhir.validate(bundle);
console.info("Validation output");
console.info(JSON.stringify(output.messages, null, 2));
// console.info(JSON.stringify(output.messages, null, 2));
expect(output.valid).toBeTruthy();
});

Expand All @@ -46,7 +130,7 @@ describe("FHIR resources", () => {
// fhir validation
const output = fhir.validate(bundle);
console.info("Validation output");
console.info(JSON.stringify(output.messages, null, 2));
// console.info(JSON.stringify(output.messages, null, 2));
expect(output.valid).toBeTruthy();
});
});