Skip to content

Commit

Permalink
Tries to solve #63
Browse files Browse the repository at this point in the history
  • Loading branch information
pfw13 committed Apr 25, 2024
1 parent 76bff52 commit 0d02eaa
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 62 deletions.
5 changes: 5 additions & 0 deletions apps/react/src/epilog/plain-js/epilog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ declare const debugfinds: (
) => string[] | string[][];

declare const definemorerules: Function;

declare const eliminatefacts: (
symbol: string,
dataset: ReturnType<typeof readdata>,
) => ReturnType<typeof readdata>;
141 changes: 79 additions & 62 deletions apps/react/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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<string, string> ([
["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<string, string>([
["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);
Expand All @@ -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],
Expand Down
3 changes: 3 additions & 0 deletions apps/react/src/utils/removeFromDataset.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @deprecated Use instead: http://epilog.stanford.edu/documentation/epilogjs/eliminatefacts.php
*/
export function removeFromDataset(
id: string,
dataset: ReturnType<typeof definemorefacts>,
Expand Down
Binary file modified apps/server/var/sessions.db
Binary file not shown.
Binary file modified apps/server/var/sqlite.db
Binary file not shown.

0 comments on commit 0d02eaa

Please sign in to comment.