Skip to content

Commit

Permalink
fix: use utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jamil314 committed Jan 31, 2025
1 parent 519d173 commit 7d83bbf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/workflow/src/records/handler/correction/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
isCorrectionRequestedTask,
isTask,
OpenCRVSPractitionerName,
TransactionResponse
TransactionResponse,
URLReference,
urlReferenceToResourceIdentifier,
urlReferenceToUUID
} from '@opencrvs/commons/types'
import { NOTIFICATION_SERVICE_URL } from '@workflow/constants'
import { partition } from 'lodash'
Expand Down Expand Up @@ -72,7 +75,11 @@ export async function sendNotification<T extends keyof PayloadMap>(
return res
}

const replaceTmpURN = (resource: any, tmpURN: string, fullUrl: string) => {
const replaceTmpURN = (
resource: any,
tmpURN: string,
fullUrl: URLReference
) => {
if (Array.isArray(resource)) {
resource.forEach((item, index) => {
if (item === tmpURN) {
Expand All @@ -86,7 +93,7 @@ const replaceTmpURN = (resource: any, tmpURN: string, fullUrl: string) => {
if (resource[key] === tmpURN) {
resource[key] =
key === 'reference'
? fullUrl.split('/').slice(2, 4).join('/') // /fhir/Patient/xyz/_history/abc => Patient/xyz
? urlReferenceToResourceIdentifier(fullUrl)
: fullUrl
} else {
replaceTmpURN(resource[key], tmpURN, fullUrl)
Expand All @@ -108,7 +115,7 @@ export const updateFullUrl = <T extends Bundle>(
if (status === '201') {
others[id].fullUrl &&
replaceTmpURN(bundle, others[id].fullUrl, location)
others[id].resource.id = location.split('/')[3]
others[id].resource.id = urlReferenceToUUID(location)
}
}
)
Expand Down

0 comments on commit 7d83bbf

Please sign in to comment.