Skip to content

Commit

Permalink
Merge pull request #129 from samuelmale/fix-tests
Browse files Browse the repository at this point in the history
(chore) Apply Linting and Resolve Test Failures
  • Loading branch information
ashaban authored Jan 30, 2024
2 parents 15a3465 + 3c65454 commit 3d8216c
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 15 deletions.
14 changes: 12 additions & 2 deletions server/__tests__/otherResources/potentialMatches.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[{
[
{
"id": "433ebeb6-1d89-4b64-97e6-a985675ca571",
"gender": "male",
"given": "Emanuel",
"family": "Joshua",
"birthDate": "1972-01-08",
"uid": "eda0fdeb-1d52-4878-a84f-ccf581ef9fff",
"ouid": "eda0fdeb-1d52-4878-a84f-ccf581ef9fff",
"identifier_http://clientregistry.org/openmrs": "patient3",
"identifier_http://health.go.ug/cr/nationalid": "228374844",
"identifier_http://system1.org": "12347",
"phone": "0678 56160",
"source_id": "patient3",
"source": "OpenMRS",
Expand All @@ -22,6 +26,9 @@
"birthDate": "1972-01-08",
"uid": "739d4023-40eb-4f44-8d14-3355926bd60d",
"ouid": "739d4023-40eb-4f44-8d14-3355926bd60d",
"identifier_http://clientregistry.org/openmrs": "patient1",
"identifier_http://health.go.ug/cr/nationalid": "228374844",
"identifier_http://system1.org": "12347",
"phone": "0678 561608",
"source_id": "patient1",
"source": "OpenMRS",
Expand All @@ -38,6 +45,9 @@
"birthDate": "1972-01-08",
"uid": "42184bd9-1c0c-41ce-9188-f57341ca9e88",
"ouid": "42184bd9-1c0c-41ce-9188-f57341ca9e88",
"identifier_http://clientregistry.org/openmrs": "patient2",
"identifier_http://health.go.ug/cr/nationalid": "228374844",
"identifier_http://system1.org": "12347",
"phone": "0678 561608",
"source_id": "patient2",
"source": "OpenMRS",
Expand All @@ -46,4 +56,4 @@
"patient3": 2
}
}
]
]
7 changes: 5 additions & 2 deletions server/__tests__/route-fhir-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ describe( "Testing express", () => {
axios.__setFhirResults( `${ES_BASE_URL}/_doc/d55e15fd-d7a6-42b8-89cc-560e3578ef7f`, require("./ESResources/cacheRequest-d55e15fd-d7a6-42b8-89cc-560e3578ef7f.json"), require("./ESResources/cacheResults-d55e15fd-d7a6-42b8-89cc-560e3578ef7f.json"));
axios.__setFhirResults( `${ES_BASE_URL}/_doc/433ebeb6-1d89-4b64-97e6-a985675ca571`, require("./ESResources/cacheRequest-433ebeb6-1d89-4b64-97e6-a985675ca571.json"), require("./ESResources/cacheResults-433ebeb6-1d89-4b64-97e6-a985675ca571.json"));
return supertest(app)
.post("/Patient").set("x-openhim-clientid", "openmrs").send(PATIENT3).then( (response) => {
expect(response.headers.location).toEqual("Patient/eda0fdeb-1d52-4878-a84f-ccf581ef9fff");
.post("/Patient").set("x-openhim-clientid", "openmrs").send(PATIENT3).then( (response) => {
// verify patient ID
expect(response.headers.location).toEqual("Patient/433ebeb6-1d89-4b64-97e6-a985675ca571");
// verify golden record ID
expect(response.headers.locationcruid).toEqual("Patient/eda0fdeb-1d52-4878-a84f-ccf581ef9fff");
} );
} );

Expand Down
76 changes: 73 additions & 3 deletions server/__tests__/route-match-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const ES_BASE_URL = URI(config.get('elastic:server')).segment(config.get('elasti
const supertest = require("supertest");

const route = require("../lib/routes/match");
const { buildQuery } = require("../lib/esMatching");

const express = require('express');
const app = express();
Expand Down Expand Up @@ -176,12 +177,81 @@ describe( "Testing express", () => {
//testing getting potential matches
test( "Testing Getting Potential Matches", () => {
const potentialMatches = require("./otherResources/potentialMatches.json");
request.__setFhirResults( `${FHIR_BASE_URL}/Patient/433ebeb6-1d89-4b64-97e6-a985675ca571`, null, JSON.stringify(require("./FHIRResources/patient3.json")) );
const decisionRules = config.get("rules");

request.__setFhirResults(
`${FHIR_BASE_URL}/Patient/433ebeb6-1d89-4b64-97e6-a985675ca571`,
null,
JSON.stringify(require("./FHIRResources/patient3.json"))
);
request.__setFhirResults(
`${FHIR_BASE_URL}/Patient/bc58707b-62f1-498a-8fb3-568cd5b69db2`,
null,
JSON.stringify(require("./FHIRResources/patient1.json"))
);
request.__setFhirResults(
`${FHIR_BASE_URL}/Patient/d55e15fd-d7a6-42b8-89cc-560e3578ef7f`,
null,
JSON.stringify(require("./FHIRResources/patient2.json"))
);

// fhir search results for potential matches
request.__setFhirResults(
`${FHIR_BASE_URL}/Patient?_id=bc58707b-62f1-498a-8fb3-568cd5b69db2,d55e15fd-d7a6-42b8-89cc-560e3578ef7f`,
null,
JSON.stringify({
entry: [
require("./FHIRResources/patient1andlinkAfterBrokenMatchWithoutRematch.json")
.entry[0],
require("./FHIRResources/patient2andlinkAfterBrokenMatchWithoutRematch.json")
.entry[0],
],
})
);
request.__setFhirResults(
`${FHIR_BASE_URL}/Patient?_id=bc58707b-62f1-498a-8fb3-568cd5b69db2&_include=Patient:link`,
null,
JSON.stringify(
require("./FHIRResources/patient1andlinkAfterBrokenMatchWithoutRematch.json")
)
);
request.__setFhirResults(
`${FHIR_BASE_URL}/Patient?_id=d55e15fd-d7a6-42b8-89cc-560e3578ef7f&_include=Patient:link`,
null,
JSON.stringify(
require("./FHIRResources/patient2andlinkAfterBrokenMatchWithoutRematch.json")
)
);
request.__setFhirResults(
`${FHIR_BASE_URL}/Patient?_id=433ebeb6-1d89-4b64-97e6-a985675ca571`,
null,
JSON.stringify(
require("./FHIRResources/patient3andlinkAfterBrokenMatchWithoutRematch.json")
)
);
axios.__setFhirResults(
`${ES_BASE_URL}/_search?scroll=1m&size=1000`,
buildQuery(require("./FHIRResources/patient3.json"), decisionRules[0]),
require("./ESResources/searchresultsforpatient3.json")
);
axios.__setFhirResults(
`${ES_BASE_URL}/_search?scroll=1m&size=1000`,
buildQuery(require("./FHIRResources/patient2.json"), decisionRules[0]),
require("./ESResources/searchresultsforpatient2.json")
);
axios.__setFhirResults(
`${ES_BASE_URL}/_search?scroll=1m&size=1000`,
buildQuery(require("./FHIRResources/patient1.json"), decisionRules[0]),
require("./ESResources/searchresultsforpatient1.json")
);

return supertest(app)
.get("/potential-matches/433ebeb6-1d89-4b64-97e6-a985675ca571").send().then( (response) => {
.get("/potential-matches/433ebeb6-1d89-4b64-97e6-a985675ca571")
.send()
.then((response) => {
expect(response.statusCode).toBe(200);
expect(response.body).toEqual(potentialMatches);
} );
});
});

test( "Testing Getting Match Issues", () => {
Expand Down
13 changes: 5 additions & 8 deletions server/lib/esMatching.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,11 @@ const getESDocument = (query, callback) => {
let scroll_id = null;
async.doWhilst(
(callback) => {
axios({
method: 'POST',
url,
data: query,
axios.post(url, query, {
auth: {
username: config.get('elastic:username'),
password: config.get('elastic.password'),
}
username: config.get("elastic:username"),
password: config.get("elastic.password"),
},
}).then((response) => {
if(response.data.hits && response.data.hits.hits && Array.isArray(response.data.hits.hits)) {
documents = documents.concat(response.data.hits.hits);
Expand All @@ -232,7 +229,6 @@ const getESDocument = (query, callback) => {
logger.warn('ES is overloaded with too many requests, delaying for 2 seconds');
setTimeout(() => {
return callback(null);

}, 2000);
} else {
error = err;
Expand Down Expand Up @@ -495,6 +491,7 @@ const performMatch = ({
};

module.exports = {
buildQuery,
performMatch,
refreshIndex
};

0 comments on commit 3d8216c

Please sign in to comment.