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

Feat/ocrvs 7955/qr code scanner poc #1163

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
59 changes: 59 additions & 0 deletions src/form/birth/custom-fields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { getCustomFieldMapping } from '@countryconfig/utils/mapping/field-mapping-utils'
import { formMessageDescriptors } from '../common/messages'
import { Conditional, SerializedFormField } from '../types/types'
import { genderOptions } from '../common/select-options'

/**
*
* @param event
* @param sectionId
* @returns hidden field to store QR scanned data
*/
export function getQRCodeField(
event: string,
sectionId: string,
conditionals: Conditional[]
): SerializedFormField {
const fieldName: string = 'qrCode'
const fieldId: string = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`
return {
name: fieldName,
customQuestionMappingId: fieldId,
custom: true,
required: false,
type: 'QR_SCANNER',
label: {
id: 'form.field.label.empty',
description: 'empty string',
defaultMessage: ''
},
initialValue: '',
validator: [],
mapping: getCustomFieldMapping(fieldId),
placeholder: formMessageDescriptors.formSelectPlaceholder,
conditionals
}
}

/** To bypass config validation */
export function getGenderCustom(
event: string,
sectionId: string,
initialValue: { dependsOn: string[]; expression: string } | string = ''
) {
const fieldName: string = 'gender'
const fieldId: string = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`
return {
name: fieldName,
type: 'SELECT_WITH_OPTIONS',
customQuestionMappingId: fieldId,
custom: true,
label: formMessageDescriptors.sex,
required: false,
initialValue,
validator: [],
placeholder: formMessageDescriptors.formSelectPlaceholder,
mapping: getCustomFieldMapping(fieldId),
options: genderOptions
} satisfies SerializedFormField
}
29 changes: 27 additions & 2 deletions src/form/birth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import { getSectionMapping } from '@countryconfig/utils/mapping/section/birth/ma
import { getCommonSectionMapping } from '@countryconfig/utils/mapping/field-mapping-utils'
import { getReasonForLateRegistration } from '../custom-fields'
import { getIDNumberFields, getIDType } from '../custom-fields'
import { getGenderCustom, getQRCodeField } from './custom-fields'
// import { createCustomFieldExample } from '../custom-fields'

// ======================= FORM CONFIGURATION =======================
Expand Down Expand Up @@ -220,20 +221,44 @@ export const birthForm: ISerializedForm = {
fields: [
informantType, // Required field.
otherInformantType(Event.Birth), // Required field.
getQRCodeField(
'birth',
'informant',
informantFirstNameConditionals
.concat(hideIfInformantMotherOrFather)
.concat([
{
action: 'disable',
expression: 'Boolean($form.qrCode)'
}
])
),
getFirstNameField(
'informantNameInEnglish',
informantFirstNameConditionals.concat(
hideIfInformantMotherOrFather
),
certificateHandlebars.informantFirstName
certificateHandlebars.informantFirstName,
{
dependsOn: ['qrCode'],
expression: '$form.qrCode?.firstName?.[0].value'
}
), // Required field. In Farajaland, we have built the option to integrate with MOSIP. So we have different conditionals for each name to check MOSIP responses. You could always refactor firstNamesEng for a basic setup
getFamilyNameField(
'informantNameInEnglish',
informantFamilyNameConditionals.concat(
hideIfInformantMotherOrFather
),
certificateHandlebars.informantFamilyName
certificateHandlebars.informantFamilyName,
{
dependsOn: ['qrCode'],
expression: '$form.qrCode?.lastName?.[0].value'
}
), // Required field.
getGenderCustom('birth', 'informant', {
dependsOn: ['qrCode'],
expression: '$form.qrCode?.gender?.[0].value?.toLowerCase()'
}),
getBirthDate(
'informantBirthDate',
informantBirthDateConditionals.concat(
Expand Down
10 changes: 6 additions & 4 deletions src/form/common/common-required-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const getGender = (certificateHandlebar: string) =>
export const getFamilyNameField = (
previewGroup: string,
conditionals: Conditional[],
certificateHandlebar: string
certificateHandlebar: string,
initialValue: string | { dependsOn: string[]; expression: string } = ''
) =>
({
name: 'familyNameEng', // A field with this name MUST exist
Expand All @@ -58,7 +59,7 @@ export const getFamilyNameField = (
label: formMessageDescriptors.familyName,
maxLength: 32,
required: true,
initialValue: '',
initialValue,
validator: [
{
operation: 'englishOnlyNameFormat'
Expand All @@ -70,7 +71,8 @@ export const getFamilyNameField = (
export const getFirstNameField = (
previewGroup: string,
conditionals: Conditional[],
certificateHandlebar: string
certificateHandlebar: string,
initialValue: string | { dependsOn: string[]; expression: string } = ''
) =>
({
name: 'firstNamesEng', // A field with this name MUST exist
Expand All @@ -84,7 +86,7 @@ export const getFirstNameField = (
conditionals,
maxLength: 32,
required: true,
initialValue: '',
initialValue,
validator: [
{
operation: 'englishOnlyNameFormat'
Expand Down
11 changes: 11 additions & 0 deletions src/form/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const TEL = 'TEL'
export const NUMBER = 'NUMBER'
export const BIG_NUMBER = 'BIG_NUMBER'
export const RADIO_GROUP = 'RADIO_GROUP'
export const HIDDEN = 'HIDDEN'
export const INFORMATIVE_RADIO_GROUP = 'INFORMATIVE_RADIO_GROUP'
export const CHECKBOX_GROUP = 'CHECKBOX_GROUP'
export const CHECKBOX = 'CHECKBOX'
Expand Down Expand Up @@ -142,6 +143,7 @@ export const NID_VERIFICATION_BUTTON = 'NID_VERIFICATION_BUTTON'
export const DIVIDER = 'DIVIDER'
export const HEADING3 = 'HEADING3'
export const SIGNATURE = 'SIGNATURE'
export const QR_SCANNER = 'QR_SCANNER'

export enum RadioSize {
LARGE = 'large',
Expand Down Expand Up @@ -492,6 +494,9 @@ export interface ISignatureFormField extends IFormFieldBase {
)[]
}

export interface IQRScannerFormField extends IFormFieldBase {
type: typeof QR_SCANNER
}
export type IFormField =
| ITextFormField
| ITelFormField
Expand Down Expand Up @@ -525,6 +530,8 @@ export type IFormField =
| IDividerField
| IHeading3Field
| ISignatureFormField
| IHiddenFormField
| IQRScannerFormField

export interface SelectComponentOption {
value: string
Expand Down Expand Up @@ -740,6 +747,10 @@ export type SerializedFormField = UnionOmit<
mapping?: IFormFieldMapping
}

interface IHiddenFormField extends IFormFieldBase {
type: typeof HIDDEN
}

export type IFormSectionQueryMapFunction = (
transFormedData: IFormData,
queryData: any,
Expand Down
Loading