Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added matching rule to audit trail table #181

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think you should create a new type. The change is too small (i.e not worth the extra complexities) . Just update the current version of the AuditTrail type with the additional type.

import { useLoaderData, useNavigate } from 'react-router-dom'
import { useConfig } from 'hooks/useConfig'

Expand Down Expand Up @@ -135,14 +135,14 @@ const RecordDetails = () => {
data: auditTrail,
isLoading: isAuditTrailLoading,
isFetching
} = useQuery<Array<AuditTrail>, AxiosError>({
} = useQuery<Array<ExpandedAuditTrail>, 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')
Expand Down Expand Up @@ -343,4 +343,4 @@ const RecordDetails = () => {
)
}

export default RecordDetails
export default RecordDetails
67 changes: 66 additions & 1 deletion JeMPI_Apps/JeMPI_UI/src/services/ApiClient.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -343,6 +343,24 @@ export class ApiClient {
}))
}

async getExpandedGoldenRecordAuditTrail(gid: string): Promise<ExpandedAuditTrail[]>{
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 }
Expand All @@ -357,6 +375,24 @@ export class ApiClient {
return entries
}

async getExpandedInteractionAuditTrail(iid: string): Promise<ExpandedAuditTrail[]>{
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 }
Expand Down Expand Up @@ -419,6 +455,35 @@ export class ApiClient {
}
}

const extractMatchingRule = (input: string ) => {
Copy link
Collaborator

@walisc walisc Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the correct way of doing this. As much as possible avoid using heuristic for your logic...i.e assuming the string will always be of a particular format , or if the score is x then it is DETERMINISTIC (this is actually not the case always)

What you want to do is send back this data with the correct info already, removing the need to use heuristic. i.e getGoldenRecordAuditTrail should return a json object like

[
   {
      "text": "Matched with score....etc",
      "matchType": "DETERMINISTIC"
   }
]

and then extract the information from there

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) {
Expand Down
4 changes: 4 additions & 0 deletions JeMPI_Apps/JeMPI_UI/src/types/AuditTrail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ export interface AuditTrail {
export interface AuditTrailEntries {
entries: Array<AuditTrail>
}

export interface ExpandedAuditTrail extends AuditTrail {
matching_rule: string | null
}
8 changes: 8 additions & 0 deletions JeMPI_Apps/JeMPI_UI/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]