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: updateField GraphQL mutation #8291

Merged
merged 24 commits into from
Jan 24, 2025
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ac31d24
feat: notify CC about actions
naftis Jan 6, 2025
57b76be
refactor: use 'getValidRecordById' as it has the same statuses
naftis Jan 7, 2025
5bbcebc
feat: workflow endpoint allowing editing field ids
naftis Jan 7, 2025
91f09e4
fix(tests): mock country config event notification hook
naftis Jan 7, 2025
bbd398b
Merge branch 'develop' of https://github.com/opencrvs/opencrvs-core i…
naftis Jan 22, 2025
a41d2e7
feat: initial graphql endpoint for update field
naftis Jan 22, 2025
57e0cfa
chore: test and fix errors, return boolean
naftis Jan 22, 2025
fd33fef
feat: update the action notification according to events v2
naftis Jan 22, 2025
0109607
fix: update test to conform events v2 notification format
naftis Jan 22, 2025
3f35252
Merge branch 'develop' into notify-cc-about-actions
naftis Jan 23, 2025
c360d6f
Merge branch 'develop' into notify-cc-about-actions
naftis Jan 23, 2025
7bd2ce0
feat: token exchange on notify
naftis Jan 23, 2025
1ee22a7
Merge branch 'notify-cc-about-actions' of https://github.com/opencrvs…
naftis Jan 23, 2025
6656b72
update: test comment
naftis Jan 24, 2025
59f1b1d
chore(changelog): add update field
naftis Jan 24, 2025
a66600a
Merge branch 'notify-cc-about-actions' of https://github.com/opencrvs…
naftis Jan 24, 2025
10477f8
Merge branch 'develop' of https://github.com/opencrvs/opencrvs-core i…
naftis Jan 24, 2025
5166559
fix: rename config to options
naftis Jan 24, 2025
13cba43
refactor: rename token-exchange away from 'handler' as it's not a htt…
naftis Jan 24, 2025
504acf5
fix: test not mocking the token exchange
naftis Jan 24, 2025
93622a0
chore: remove unused function
naftis Jan 24, 2025
cfa93ed
Merge branch 'develop' into notify-cc-about-actions
naftis Jan 24, 2025
a1a5764
fix: align the error handling with how events service notifies
naftis Jan 24, 2025
3be2948
Merge branch 'notify-cc-about-actions' of https://github.com/opencrvs…
naftis Jan 24, 2025
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
Next Next commit
feat: notify CC about actions
naftis committed Jan 6, 2025
commit ac31d248154243b449f855dded0bf7bd93fb670f
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@

import { UUID, logger } from '@opencrvs/commons'
import {
Bundle,
Composition,
Patient,
Practitioner,
@@ -26,7 +25,6 @@ import {
SupportedPatientIdentifierCode,
ValidRecord
} from '@opencrvs/commons/types'
import { COUNTRY_CONFIG_URL } from '@workflow/constants'
import {
OPENCRVS_SPECIFICATION_URL,
RegStatus
@@ -39,31 +37,6 @@ import {
import { getPractitionerRef } from '@workflow/features/user/utils'
import { ITokenPayload } from '@workflow/utils/auth-utils'
import { isEqual } from 'lodash'
import fetch from 'node-fetch'

export async function invokeRegistrationValidation(
bundle: Saved<Bundle>,
headers: Record<string, string>
): Promise<Bundle> {
const res = await fetch(
new URL('event-registration', COUNTRY_CONFIG_URL).toString(),
{
method: 'POST',
body: JSON.stringify(bundle),
headers: {
'Content-Type': 'application/json',
...headers
}
}
)
if (!res.ok) {
const errorText = await res.text()
throw new Error(
`Error calling country configuration event-registration [${res.statusText} ${res.status}]: ${errorText}`
)
}
return bundle
}

export async function setupRegistrationWorkflow(
taskResource: Task,
13 changes: 13 additions & 0 deletions packages/workflow/src/records/handler/create.ts
Original file line number Diff line number Diff line change
@@ -75,6 +75,7 @@ import {
toWaitingForExternalValidationState
} from '@workflow/records/state-transitions'
import { logger, UUID } from '@opencrvs/commons'
import { notifyForAction } from '@workflow/utils/country-config-api'

const requestSchema = z.object({
event: z.custom<EVENT_TYPE>(),
@@ -348,6 +349,8 @@ export default async function createRecordHandler(
/*
* We need to initiate registration for a
* record in waiting validation state
*
* `initiateRegistration` notifies country configuration about the event which then either confirms or rejects the record.
*/
if (isWaitingExternalValidation(record)) {
const rejectedOrWaitingValidationRecord = await initiateRegistration(
@@ -360,6 +363,16 @@ export default async function createRecordHandler(
await indexBundle(rejectedOrWaitingValidationRecord, token)
await auditEvent('sent-for-updates', record, token)
}
} else {
/*
* Notify country configuration about the event so that countries can hook into actions like "sent-for-approval"
*/
await notifyForAction({
event,
action: eventAction,
record,
headers: request.headers
})
}

return {
2 changes: 1 addition & 1 deletion packages/workflow/src/records/state-transitions.ts
Original file line number Diff line number Diff line change
@@ -58,7 +58,6 @@ import {
SECTION_CODE
} from '@workflow/features/events/utils'
import {
invokeRegistrationValidation,
setupLastRegOffice,
setupLastRegUser,
updatePatientIdentifierWithRN,
@@ -109,6 +108,7 @@ import {
} from '@workflow/records/fhir'
import { REG_NUMBER_GENERATION_FAILED } from '@workflow/features/registration/fhir/constants'
import { tokenExchangeHandler } from './token-exchange-handler'
import { invokeRegistrationValidation } from '@workflow/utils/country-config-api'

export async function toCorrected(
record: RegisteredRecord | CertifiedRecord | IssuedRecord,
86 changes: 86 additions & 0 deletions packages/workflow/src/utils/country-config-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import { logger } from '@opencrvs/commons'
import { Bundle, EVENT_TYPE, Saved, ValidRecord } from '@opencrvs/commons/types'
import { COUNTRY_CONFIG_URL } from '@workflow/constants'
import fetch from 'node-fetch'

const ACTION_NOTIFY_URL = (event: EVENT_TYPE, action: string) =>
new URL(
`event/${event.toLowerCase() as Lowercase<EVENT_TYPE>}/action/${action}`,
COUNTRY_CONFIG_URL
)

export async function notifyForAction({
event,
action,
record,
headers
}: {
event: EVENT_TYPE
action: string
record: Saved<ValidRecord>
headers: Record<string, string>
}) {
const response = await fetch(ACTION_NOTIFY_URL(event, action), {
method: 'POST',
body: JSON.stringify(record),
headers: {
'Content-Type': 'application/json',
...headers
}
})

if (response.status === 404) {
logger.debug(
`Non-issue: No country configuration endpoint for POST ${ACTION_NOTIFY_URL(
event,
action
)}. To optionally hook into this action, you must implement the corresponding action route in your country configuration.`
)
return
}

if (!response.ok) {
throw new Error(
`Error notifying country-config as POST ${ACTION_NOTIFY_URL(
event,
action
)} [${response.statusText} ${response.status}]: ${response.text()}`
)
}

return response
}

export async function invokeRegistrationValidation(
bundle: Saved<Bundle>,
headers: Record<string, string>
): Promise<Bundle> {
const res = await fetch(
new URL('event-registration', COUNTRY_CONFIG_URL).toString(),
{
method: 'POST',
body: JSON.stringify(bundle),
headers: {
'Content-Type': 'application/json',
...headers
}
}
)
if (!res.ok) {
const errorText = await res.text()
throw new Error(
`Error calling country configuration event-registration [${res.statusText} ${res.status}]: ${errorText}`
)
}
return bundle
}