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

Ghana json schema #952

Merged
merged 3 commits into from
Jan 28, 2025
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
1 change: 1 addition & 0 deletions packages/ghana-bdr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
],
"dependencies": {
"@openfn/language-common": "workspace:*",
"ajv": "^6.12.6",
"undici": "^5.22.1"
},
"devDependencies": {
Expand Down
77 changes: 10 additions & 67 deletions packages/ghana-bdr/src/mock.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,11 @@
import { MockAgent } from 'undici';
import { validateRequestBody } from '../../../tools/mock-validator.js';

const sampleRequestBody = {
child: {
first_name: 'Nana',
middle_name: 'Nana',
Surname: 'Kumasi',
birth_date: '2023/10/22',
national_id_number: '90282901892',
place_of_delivery_code: '2',
place_of_delivery_other: null,
birth_type_code: '1',
gender_code: '2',
attendant_at_birth_code: '1',
attendant_at_birth_other: null,
bith_attendant_full_name: 'Dr Lawrence Kwame',
bith_attendant_phone: '0556969609',
},
mother: {
first_name: 'Nana',
middle_name: 'Nana',
maiden_name: 'Nana',
surname_or_marriage_name: 'Nana',
phone: '05673673673',
age: 35,
national_id_number: '90-030-003',
nationality_code: '131',
house_number: 'No 4536',
street_name: 'Accra city Ghana',
district_code: '10',
region_code: '10',
town_or_village: 'Ajiringanor',
number_of_children_ever_born_alive: 5,
born_alive_are_living: 5,
live_birth_order: 5,
born_alive_are_dead: 0,
education_level_code: '6',
education_level_other: null,
occupation_code: '13',
occupation_other: null,
},
father: {
first_name: 'Kufor',
middle_name: 'Kufor',
surname: 'Mensa',
nationality_code: '131',
national_id_number: '88-9292-92092',
phone: '05673673737',
age: 38,
education_level_code: '13',
occupation_code: '13',
religion_code: '1',
education_level_other: null,
occupation_other: null,
religion_other: null,
is_gainfully_employed_code: '1',
},
health_facility: {
name: 'Korlebu General Hospital',
house_number: 'No 4536',
street_name: 'Adjiringano',
town_code: '12',
town_other: null,
district_code: '11',
region_code: '12',
},
};
// Generated from sample with https://www.jsongenerator.io/schema
// But!! I had to replace $schema with $id
import reqSchema from './schema/request.json' assert { type: 'json' };
import Ajv from 'ajv';

const validate = new Ajv().compile(reqSchema);

const birthNotificationResponse = {
birth_certificate_number: '000000-00-2024',
Expand Down Expand Up @@ -112,7 +52,7 @@ export function createServer(url = 'http://tracker.chimgh.org') {
const mockPool = agent.get(url);

const sendBirthNotification = req => {
if (validateRequestBody(JSON.parse(req.body), sampleRequestBody)) {
if (validate(JSON.parse(req.body))) {
return {
statusCode: 200,
responseOptions: {
Expand All @@ -121,6 +61,7 @@ export function createServer(url = 'http://tracker.chimgh.org') {
data: JSON.stringify(birthNotificationResponse),
};
} else {
console.log('Validation errors:', validate.errors);
return {
statusCode: 417,
responseOptions: {
Expand All @@ -129,6 +70,8 @@ export function createServer(url = 'http://tracker.chimgh.org') {
data: {
Message:
'{"issuccessful":false,"message":"Record failed to save with this error --> Modify the clause to make sure that a column is updated only once. If this statement updates or inserts columns into a view, column aliasing can conceal the duplication in your code.","messagecode":"210"} (Note that this is just a sample error from a mock endpoint.)',
// from the mock:
_errors: validate.errors,
},
};
}
Expand Down
Loading
Loading