Skip to content

Commit 8eb84cf

Browse files
authored
feat: confirm registration via graphql api (#288)
* refactor: remove all graphql related stuff * chore: remove unused code * feat: allow graphql type hints * feat: allow confirming registration via the new graphql api * refactor: use graphql comment so no package needed * refactor: use graphql comment in the last query as well * refactor: throw if the composition doesn't have an id * fix: throw if the id is not found as the function is _get_ * fix: add required env variables * fix: use identifiers instead of childIdentifiers * fix: remove posting tracking id
1 parent 837e927 commit 8eb84cf

File tree

15 files changed

+208
-2606
lines changed

15 files changed

+208
-2606
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ data
1919

2020
.history
2121

22-
graphql.schema.json
2322
*.tar.gz
2423
.secrets
2524
.env*

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"apollographql.vscode-apollo"
4+
]
5+
}

apollo.config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"client": {
3+
"service": {
4+
"name": "@opencrvs/gateway",
5+
"url": "http://localhost:7070/graphql"
6+
}
7+
}
8+
}

codegen.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,8 @@
3131
"sort-translations": "cross-env NODE_ENV=development ts-node -r tsconfig-paths/register src/sort-translations.ts"
3232
},
3333
"devDependencies": {
34-
"@graphql-codegen/add": "^3.1.1",
35-
"@graphql-codegen/cli": "^3.3.1",
36-
"@graphql-codegen/introspection": "^3.0.1",
37-
"@graphql-codegen/typescript": "^3.0.4",
38-
"@graphql-codegen/typescript-operations": "^3.0.4",
3934
"@inquirer/editor": "^1.2.13",
4035
"@octokit/core": "4.2.1",
41-
"@types/google-libphonenumber": "^7.4.23",
4236
"@types/handlebars": "^4.1.0",
4337
"@types/hapi__inert": "5.2.1",
4438
"@types/inquirer": "^9.0.7",
@@ -91,9 +85,6 @@
9185
"dotenv": "^16.4.5",
9286
"envalid": "^8.0.0",
9387
"esbuild": "^0.18.9",
94-
"google-libphonenumber": "^3.2.32",
95-
"graphql": "^16.3.0",
96-
"graphql-tag": "^2.12.6",
9788
"handlebars": "^4.7.7",
9889
"hapi-auth-jwt2": "10.4.0",
9990
"hapi-pino": "^9.0.0",

src/api/event-registration/handler.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
1010
*/
1111
import * as Hapi from '@hapi/hapi'
12-
import fetch from 'node-fetch'
1312
import { logger } from '@countryconfig/logger'
14-
import { CONFIRM_REGISTRATION_URL } from '@countryconfig/constants'
1513
import { createUniqueRegistrationNumberFromBundle } from '@countryconfig/api/event-registration/service'
1614
import { badImplementation } from '@hapi/boom'
15+
import {
16+
confirmRegistration
17+
// rejectRegistration
18+
} from '@countryconfig/utils/gateway-api'
1719

1820
export async function eventRegistrationHandler(
1921
request: Hapi.Request,
@@ -33,15 +35,28 @@ export async function eventRegistrationHandler(
3335
const bundle = request.payload as fhir.Bundle
3436

3537
const eventRegistrationIdentifiersResponse =
36-
await createUniqueRegistrationNumberFromBundle(bundle)
38+
createUniqueRegistrationNumberFromBundle(bundle)
3739

38-
await fetch(CONFIRM_REGISTRATION_URL, {
39-
method: 'POST',
40-
body: JSON.stringify(eventRegistrationIdentifiersResponse),
41-
headers: request.headers
42-
})
40+
await confirmRegistration(
41+
eventRegistrationIdentifiersResponse.compositionId,
42+
eventRegistrationIdentifiersResponse,
43+
{
44+
headers: request.headers
45+
}
46+
)
4347
} catch (err) {
44-
// IF ANY ERROR OCCURS IN THIS API, THE REGISTRATION WILL BE REJECTED AND MUST BE RE-SUBMITTED BY A REGISTRAR ONCE THE ISSUE IS RESOLVED
48+
// If the confirm registration endpoint throws an error, the registration will be retried through country-config
49+
// If you don't want the registration to retry, you can call `rejectRegistration` from here and return 202 Accepted
50+
51+
// await confirmRegistration(
52+
// eventRegistrationIdentifiersResponse.compositionId,
53+
// {
54+
// reason: 'other', // Refer to the GraphQL schema for other options
55+
// comment: 'The comment that will be visible on audit log.'
56+
// },
57+
// { headers: request.headers }
58+
// )
59+
4560
logger.error(err)
4661

4762
const boomError = badImplementation()

src/api/event-registration/service.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ function generateRegistrationNumber(trackingId: string): string {
2424
return brn
2525
}
2626

27-
export async function createUniqueRegistrationNumberFromBundle(
28-
bundle: fhir.Bundle
29-
) {
27+
export function createUniqueRegistrationNumberFromBundle(bundle: fhir.Bundle) {
3028
const taskResource = getTaskResource(bundle)
3129

3230
if (!taskResource || !taskResource.extension) {
@@ -36,11 +34,12 @@ export async function createUniqueRegistrationNumberFromBundle(
3634
}
3735

3836
const trackingId = getTrackingIdFromTaskResource(taskResource)
37+
const compositionId = getCompositionId(bundle)
3938

4039
return {
4140
trackingId,
41+
compositionId,
4242
registrationNumber: generateRegistrationNumber(trackingId),
43-
compositionId: getCompositionId(bundle),
4443
...(taskResource.code?.coding?.[0].code === 'BIRTH' && {
4544
// Some countries desire to create multiple identifiers for citizens at the point of birth registration using external systems.
4645
// OpenCRVS supports up to 3 additional, custom identifiers that can be created

src/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@ export const APPLICATION_CONFIG_URL = env.APPLICATION_CONFIG_URL
2828
export const SENTRY_DSN = env.SENTRY_DSN
2929
export const CHECK_INVALID_TOKEN = env.CHECK_INVALID_TOKEN
3030

31-
export const CONFIRM_REGISTRATION_URL = env.CONFIRM_REGISTRATION_URL
3231
export const PRODUCTION = env.isProd
3332
export const QA_ENV = env.QA_ENV

src/environment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ export const env = cleanEnv(process.env, {
1616
LOGIN_URL: url({ devDefault: 'http://localhost:3020/' }),
1717
CLIENT_APP_URL: url({ devDefault: 'http://localhost:3000/' }),
1818
FHIR_URL: url({ devDefault: 'http://localhost:3447/fhir' }),
19-
COUNTRY_CONFIG_HOST: str({ devDefault: '0.0.0.0' }),
19+
COUNTRY_CONFIG_HOST: str({ default: '0.0.0.0' }),
2020
COUNTRY_CONFIG_PORT: port({ default: 3040 }),
2121
AUTH_URL: url({ devDefault: 'http://localhost:4040' }),
2222
COUNTRY_CONFIG_URL: url({ devDefault: 'http://localhost:3040' }),
2323
APPLICATION_CONFIG_URL: url({ devDefault: 'http://localhost:2021/' }),
2424
SENTRY_DSN: str({ default: undefined }),
2525
CHECK_INVALID_TOKEN: bool({
26+
default: true,
2627
devDefault: false,
2728
desc: 'Check if the token has been invalidated in the auth service before it has expired'
2829
}),

src/form/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import { birthForm } from './birth'
1414
import { deathForm } from './death'
1515
import { marriageForm } from './marriage'
1616
import { IForms, Event } from './types/types'
17-
import { fetchUserLocationHierarchy } from '@countryconfig/utils/users'
17+
import { fetchUserLocationHierarchy } from '@countryconfig/utils/gateway-api'
1818

1919
export async function formHandler(req: Request): Promise<IForms> {
2020
const addressHierarchy = await fetchUserLocationHierarchy(
21-
req.headers.authorization,
22-
req.auth.credentials.sub as string
21+
req.auth.credentials.sub as string,
22+
{ headers: req.headers }
2323
)
2424
// ====================== NOTE REGARDING MIGRATING FROM OPNCRVS v1.2 OR EARLIER ======================
2525

0 commit comments

Comments
 (0)