diff --git a/apps/react/src/epilog/plain-js/epilog.d.ts b/apps/react/src/epilog/plain-js/epilog.d.ts index 276143c..fd3c3da 100644 --- a/apps/react/src/epilog/plain-js/epilog.d.ts +++ b/apps/react/src/epilog/plain-js/epilog.d.ts @@ -22,3 +22,8 @@ declare const debugfinds: ( ) => string[] | string[][]; declare const definemorerules: Function; + +declare const eliminatefacts: ( + symbol: string, + dataset: ReturnType, +) => ReturnType; diff --git a/apps/react/src/pages/Dashboard.tsx b/apps/react/src/pages/Dashboard.tsx index 8141558..208a13a 100644 --- a/apps/react/src/pages/Dashboard.tsx +++ b/apps/react/src/pages/Dashboard.tsx @@ -1,13 +1,16 @@ +import { ROUTES } from "common"; import { useCallback, useContext, useMemo } from "react"; +import { useUserDataset } from "../api/userDataset"; import Container from "../components/Container"; import Heading from "../components/Heading"; import ResourceList from "../components/ResourceList"; -import { UserDatasetContext } from "../contexts/userDatasetContext"; -import { getExistingIds, getPersonDetailsById, getClaimDetailsById } from "../utils/epilogUtils"; -import { ROUTES } from "common"; import { LoginContext } from "../contexts/loginContext"; -import { useUserDataset } from "../api/userDataset"; -import { removeFromDataset } from "../utils/removeFromDataset"; +import { UserDatasetContext } from "../contexts/userDatasetContext"; +import { + getClaimDetailsById, + getExistingIds, + getPersonDetailsById, +} from "../utils/epilogUtils"; export default function Dashboard() { const sessionUser = useContext(LoginContext); @@ -26,65 +29,79 @@ export default function Dashboard() { [policyIds], ); - const personItems = useMemo(() => personIds.map((id) => { - const details = getPersonDetailsById(id, dataset); - - // If details exist, structure them with separate fields - if (details) { - return { - id: details.id, // Assuming you always have an ID - label: details.id, - dob: details.dob, - occupation: details.occupation, - immunocompromised: details.immunocompromised - }; - } else { - // Provide a fallback structure for missing details - return { - id: id, - label: id, - dob: 'Unknown', - occupation: 'Unknown', - immunocompromised: 'Unknown' - }; - } - }), [personIds, dataset]); + const personItems = useMemo( + () => + personIds.map((id) => { + const details = getPersonDetailsById(id, dataset); + + // If details exist, structure them with separate fields + if (details) { + return { + id: details.id, // Assuming you always have an ID + label: details.id, + dob: details.dob, + occupation: details.occupation, + immunocompromised: details.immunocompromised, + }; + } else { + // Provide a fallback structure for missing details + return { + id: id, + label: id, + dob: "Unknown", + occupation: "Unknown", + immunocompromised: "Unknown", + }; + } + }), + [personIds, dataset], + ); - const claimItems = useMemo(() => claimIds.map((id) => { - let serviceTypeToLabel = (serviceType : string) : string | false => { - let serviceTypeToLabelMap = new Map ([ - ["contraceptives", "Contraceptives"], - ["covidVaccine", "COVID-19 Vaccine"], - ]); - - return serviceTypeToLabelMap.has(serviceType) ? serviceTypeToLabelMap.get(serviceType) as string : false; - } + const claimItems = useMemo( + () => + claimIds.map((id) => { + let serviceTypeToLabel = (serviceType: string): string | false => { + let serviceTypeToLabelMap = new Map([ + ["contraceptives", "Contraceptives"], + ["covidVaccine", "COVID-19 Vaccine"], + ]); - const details = getClaimDetailsById(id, dataset); // Use getClaimDetailsById - return details ? { - id: details.id, - label: serviceTypeToLabel(details.serviceType) || 'Unknown Service Type', - policyId: details.policyId || 'Unknown Policy', - claimantId: details.claimantId || 'Unknown Claimant', - time: details.time || 'Unknown Time', - hospitalStart: details.hospitalStart || 'Unknown Start Time', - hospitalEnd: details.hospitalEnd || 'Unknown End Time', - hospitalName: details.hospitalName || 'Unknown Hospital', - vaccine: details.vaccine || 'Unknown Vaccine', - vaccineBrand: details.vaccineBrand || 'Unknown Brand', - vaccineDoseCount: details.vaccineDoseCount || 0, - consequenceOfOccupation: details.consequenceOfOccupation || 'Unknown', - location: details.location || 'Unknown Location', - previousVaccinesPfizer: details.previousVaccinesPfizer || 0, - previousVaccinesModerna: details.previousVaccinesModerna || 0, - previousVaccinesOther: details.previousVaccinesOther || 0, - } : { - id, - label: 'Missing Details', - // Default values for missing claim details - }; - }), [claimIds, dataset]); + return serviceTypeToLabelMap.has(serviceType) + ? (serviceTypeToLabelMap.get(serviceType) as string) + : false; + }; + const details = getClaimDetailsById(id, dataset); // Use getClaimDetailsById + return details + ? { + id: details.id, + label: + serviceTypeToLabel(details.serviceType) || + "Unknown Service Type", + policyId: details.policyId || "Unknown Policy", + claimantId: details.claimantId || "Unknown Claimant", + time: details.time || "Unknown Time", + hospitalStart: details.hospitalStart || "Unknown Start Time", + hospitalEnd: details.hospitalEnd || "Unknown End Time", + hospitalName: details.hospitalName || "Unknown Hospital", + vaccine: details.vaccine || "Unknown Vaccine", + vaccineBrand: details.vaccineBrand || "Unknown Brand", + vaccineDoseCount: details.vaccineDoseCount || 0, + consequenceOfOccupation: + details.consequenceOfOccupation || "Unknown", + location: details.location || "Unknown Location", + previousVaccinesPfizer: details.previousVaccinesPfizer || 0, + previousVaccinesModerna: details.previousVaccinesModerna || 0, + previousVaccinesOther: details.previousVaccinesOther || 0, + } + : { + id, + label: "Missing Details", + // Default values for missing claim details + }; + }), + [claimIds, dataset], + ); console.log("claimItems", claimItems); console.log("personItems", personItems); @@ -93,7 +110,7 @@ export default function Dashboard() { const onClickRemoveClaim = useCallback( (claimId: string) => { - const newDataset = removeFromDataset(claimId, dataset); + const newDataset = eliminatefacts(claimId, dataset); mutation.mutate(newDataset); }, [dataset, mutation], diff --git a/apps/react/src/utils/removeFromDataset.ts b/apps/react/src/utils/removeFromDataset.ts index 411fa6f..af0d8f1 100644 --- a/apps/react/src/utils/removeFromDataset.ts +++ b/apps/react/src/utils/removeFromDataset.ts @@ -1,3 +1,6 @@ +/** + * @deprecated Use instead: http://epilog.stanford.edu/documentation/epilogjs/eliminatefacts.php + */ export function removeFromDataset( id: string, dataset: ReturnType, diff --git a/apps/server/var/sessions.db b/apps/server/var/sessions.db index 39d72a4..0c4d47d 100644 Binary files a/apps/server/var/sessions.db and b/apps/server/var/sessions.db differ diff --git a/apps/server/var/sqlite.db b/apps/server/var/sqlite.db index 206b1a2..931363f 100644 Binary files a/apps/server/var/sqlite.db and b/apps/server/var/sqlite.db differ