Skip to content

Commit 55a5154

Browse files
authored
fix: forward record with proper history (#9656)
* fix: forward record with proper history When indexing the validated record, the DECLARATION_UPDATED history entry wasn't being forwarded, which was causing conflicting assignments to be found during indexing and unassign. * docs: update CHANGELOG * test: return validated record from records endpoint
1 parent a5d44e4 commit 55a5154

File tree

4 files changed

+134
-6
lines changed

4 files changed

+134
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Fix a child's NID form field cannot be added eithe rmanually or via ESignet. A father section cannot be placed before a mother section if you wish to use a radio button to control mapping addresses from one individual to aother to make data entry easier [#9582](https://github.com/opencrvs/opencrvs-core/issues/9582)
1717
- Fix the role of the certifier unable to get resolved for new users which in turn caused the download of the declaration to fail [#9643](https://github.com/opencrvs/opencrvs-core/issues/9643)
1818
- Fix one failing unassign blocking all other unassign actions from continuing [#9651](https://github.com/opencrvs/opencrvs-core/issues/9651)
19+
- Fix record not getting unassigned when validating an already validated record again [#9648](https://github.com/opencrvs/opencrvs-core/issues/9648)
1920

2021
## [1.7.1](https://github.com/opencrvs/opencrvs-core/compare/v1.7.0...v1.7.1)
2122

packages/workflow/src/records/handler/validate.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
ValidRecord
2323
} from '@opencrvs/commons/types'
2424
import { SCOPES } from '@opencrvs/commons/authentication'
25+
import { VALIDATED_BIRTH_RECORD } from '@test/mocks/records/validated'
2526

2627
describe('Validate record endpoint', () => {
2728
let server: Awaited<ReturnType<typeof createServer>>
@@ -46,12 +47,18 @@ describe('Validate record endpoint', () => {
4647
}
4748
)
4849

50+
let calledOnce = false
51+
4952
// Gets record by id via getRecordById endpoint
5053
mswServer.use(
5154
rest.get(
5255
'http://localhost:9090/records/7c3af302-08c9-41af-8701-92de9a71a3e4',
5356
(_, res, ctx) => {
54-
return res(ctx.json(READY_FOR_REVIEW_BIRTH_RECORD))
57+
if (!calledOnce) {
58+
calledOnce = true
59+
return res(ctx.json(READY_FOR_REVIEW_BIRTH_RECORD))
60+
}
61+
return res(ctx.json(VALIDATED_BIRTH_RECORD))
5562
}
5663
)
5764
)

packages/workflow/src/records/handler/validate.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { auditEvent } from '@workflow/records/audit'
1616
import { validateRequest } from '@workflow/utils/index'
1717
import * as z from 'zod'
1818
import { SCOPES } from '@opencrvs/commons/authentication'
19+
import { getRecordById } from '@workflow/records'
1920

2021
export const validateRoute = createRoute({
2122
method: 'POST',
@@ -34,11 +35,12 @@ export const validateRoute = createRoute({
3435
request.payload
3536
)
3637

37-
const validatedRecord = await toValidated(
38-
record,
39-
token,
40-
payload.comments,
41-
payload.timeLoggedMS
38+
await toValidated(record, token, payload.comments, payload.timeLoggedMS)
39+
const validatedRecord = await getRecordById(
40+
request.params.recordId,
41+
request.headers.authorization,
42+
['VALIDATED'],
43+
true
4244
)
4345

4446
await indexBundle(validatedRecord, token)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* OpenCRVS is also distributed under the terms of the Civil Registration
7+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
8+
*
9+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
10+
*/
11+
import {
12+
Composition,
13+
Encounter,
14+
Location,
15+
Observation,
16+
Patient,
17+
Practitioner,
18+
PractitionerRole,
19+
RelatedPerson,
20+
SavedBundle,
21+
Task,
22+
TrackingID,
23+
URLReference
24+
} from '@opencrvs/commons/types'
25+
import { UUID } from '@opencrvs/commons'
26+
import { READY_FOR_REVIEW_BIRTH_RECORD } from './readyForReview'
27+
28+
export const VALIDATED_BIRTH_RECORD: SavedBundle<
29+
| Composition
30+
| Encounter
31+
| Patient
32+
| RelatedPerson
33+
| Task
34+
| Practitioner
35+
| PractitionerRole
36+
| Location
37+
| Observation
38+
> = {
39+
resourceType: 'Bundle',
40+
type: 'document',
41+
entry: [
42+
...READY_FOR_REVIEW_BIRTH_RECORD.entry.filter(
43+
(e) => e.resource.resourceType !== 'Task'
44+
),
45+
{
46+
fullUrl:
47+
'/fhir/Task/f00e742a-0900-488b-b7c1-9625d7b7e456/_history/4d67992c-ab35-4e26-a8b9-9447540cca00' as URLReference,
48+
resource: {
49+
resourceType: 'Task',
50+
extension: [
51+
{
52+
url: 'http://opencrvs.org/specs/extension/contact-person',
53+
valueString: 'MOTHER'
54+
},
55+
{
56+
url: 'http://opencrvs.org/specs/extension/contact-person-email',
57+
valueString: '[email protected]'
58+
},
59+
{
60+
url: 'http://opencrvs.org/specs/extension/timeLoggedMS',
61+
valueInteger: 210764
62+
},
63+
{
64+
url: 'http://opencrvs.org/specs/extension/regLastUser',
65+
valueReference: {
66+
reference:
67+
'Practitioner/4651d1cc-6072-4e34-bf20-b583f421a9f1' as `Practitioner/${UUID}`
68+
}
69+
},
70+
{
71+
url: 'http://opencrvs.org/specs/extension/regLastOffice',
72+
valueReference: {
73+
reference:
74+
'Location/ce73938d-a188-4a78-9d19-35dfd4ca6957' as `Location/${UUID}`
75+
}
76+
}
77+
],
78+
status: 'ready',
79+
identifier: [
80+
{
81+
system: 'http://opencrvs.org/specs/id/draft-id',
82+
value: '7c3af302-08c9-41af-8701-92de9a71a3e4'
83+
},
84+
{
85+
system: 'http://opencrvs.org/specs/id/birth-tracking-id',
86+
value: 'BQSQASX' as TrackingID
87+
}
88+
],
89+
lastModified: '2023-11-30T12:36:27.043Z',
90+
businessStatus: {
91+
coding: [
92+
{
93+
system: 'http://opencrvs.org/specs/reg-status',
94+
code: 'VALIDATED'
95+
}
96+
]
97+
},
98+
code: {
99+
coding: [
100+
{
101+
system: 'http://opencrvs.org/specs/types',
102+
code: 'BIRTH'
103+
}
104+
]
105+
},
106+
focus: {
107+
reference:
108+
'Composition/c8b8e843-c5e0-49b5-96d9-a702ddb46454' as `Composition/${UUID}`
109+
},
110+
meta: {
111+
lastUpdated: '2023-11-30T12:36:27.277+00:00',
112+
versionId: '4d67992c-ab35-4e26-a8b9-9447540cca00'
113+
},
114+
id: 'f00e742a-0900-488b-b7c1-9625d7b7e456' as UUID
115+
}
116+
}
117+
]
118+
}

0 commit comments

Comments
 (0)