Skip to content

Commit

Permalink
Merge pull request #7613 from opencrvs/auto-pr-release-v1.5.1-7610-31528
Browse files Browse the repository at this point in the history
fix(v1.5.1): Refactor bundleIncludesLocationResources() function logic to properly check if location resources are included in a bundle
  • Loading branch information
Zangetsu101 authored Sep 13, 2024
2 parents a27ae1d + 133fc0e commit f92f994
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
- When any user's role was updated, incorrect role was shown for that user's actions in the history section of a declaration's record audit page. [#7495](https://github.com/opencrvs/opencrvs-core/issues/7495)
- Registration agent was unable to download declarations that were previously corrected by registrar. [#7582](https://github.com/opencrvs/opencrvs-core/issues/7582)
- When a user updates a marriage declaration editing the signature of the bride, groom, witness one or witness two, handle the changed value of the signature properly. [#7462](https://github.com/opencrvs/opencrvs-core/issues/7462)
- The internal function we used to check if all the location references listed in the encounter are included in the bundle had incorrect logic which resulted in location details missing in ElasticSearch which broke Advanced search. [7494](https://github.com/opencrvs/opencrvs-core/issues/7494)

## 1.5.0 (TBD)

Expand Down
29 changes: 28 additions & 1 deletion packages/workflow/src/records/handler/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,36 @@ import { readFileSync } from 'fs'
import { createBirthRegistrationPayload } from '@test/mocks/createBirthRecord'
import { server as mswServer } from '@test/setupServer'
import { rest } from 'msw'
import { SavedBundle, SavedTask, URLReference } from '@opencrvs/commons/types'
import { TransactionResponse } from '@workflow/records/fhir'
import {
SavedBundle,
SavedTask,
URLReference,
SavedLocation
} from '@opencrvs/commons/types'
import { UUID } from '@opencrvs/commons'

const existingTaskBundle: SavedBundle<SavedTask> = {
resourceType: 'Bundle',
type: 'document',
entry: []
}

const existingLocationBundle: SavedBundle<SavedLocation> = {
resourceType: 'Bundle',
type: 'document',
entry: [
{
resource: {
resourceType: 'Location',
id: '146251e9-df90-4068-82b0-27d8f979e8e2' as UUID
},
fullUrl:
'http://localhost:3447/fhir/Location/146251e9-df90-4068-82b0-27d8f979e8e2/_history/e79c368d-f8e4-49b7-8573-d885e11ebb47' as URLReference
}
]
}

describe('Create record endpoint', () => {
let server: Awaited<ReturnType<typeof createServer>>

Expand Down Expand Up @@ -116,6 +137,12 @@ describe('Create record endpoint', () => {
})
)

mswServer.use(
rest.get('http://localhost:3447/fhir/Location', (_, res, ctx) => {
return res(ctx.json(existingLocationBundle))
})
)

// mock tracking-id generation from country confgi
mswServer.use(
rest.post('http://localhost:3040/tracking-id', (_, res, ctx) => {
Expand Down
12 changes: 8 additions & 4 deletions packages/workflow/src/records/handler/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,18 @@ async function resolveLocationsForEncounter(

function bundleIncludesLocationResources(record: Saved<Bundle>) {
const encounter = findEncounterFromRecord(record)
const locationIds =
const encounterLocationIds =
encounter?.location?.map(
({ location }) => location.reference.split('/')[1]
) || []

return record.entry
.filter(({ resource }) => resource.resourceType == 'Location')
.every(({ resource }) => locationIds?.includes(resource.id))
const bundleLocations = record.entry.filter(
({ resource }) => resource.resourceType == 'Location'
)

return encounterLocationIds.every((locationId) =>
bundleLocations.some((location) => location.id === locationId)
)
}

async function createRecord(
Expand Down

0 comments on commit f92f994

Please sign in to comment.