Skip to content

Commit

Permalink
fix: save additional practitioner role entry in bundle during view ac…
Browse files Browse the repository at this point in the history
…tion (#8332)

* fix: save additional practitioner role entry in bundle during view action

* fix: amend officeHome on page change handler

* fix: update commons import in client
  • Loading branch information
Nil20 authored Jan 15, 2025
1 parent 502a2bc commit 33fbd04
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { formMessageDescriptors } from '@client/i18n/messages'
import { messages as advancedSearchForm } from '@client/i18n/messages/views/advancedSearchForm'
import { isValidDate } from '@client/search/advancedSearch/validators'
import { TIME_PERIOD } from './utils'
import { UUID } from '@opencrvs/commons'
import { UUID } from '@opencrvs/commons/client'

const createBirthSearchRegistrationSection = (
hasBirthSearchJurisdictionScope?: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { formMessageDescriptors } from '@client/i18n/messages'
import { messages as advancedSearchForm } from '@client/i18n/messages/views/advancedSearchForm'
import { isValidDate } from '@client/search/advancedSearch/validators'
import { TIME_PERIOD } from './utils'
import { UUID } from '@opencrvs/commons'
import { UUID } from '@opencrvs/commons/client'

const createDeathSearchRegistrationSection = (
hasDeathSearchJurisdictionScope?: boolean,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/forms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
NATIONAL_ID
} from '@client/utils/constants'
import { IconProps } from '@opencrvs/components/lib'
import { UUID } from '@opencrvs/commons'
import { UUID } from '@opencrvs/commons/client'

export const TEXT = 'TEXT'
export const TEL = 'TEL'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/search/advancedSearch/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
isInvalidDate,
TIME_PERIOD
} from '@client/forms/advancedSearch/fieldDefinitions/utils'
import { UUID } from '@opencrvs/commons'
import { UUID } from '@opencrvs/commons/client'

export type advancedSearchPillKey = Exclude<
keyof IAdvancedSearchResultMessages,
Expand Down
7 changes: 5 additions & 2 deletions packages/client/src/tests/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import { Scope, SCOPES } from '@opencrvs/commons/client'
import {
Scope,
SCOPES,
DEFAULT_ROLES_DEFINITION
} from '@opencrvs/commons/client'
import { EventType, Status, FetchUserQuery } from '@client/utils/gateway'
import { UserDetails } from '@client/utils/userUtils'
import { getRegisterForm } from '@client/forms/register/declaration-selectors'
Expand All @@ -17,7 +21,6 @@ import { offlineDataReady, setOfflineData } from '@client/offline/actions'
import { AppStore, createStore, IStoreState } from '@client/store'
import { ThemeProvider } from 'styled-components'
import { getSchema } from '@client/tests/graphql-schema-mock'
import { DEFAULT_ROLES_DEFINITION } from '@opencrvs/commons/authentication'
import { I18nContainer } from '@opencrvs/client/src/i18n/components/I18nContainer'
import { getTheme } from '@opencrvs/components/lib/theme'
import { join } from 'path'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/utils/locationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { countries } from '@client/utils/countries'
import { lookup } from 'country-data'
import { getDefaultLanguage } from '@client/i18n/utils'
import { camelCase } from 'lodash'
import { UUID } from '@opencrvs/commons'
import { UUID } from '@opencrvs/commons/client'

export const countryAlpha3toAlpha2 = (isoCode: string): string | undefined => {
const alpha2 =
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/views/OfficeHome/OfficeHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class OfficeHomeView extends React.Component<
pageId: newPageNumber
})
)
return
}

this.props.router.navigate(
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/views/SearchResult/AdvancedSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { advancedSearchInitialState } from '@client/search/advancedSearch/reduce
import { usePermissions } from '@client/hooks/useAuthorization'
import { useNavigate } from 'react-router-dom'
import * as routes from '@client/navigation/routes'
import { UUID } from '@opencrvs/commons'
import { UUID } from '@opencrvs/commons/client'

enum TabId {
BIRTH = 'birth',
Expand Down
2 changes: 2 additions & 0 deletions packages/commons/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ export * from './scopes'
export * from './conditionals/conditionals'
export * from './conditionals/validate'
export * from './documents'
export * from './uuid'
export { DEFAULT_ROLES_DEFINITION } from './authentication'

export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
4 changes: 4 additions & 0 deletions packages/workflow/src/features/user/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,7 @@ export function getPractitionerRef(practitioner: Practitioner) {
practitioner.id as UUID /* @todo move to practitioner */
}` as const
}

export function getPractitionerRoleByPractitionerId(practitionerId: UUID) {
return getFromFhir(`/PractitionerRole?practitioner=${practitionerId}`)
}
12 changes: 9 additions & 3 deletions packages/workflow/src/records/handler/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ export async function viewRecordHandler(

const viewedRecord = await toViewed(record, token)

const viewedRecordWithTaskOnly: Bundle = {
const viewedRecordWithSpecificEntries: Bundle = {
...viewedRecord,
entry: [viewedRecord.entry.find((e) => e.resource.resourceType === 'Task')!]
entry: [
...viewedRecord.entry.filter(
(e) =>
e.resource.resourceType === 'Task' ||
e.resource.resourceType === 'PractitionerRole'
)!
]
}

await sendBundleToHearth(viewedRecordWithTaskOnly)
await sendBundleToHearth(viewedRecordWithSpecificEntries)
await auditEvent('viewed', viewedRecord, token)

return viewedRecord
Expand Down
19 changes: 17 additions & 2 deletions packages/workflow/src/records/state-transitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
RejectedRecord,
SupportedPatientIdentifierCode
} from '@opencrvs/commons/types'
import { getUUID, logger, UUID } from '@opencrvs/commons'
import { getTokenPayload, getUUID, logger, UUID } from '@opencrvs/commons'
import {
REG_NUMBER_SYSTEM,
SECTION_CODE
Expand Down Expand Up @@ -109,6 +109,10 @@ import {
} from '@workflow/records/fhir'
import { REG_NUMBER_GENERATION_FAILED } from '@workflow/features/registration/fhir/constants'
import { tokenExchangeHandler } from './token-exchange-handler'
import {
getPractitionerRoleByPractitionerId,
getUser
} from '@workflow/features/user/utils'

export async function toCorrected(
record: RegisteredRecord | CertifiedRecord | IssuedRecord,
Expand Down Expand Up @@ -303,6 +307,13 @@ export async function toViewed<T extends ValidRecord>(
toHistoryResource(previousTask)
) as SavedBundleEntry<TaskHistory>

const tokenPayload = getTokenPayload(token)
const userDetails = await getUser(tokenPayload.sub, { Authorization: token })
const practitionerId = userDetails.practitionerId
const practitionerRoleBundle = await getPractitionerRoleByPractitionerId(
practitionerId as UUID
)

const filteredEntries = record.entry.filter(
(e) => e.resource.resourceType !== 'Task'
)
Expand All @@ -318,7 +329,11 @@ export async function toViewed<T extends ValidRecord>(
)[0].fullUrl,
resource: viewedTask
},
taskHistoryEntry
taskHistoryEntry,
/* PractitionerRole resource is saved in the bundle
since PractitionerRole is fetched from bundle
in the resolvers during readying history of a record */
practitionerRoleBundle.entry[0]
]
} as T

Expand Down

0 comments on commit 33fbd04

Please sign in to comment.