From cd57e4353bc346cee3a243198a8934b707af87be Mon Sep 17 00:00:00 2001 From: NyashaMuusha Date: Tue, 20 Feb 2024 01:24:22 +0200 Subject: [PATCH] Added matching rule to audit trail table --- .../recordDetails/RecordDetails.tsx | 10 +-- JeMPI_Apps/JeMPI_UI/src/services/ApiClient.ts | 67 ++++++++++++++++++- JeMPI_Apps/JeMPI_UI/src/types/AuditTrail.ts | 4 ++ JeMPI_Apps/JeMPI_UI/src/utils/constants.ts | 8 +++ 4 files changed, 83 insertions(+), 6 deletions(-) diff --git a/JeMPI_Apps/JeMPI_UI/src/components/recordDetails/RecordDetails.tsx b/JeMPI_Apps/JeMPI_UI/src/components/recordDetails/RecordDetails.tsx index 60bee4b90..65cd113f7 100644 --- a/JeMPI_Apps/JeMPI_UI/src/components/recordDetails/RecordDetails.tsx +++ b/JeMPI_Apps/JeMPI_UI/src/components/recordDetails/RecordDetails.tsx @@ -30,7 +30,7 @@ import { PatientRecord, GoldenRecord, AnyRecord } from 'types/PatientRecord' import { sortColumns } from 'utils/helpers' import getCellComponent from 'components/shared/getCellComponent' import { AUDIT_TRAIL_COLUMNS } from 'utils/constants' -import { AuditTrail } from 'types/AuditTrail' +import { AuditTrail, ExpandedAuditTrail } from 'types/AuditTrail' import { useLoaderData, useNavigate } from 'react-router-dom' import { useConfig } from 'hooks/useConfig' @@ -135,14 +135,14 @@ const RecordDetails = () => { data: auditTrail, isLoading: isAuditTrailLoading, isFetching - } = useQuery, AxiosError>({ + } = useQuery, AxiosError>({ queryKey: ['audit-trail', record?.uid], queryFn: async () => { if (record) { if ('linkRecords' in record) { - return await apiClient.getGoldenRecordAuditTrail(record.uid || '') + return await apiClient.getExpandedGoldenRecordAuditTrail(record.uid || '') } else { - return await apiClient.getInteractionAuditTrail(record.uid || '') + return await apiClient.getExpandedInteractionAuditTrail(record.uid || '') } } throw new Error('Empty record') @@ -343,4 +343,4 @@ const RecordDetails = () => { ) } -export default RecordDetails +export default RecordDetails \ No newline at end of file diff --git a/JeMPI_Apps/JeMPI_UI/src/services/ApiClient.ts b/JeMPI_Apps/JeMPI_UI/src/services/ApiClient.ts index 4233f3674..e059f2576 100644 --- a/JeMPI_Apps/JeMPI_UI/src/services/ApiClient.ts +++ b/JeMPI_Apps/JeMPI_UI/src/services/ApiClient.ts @@ -1,5 +1,5 @@ import { AxiosInstance, AxiosRequestConfig } from 'axios' -import { AuditTrailEntries } from '../types/AuditTrail' +import { AuditTrailEntries, ExpandedAuditTrail } from '../types/AuditTrail' import { FieldChangeReq, Fields } from '../types/Fields' import { ApiSearchResponse, @@ -343,6 +343,24 @@ export class ApiClient { })) } + async getExpandedGoldenRecordAuditTrail(gid: string): Promise{ + const entries = await this.getGoldenRecordAuditTrail(gid); + + return entries.map((entry) => { + const expandedEntry: ExpandedAuditTrail = { + matching_rule: extractMatchingRule(entry.entry), + inserted_at: entry.inserted_at, + created_at: entry.created_at, + interaction_id: entry.interaction_id, + golden_id: entry.golden_id, + entry: entry.entry + + }; + + return expandedEntry; + }) + } + async getGoldenRecordAuditTrail(gid: string) { const { data: { entries } @@ -357,6 +375,24 @@ export class ApiClient { return entries } + async getExpandedInteractionAuditTrail(iid: string): Promise{ + const entries = await this.getInteractionAuditTrail(iid); + + return entries.map((entry) => { + const expandedEntry: ExpandedAuditTrail = { + matching_rule: null, + inserted_at: entry.inserted_at, + created_at: entry.created_at, + interaction_id: entry.interaction_id, + golden_id: entry.golden_id, + entry: entry.entry + + }; + + return expandedEntry; + }) + } + async getInteractionAuditTrail(iid: string) { const { data: { entries } @@ -419,6 +455,35 @@ export class ApiClient { } } +const extractMatchingRule = (input: string ) => { + const numberStr = extractScore(input) + + if (numberStr !== null) { + const number = parseFloat(numberStr); + + if (number === 1.0) { + return "DETERMINISTIC"; + } else if (number > 0.0 && number < 1.0) { + return "PROBABILISTIC"; + } + } + + return null; +}; + +const extractScore = (input: string) => { + const pattern = /\((\d+\.\d+)\)/; + const matches = input.match(pattern); + + if (matches !== null) { + return matches[1]; + } else { + return null; + } +}; + + + const apiClient = new ApiClient() export function getApiClient(config: Config) { diff --git a/JeMPI_Apps/JeMPI_UI/src/types/AuditTrail.ts b/JeMPI_Apps/JeMPI_UI/src/types/AuditTrail.ts index 953c5ced6..937f9e02d 100644 --- a/JeMPI_Apps/JeMPI_UI/src/types/AuditTrail.ts +++ b/JeMPI_Apps/JeMPI_UI/src/types/AuditTrail.ts @@ -9,3 +9,7 @@ export interface AuditTrail { export interface AuditTrailEntries { entries: Array } + +export interface ExpandedAuditTrail extends AuditTrail { + matching_rule: string | null +} diff --git a/JeMPI_Apps/JeMPI_UI/src/utils/constants.ts b/JeMPI_Apps/JeMPI_UI/src/utils/constants.ts index 12b08fefd..03130f16d 100644 --- a/JeMPI_Apps/JeMPI_UI/src/utils/constants.ts +++ b/JeMPI_Apps/JeMPI_UI/src/utils/constants.ts @@ -92,5 +92,13 @@ export const AUDIT_TRAIL_COLUMNS: GridColDef[] = [ disableColumnMenu: true, headerClassName: 'super-app-theme--header', flex: 1 + }, + { + field: 'matching_rule', + headerName: 'Matching Rule', + sortable: false, + disableColumnMenu: true, + headerClassName: 'super-app-theme--header', + flex: 1 } ]