Skip to content

Commit

Permalink
chore: refactor fetching role
Browse files Browse the repository at this point in the history
  • Loading branch information
Nil20 committed Oct 3, 2024
1 parent 0c9cc04 commit 1f6e30e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
6 changes: 2 additions & 4 deletions packages/commons/src/fhir/practitioner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,9 @@ export const getUserRoleFromHistory = (
)

const targetCode = result?.code?.find((element) => {
return element.coding?.[0].system === 'http://opencrvs.org/specs/types'
return element.coding?.[0].system === 'http://opencrvs.org/specs/roles'
})

const role = targetCode?.coding?.[0].code
const systemRole = result?.code?.[0].coding?.[0].code

return { role, systemRole }
return role
}
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,9 @@ test('getting role at a specific time from roleHistory', async () => {
*/

const lastModified = '2024-08-30T13:14:33.704Z'
const expectedRole =
'[{"lang":"en","label":"National Registrar"},{"lang":"fr","label":"Registraire national"}]'
const expectedSystemRole = 'NATIONAL_REGISTRAR'
const expectedRole = 'NATIONAL_REGISTRAR'

const { role, systemRole } = getUserRoleFromHistory(
practitionerRoleHistory,
lastModified
)
const role = getUserRoleFromHistory(practitionerRoleHistory, lastModified)

expect(role).toEqual(expectedRole)
expect(systemRole).toEqual(expectedSystemRole)
})
19 changes: 6 additions & 13 deletions packages/gateway/src/features/registration/type-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ import {
findLastOfficeFromSavedBundle,
findLastOfficeLocationFromSavedBundle,
notCorrectedHistory,
findResourceFromBundleById
findResourceFromBundleById,
getUserRoleFromHistory
} from '@opencrvs/commons/types'

import { GQLQuestionnaireQuestion, GQLResolver } from '@gateway/graphql/schema'
Expand Down Expand Up @@ -1552,19 +1553,11 @@ export const typeResolvers: GQLResolver = {

const practitionerRoleHistory =
await dataSources.fhirAPI.getPractionerRoleHistory(practitionerRoleId)
const result = practitionerRoleHistory.find(
(it) =>
it?.meta?.lastUpdated &&
task.lastModified &&
it?.meta?.lastUpdated <= task.lastModified!
)

const targetCode = result?.code?.find((element) => {
return element.coding?.[0].system === 'http://opencrvs.org/specs/roles'
})

const roleId = targetCode?.coding?.[0].code

const roleId = getUserRoleFromHistory(
practitionerRoleHistory,
task.lastModified
)
const userResponse = await dataSources.usersAPI.getUserByPractitionerId(
resourceIdentifierToUUID(user.valueReference.reference)
)
Expand Down

0 comments on commit 1f6e30e

Please sign in to comment.