Skip to content

Commit bdaafe7

Browse files
committed
use faker to generate realistic names
1 parent 98b57e5 commit bdaafe7

4 files changed

Lines changed: 19 additions & 136 deletions

File tree

mediator/package-lock.json

Lines changed: 12 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mediator/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"body-parser": "^1.20.1",
2626
"dotenv": "^16.0.3",
2727
"express": "^4.18.2",
28+
"faker": "^5.5.3",
2829
"fhir": "^4.11.2",
2930
"joi": "^17.7.0",
3031
"morgan": "^1.10.0",

mediator/src/utils/cht.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import axios from 'axios';
22
import { CHT } from '../../config';
33
import { generateBasicAuthUrl } from './url';
44
import https from 'https';
5-
import path from 'path';
65
import qs from 'qs';
76
import { logger } from '../../logger';
87

mediator/src/utils/openimis.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { logger } from '../../logger';
55
import { createChtOpenImisRecord } from './cht';
66
import { addOpenIMISId, getContactDocumentByPhone, PatientInfo } from './db';
77
import NepaliDate from 'nepali-datetime';
8+
const faker = require('faker');
89

910
interface LoginResponse {
1011
token: string;
@@ -101,24 +102,16 @@ export const createPerson = async (claimResponse: ClaimResponse, phone: string)
101102
form: 'N',
102103
from: '+9779841171819',
103104
},
104-
age_in_years: 22,
105+
age_in_years: faker.datatype.number({ min: 1, max: 100 }),
105106
patient_phone: phone,
106-
patient_name: generateRandomString(10)
107+
patient_name: await generateRandomName()
107108
};
108109
return await createChtOpenImisRecord(record);
109110
};
110111

111-
const generateRandomString = (
112-
length = 10,
113-
characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
114-
): string => {
115-
let result = '';
116-
const charactersLength = characters.length;
117-
for (let i = 0; i < length; i++) {
118-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
119-
}
120-
121-
return result;
112+
const generateRandomName = async (
113+
): Promise<string> => {
114+
return `${faker.name.firstName()} ${faker.name.lastName()}`;
122115
};
123116

124117
const pushClaimToCht = async (claimResponse: ClaimResponse, patient: any) => {

0 commit comments

Comments
 (0)