Skip to content

Commit ed1927b

Browse files
feat: contryconfig function for all id-reader fields (#48)
* feat: provide alternative where all id reader fields come from a single function output * chore: bump package version * chore: update verification statuses * chore: update id reader label * chore: update verified logic to checking on stubbed ids * chore: update logic so that if the id is not found in the stubbed valid ids, set verified status failed * chore: update mapping of id reader field
1 parent ba137ef commit ed1927b

File tree

8 files changed

+137
-22
lines changed

8 files changed

+137
-22
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opencrvs/mosip",
3-
"version": "1.7.0-alpha.16",
3+
"version": "1.7.0-alpha.17",
44
"license": "MPL-2.0",
55
"private": true,
66
"packageManager": "yarn@1.22.13",

packages/country-config/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opencrvs/mosip",
3-
"version": "1.7.0-alpha.16",
3+
"version": "1.7.0-alpha.17",
44
"license": "MPL-2.0",
55
"main": "./build/index.js",
66
"exports": {

packages/country-config/src/forms.ts

+85-14
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ export const idReader = (
147147
required: false,
148148
type: "ID_READER",
149149
label: {
150-
id: "form.field.label.empty",
151-
defaultMessage: "",
150+
id: "form.field.label.idReader",
151+
defaultMessage: "ID verification",
152152
},
153153
hideInPreview: true,
154154
initialValue: "",
@@ -162,6 +162,11 @@ export const idReader = (
162162
id: "views.idReader.label.manualInput",
163163
defaultMessage: "Complete fields below",
164164
},
165+
mapping: {
166+
mutation: {
167+
operation: "ignoreFieldTransformer",
168+
},
169+
},
165170
readers,
166171
};
167172
};
@@ -172,18 +177,31 @@ type MessageDescriptor = {
172177
description?: string;
173178
};
174179

175-
export const qr = ({
176-
validation,
177-
}: {
178-
validation: {
179-
rule: Record<string, unknown>;
180-
errorMessage: MessageDescriptor;
181-
};
182-
}) => ({
180+
interface QRValidation {
181+
rule: Record<string, unknown>;
182+
errorMessage: MessageDescriptor;
183+
}
184+
185+
interface QRConfig {
186+
validation: QRValidation;
187+
}
188+
189+
export const qr = ({ validation }: QRConfig) => ({
183190
type: "QR",
184191
validation,
185192
});
186193

194+
interface ESignetConfig {
195+
esignetAuthUrl: string;
196+
openIdProviderClientId: string;
197+
openIdProviderClaims: string | undefined;
198+
fieldName: string;
199+
callback: {
200+
fieldName: string;
201+
mosipAPIUserInfoUrl: string;
202+
};
203+
}
204+
187205
export const verified = (event: string, sectionId: string, mapping: any) => {
188206
const fieldName = "verified";
189207
const fieldId = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`;
@@ -202,7 +220,7 @@ export const verified = (event: string, sectionId: string, mapping: any) => {
202220
expression: 'Boolean($form?.idReader)? "pending":""',
203221
},
204222
validator: [],
205-
mapping
223+
mapping,
206224
};
207225
};
208226

@@ -213,7 +231,7 @@ function capitalize(str: string) {
213231
export const idVerificationBanner = (
214232
event: string,
215233
sectionId: string,
216-
status: "pending" | "verified" | "failed",
234+
status: "verified" | "failed" | "authenticated",
217235
) => {
218236
const fieldName = "verified";
219237
const fieldId = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`;
@@ -239,11 +257,64 @@ export const idVerificationBanner = (
239257
};
240258
};
241259

242-
export const idVerificationFields = (event: string, sectionId: string, mapping: any) => {
260+
export const getInitialValueFromIDReader = (fieldNameInReader: string) => ({
261+
dependsOn: ["idReader", "esignetCallback"],
262+
expression: `$form?.idReader?.${fieldNameInReader} || $form?.esignetCallback?.data?.${fieldNameInReader} || ""`,
263+
});
264+
265+
export const idReaderFields = (
266+
event: "birth" | "death",
267+
section: "informant" | "mother" | "father",
268+
qrConfig: QRConfig,
269+
esignetConfig: ESignetConfig | undefined,
270+
verifiedCustomFieldMapping: any,
271+
conditionals: any[] = [],
272+
) => {
273+
const readers: any[] = [qr(qrConfig)];
274+
const fields: any[] = [
275+
idReader(
276+
event,
277+
section,
278+
conditionals.concat({
279+
action: "hide",
280+
expression:
281+
"$form?.verified === 'verified' || $form?.verified === 'authenticated' || $form?.verified === 'failed'",
282+
}),
283+
readers,
284+
),
285+
];
286+
if (esignetConfig) {
287+
readers.push(
288+
esignet(
289+
esignetConfig.esignetAuthUrl,
290+
esignetConfig.openIdProviderClientId,
291+
esignetConfig.openIdProviderClaims,
292+
esignetConfig.fieldName,
293+
esignetConfig.callback.fieldName,
294+
),
295+
);
296+
fields.push(
297+
esignetCallback({
298+
fieldName: esignetConfig.callback.fieldName,
299+
mosipAPIUserInfoUrl: esignetConfig.callback.mosipAPIUserInfoUrl,
300+
openIdProviderClientId: esignetConfig.openIdProviderClientId,
301+
}),
302+
);
303+
}
304+
return [
305+
...fields,
306+
...idVerificationFields(event, section, verifiedCustomFieldMapping),
307+
];
308+
};
309+
export const idVerificationFields = (
310+
event: string,
311+
sectionId: string,
312+
mapping: any,
313+
) => {
243314
return [
244315
verified(event, sectionId, mapping),
245-
idVerificationBanner(event, sectionId, "pending"),
246316
idVerificationBanner(event, sectionId, "verified"),
247317
idVerificationBanner(event, sectionId, "failed"),
318+
idVerificationBanner(event, sectionId, "authenticated"),
248319
];
249320
};

packages/esignet-mock/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@opencrvs/esignet-mock",
33
"license": "MPL-2.0",
4-
"version": "1.7.0-alpha.16",
4+
"version": "1.7.0-alpha.17",
55
"main": "index.js",
66
"scripts": {
77
"dev": "NODE_ENV=development tsx watch src/index.ts",

packages/mosip-api/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opencrvs/mosip-api",
3-
"version": "1.7.0-alpha.16",
3+
"version": "1.7.0-alpha.17",
44
"license": "MPL-2.0",
55
"scripts": {
66
"dev": "NODE_ENV=development tsx watch src/index.ts",

packages/mosip-api/src/routes/event-review.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
import { FastifyRequest, FastifyReply } from "fastify";
2-
import { getComposition, getInformantType } from "../types/fhir";
2+
import {
3+
getComposition,
4+
getInformantNationalId,
5+
getInformantType,
6+
} from "../types/fhir";
37
import { updateField } from "../opencrvs-api";
48

59
type OpenCRVSRequest = FastifyRequest<{
610
Body: fhir3.Bundle;
711
}>;
812

13+
const stubValidNIDs = [
14+
"1234567890",
15+
"1210563847",
16+
"1223948576",
17+
"1238475062",
18+
"1249583720",
19+
"1256074839",
20+
"1263849205",
21+
"1275093846",
22+
"1283749502",
23+
"1295067384",
24+
];
925
export const reviewEventHandler = async (
1026
request: OpenCRVSRequest,
1127
reply: FastifyReply,
1228
) => {
13-
const informantType = getInformantType(request.body);
29+
const informantNationalID = getInformantNationalId(request.body);
1430
const { id: eventId } = getComposition(request.body);
1531

1632
if (!request.headers.authorization) {
@@ -25,13 +41,20 @@ export const reviewEventHandler = async (
2541
}
2642

2743
// Initial test of the verification, we will verify only other informants than mother and father
28-
if (informantType !== "mother" && informantType !== "father") {
44+
if (stubValidNIDs.includes(informantNationalID)) {
2945
await updateField(
3046
eventId,
3147
`birth.informant.informant-view-group.verified`,
3248
'verified',
3349
{ headers: { Authorization: `Bearer ${token}` } },
3450
);
51+
} else {
52+
await updateField(
53+
eventId,
54+
`birth.informant.informant-view-group.verified`,
55+
'failed',
56+
{ headers: { Authorization: `Bearer ${token}` } },
57+
);
3558
}
3659

3760
return reply.code(200).send({ success: true });

packages/mosip-api/src/types/fhir.ts

+21
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,24 @@ export function getInformantType(record: fhir3.Bundle) {
560560
return (personEntry?.resource as fhir3.RelatedPerson).relationship
561561
?.coding?.[0].code;
562562
}
563+
564+
function getInformantPatient(record: fhir3.Bundle) {
565+
const compositionSection = findCompositionSection(
566+
"informant-details",
567+
getComposition(record),
568+
);
569+
if (!compositionSection) return undefined;
570+
const personSectionEntry = compositionSection.entry![0];
571+
const relatedPersonEntry = findEntryFromBundle(
572+
record,
573+
personSectionEntry.reference,
574+
);
575+
const reference = (relatedPersonEntry?.resource as fhir3.RelatedPerson)
576+
.patient.reference;
577+
return getFromBundleById(record, reference!.split("/")[1]).resource;
578+
}
579+
580+
export function getInformantNationalId(record: fhir3.Bundle) {
581+
const informantPatient = getInformantPatient(record);
582+
return getPatientNationalId(informantPatient as fhir3.Patient);
583+
}

packages/mosip-mock/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opencrvs/mosip-mock",
3-
"version": "1.7.0-alpha.16",
3+
"version": "1.7.0-alpha.17",
44
"license": "MPL-2.0",
55
"scripts": {
66
"dev": "NODE_ENV=development tsx watch src/index.ts",

0 commit comments

Comments
 (0)