-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
6 changed files
with
149 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import joi from 'joi'; | ||
|
||
export const ChtPatientSchema = joi.object({ | ||
doc: joi.object({ | ||
_id: joi.string().uuid().required(), | ||
name: joi.string().required(), | ||
phone: joi.string().required(), | ||
date_of_birth: joi.string().required(), | ||
sex: joi.string().required(), | ||
patient_id: joi.string().required() | ||
}).required() | ||
}); | ||
|
||
export const ChtPatientIdsSchema = joi.object({ | ||
doc: joi.object({ | ||
patient_id: joi.string().required(), | ||
external_id: joi.string().required() | ||
}) | ||
}); | ||
|
||
export const ValueTypeSchema = joi.object({ | ||
code: joi.string().required(), | ||
valueString: joi.string(), | ||
valueCode: joi.string(), | ||
valueBoolean: joi.boolean(), | ||
valueInteger: joi.number().integer(), | ||
valueDateTime: joi.string().isoDate(), | ||
valueTime: joi.string().regex(/^([01]\d|2[0-3]):([0-5]\d)(:[0-5]\d(\.\d{1,3})?)?$/), // matches HH:mm[:ss[.SSS]] | ||
valueQuantity: joi.object({ | ||
value: joi.number().required(), | ||
unit: joi.string().required(), | ||
system: joi.string().uri().optional(), | ||
code: joi.string().optional() | ||
}) | ||
}).or('valueString', 'valueCode', 'valueBoolean', 'valueInteger', 'valueDateTime', 'valueTime', 'valueQuantity'); | ||
|
||
export const ChtEncounterFormSchema = joi.object({ | ||
patient_uuid: joi.string().required(), | ||
reported_date: joi.number().required(), //timestamp | ||
observations: joi.array().items(ValueTypeSchema).optional() | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import request from 'supertest'; | ||
import app from '../../..'; | ||
import { ChtPatientFactory, ChtPatientIdsFactory, ChtPregnancyForm } from '../../middlewares/schemas/tests/cht-request-factories'; | ||
|
||
describe('POST /cht/patient', () => { | ||
it('doesn\'t accept incoming request with invalid patient resource', async () => { | ||
const data = ChtPatientFactory.build(); | ||
delete data.doc._id; | ||
|
||
const res = await request(app).post('/cht/patient').send(data); | ||
|
||
expect(res.status).toBe(400); | ||
expect(res.body.valid).toBe(false); | ||
expect(res.body.message).toMatchInlineSnapshot( | ||
`""doc._id" is required"` | ||
); | ||
}); | ||
}); | ||
|
||
describe('POST /cht/patient_ids', () => { | ||
it('doesn\'t accept incoming request with invalid patient resource', async () => { | ||
const data = ChtPatientIdsFactory.build(); | ||
delete data.doc.patient_id; | ||
|
||
const res = await request(app).post('/cht/patient_ids').send(data); | ||
|
||
expect(res.status).toBe(400); | ||
expect(res.body.valid).toBe(false); | ||
expect(res.body.message).toMatchInlineSnapshot( | ||
`""doc.patient_id" is required"` | ||
); | ||
}); | ||
}); | ||
|
||
describe('POST /cht/encounter', () => { | ||
it('doesn\'t accept incoming request with invalid form', async () => { | ||
const data = ChtPregnancyForm.build(); | ||
|
||
// push an invalid observation | ||
data.observations.push({ | ||
"code": "17a57368-5f59-42c8-aaab-f2774d21501e", | ||
"valueDateTime": "This is not a valid date" | ||
}) | ||
|
||
const res = await request(app).post('/cht/encounter').send(data); | ||
|
||
expect(res.status).toBe(400); | ||
expect(res.body.valid).toBe(false); | ||
expect(res.body.message).toMatchInlineSnapshot( | ||
`""observations[13].valueDateTime" must be in iso format"` | ||
); | ||
}); | ||
}); |