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

BDR and NIA adjustments #951

Merged
merged 17 commits into from
Jan 29, 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
6 changes: 6 additions & 0 deletions packages/ghana-bdr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @openfn/language-ghana-bdr

## 0.1.2

### Patch Changes

- 5e3b3cf: Updates to the mock endpoint, these are still moving targets

## 0.1.1

### Patch Changes
Expand Down
3 changes: 2 additions & 1 deletion packages/ghana-bdr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/language-ghana-bdr",
"version": "0.1.1",
"version": "0.1.2",
"description": "OpenFn ghana-bdr adaptor",
"type": "module",
"exports": {
Expand Down Expand Up @@ -29,6 +29,7 @@
],
"dependencies": {
"@openfn/language-common": "workspace:*",
"ajv": "^6.12.6",
"undici": "^5.22.1"
},
"devDependencies": {
Expand Down
162 changes: 91 additions & 71 deletions packages/ghana-bdr/src/mock.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,84 @@
import { MockAgent } from 'undici';
import { validateRequestBody } from './util';

const birthNotificationResponse = {
registry_code: '1',
// import Ajv from 'ajv';
// // Generated from sample with https://www.jsongenerator.io/schema
// // But!! I had to replace $schema with $id
// // Note: use import() or ele src build breaks
// const reqSchemaString = import('./schema/request.json');
// const reqSchema = JSON.parse(reqSchemaString);
// const validate = new Ajv().compile(reqSchema);

const sampleRequestBody = {
registry_code: '011803',
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,
first_name: 'Test',
middle_name: '',
Surname: 'Testerson',
birth_date: '2024/03/04',
birth_type_code: '1',
gender_code: '2',
place_of_delivery_code: '7',
attendant_at_birth_code: '1',
attendant_at_birth_other: null,
birth_attendant_full_name: 'Dr Lawrence Kwame',
birth_attendant_phone: '0556969609',
bith_attendant_full_name: 'Helen',
bith_attendant_phone: '0248403076',
},
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,
national_id_number: 'GHA-000000000-2',
first_name: 'fake',
middle_name: '',
maiden_name: 'fakerson',
phone: '0248403076',
occupation_code: '29',
age: 25,
},
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',
},
birth_informant: {
relationship_code: '2',
relationship_other: null,
full_name: 'Kufor Mensa',
phone: '055646874',
digital_address: 'No. 64 Ajiringanor',
national_id_number: '993993939-0303',
national_id_number: '',
first_name: 'john',
middle_name: '',
Surname: 'doe',
phone: '0248403076',
occupation_code: '115',
age: 39,
},
};

const birthNotificationResponse = {
birth_certificate_number: '000000-00-2024',
first_name: 'Test',
middle_name: '',
Surname: 'sample surname',
birth_date: '04 Mar 2024',
national_id_number: '',
place_of_delivery: 'MATERNITY HOME',
Health_facility: '',
birth_type: null,
gender: 'MALE',
house_number: '',
street_name: '',
district: '',
region: '',
town_or_village: '',
m_first_name: 'sample mom',
m_middle_name: '',
m_maiden_name: 'sample surname',
m_surname: '',
m_national_id_number: 'GHA-000000000-0',
m_nationality: '',
f_first_name: 'father fname',
f_middle_name: '',
f_Surname: 'father sur',
f_nationality: '',
f_national_id_number: '',
reference_id: 'abc123de-1995',
document_number: '1995/000000/XX0000000A1B2C3',
created_at: '05 Mar 2024',
last_updated_at: null,
issuccessful: true,
message: 'record reference_id : abc123de-1995 , created successfully',
messagecode: '200',
};

// This creates a mock bdr server
// It should present the same rest API as BDR-MOH-GHS
export function createServer(url = 'http://tracker.chimgh.org') {
Expand All @@ -84,13 +88,29 @@ export function createServer(url = 'http://tracker.chimgh.org') {
const mockPool = agent.get(url);

const sendBirthNotification = req => {
return {
statusCode: 200,
responseOptions: {
headers: { 'Content-Type': 'application/json' },
},
data: JSON.stringify(birthNotificationResponse),
};
// if (validate(JSON.parse(req.body))) {
if (validateRequestBody(JSON.parse(req.body), sampleRequestBody)) {
return {
statusCode: 200,
responseOptions: {
headers: { 'Content-Type': 'application/json' },
},
// Note the double stringification from BDR
data: JSON.stringify(JSON.stringify(birthNotificationResponse)),
};
} else {
// console.log('Validation errors:', validate.errors);
return {
statusCode: 417,
responseOptions: {
headers: { 'Content-Type': 'application/json' },
},
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.)',
},
};
}
};

mockPool
Expand Down
65 changes: 65 additions & 0 deletions packages/ghana-bdr/src/samples/v2-requestBody.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"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"
}
}
Loading