Skip to content

Commit

Permalink
bug fix, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Chen committed Aug 25, 2023
1 parent af4ce2a commit 9d5e4dd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 43 deletions.
24 changes: 2 additions & 22 deletions patientsearch/src/js/components/patientList/MyPatientsCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import ErrorIcon from "@material-ui/icons/ReportProblemOutlined";
import Tooltip from "@material-ui/core/Tooltip";
import Typography from "@material-ui/core/Typography";
import {usePatientListContext} from "../../context/PatientListContextProvider";
import {
getPatientIdsByCareTeamParticipant,
} from "../../helpers/utility";

const checkBoxStyles = makeStyles((theme) => {
return {
Expand Down Expand Up @@ -42,32 +39,15 @@ export default function MyPatientsCheckbox({
label
}) {
const {
setPatientIdsByCareTeamParticipant = function() {},
user,
onMyPatientsCheckboxChange,
userError,
tableRef
} = usePatientListContext();
const checkboxClasses = checkBoxStyles();
const formControlClasses = formControlStyles();
const [state, setState] = useState(false);
const handleChange = (event) => {
setState(event.target.checked);
if (!event.target.checked) {
setPatientIdsByCareTeamParticipant(null);
if (tableRef.current) tableRef.current.onQueryChange();
if (changeEvent) changeEvent();
return;
}
// NOTE - retrieving id(s) of patients whose care team the practitioner is part of
getPatientIdsByCareTeamParticipant(user ? user.practitionerId : null).then(
(result) => {
setPatientIdsByCareTeamParticipant(
result && result.length ? result : [-1]
);
if (tableRef.current) tableRef.current.onQueryChange();
if (changeEvent) changeEvent();
}
);
onMyPatientsCheckboxChange(event, changeEvent);
};
return (
<div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion patientsearch/src/js/components/patientList/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PatientListContextProvider from "../../context/PatientListContextProvider";
import PatientListTable from "./PatientListTable";
import PatientListTable from "./PatientList";

export default function MainContent() {
return (
Expand Down
49 changes: 29 additions & 20 deletions patientsearch/src/js/context/PatientListContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getAppLaunchURL,
getLocalDateTimeString,
getClientsByRequiredRoles,
getPatientIdsByCareTeamParticipant,
getTimeAgoDisplay,
isString,
putPatientData,
Expand Down Expand Up @@ -180,7 +181,7 @@ export default function PatientListContextProvider({ children }) {
// open a dialog here so user can select which one to launch?
if (!launchParams && hasMultipleSoFClients()) {
setCurrentRow(rowData);
setOpenLoadingModal(false);
// setOpenLoadingModal(false);
setOpenLaunchInfoModal(true);
return;
}
Expand All @@ -197,13 +198,11 @@ export default function PatientListContextProvider({ children }) {
};
const handleLaunchError = (message) => {
setErrorMessage(message || "Unable to launch application.");
setOpenLoadingModal(false);
toTop();
return false;
};
const onLaunchDialogClose = () => {
setOpenLaunchInfoModal(false);
_handleRefresh();
};
const onFiltersDidChange = (filters) => {
clearTimeout(filterIntervalId);
Expand Down Expand Up @@ -273,11 +272,8 @@ export default function PatientListContextProvider({ children }) {
const handleMenuSelect = (event) => {
event.stopPropagation();
const selectedTarget = event.target.getAttribute("datatopic");
if (!selectedTarget) return;
setSelectedMenuItem(selectedTarget);
if (!selectedTarget) {
handleMenuClose();
return;
}
setTimeout(function () {
currentRow.tableData.showDetailPanel = true;
handleToggleDetailPanel(currentRow);
Expand Down Expand Up @@ -319,6 +315,24 @@ export default function PatientListContextProvider({ children }) {
setFilterByTestPatients(event.target.checked);
if (tableRef.current) tableRef.current.onQueryChange();
};
const onMyPatientsCheckboxChange = (event, changeEvent) => {
if (!event.target.checked) {
setPatientIdsByCareTeamParticipant(null);
if (tableRef.current) tableRef.current.onQueryChange();
if (changeEvent) changeEvent();
return;
}
// NOTE - retrieving id(s) of patients whose care team the practitioner is part of
getPatientIdsByCareTeamParticipant(user ? user.practitionerId : null).then(
(result) => {
setPatientIdsByCareTeamParticipant(
result && result.length ? result : [-1]
);
if (tableRef.current) tableRef.current.onQueryChange();
if (changeEvent) changeEvent();
}
);
};
const shouldShowLegend = () => containNoPMPRow;
const _getSelectedItemComponent = (selectedMenuItem, rowData) => {
let selected = menuItems.filter(
Expand Down Expand Up @@ -400,8 +414,7 @@ export default function PatientListContextProvider({ children }) {
if (dataType === "timeago" && value) {
value = value ? getTimeAgoDisplay(new Date(value)) : "--";
}
if (col.field)
rowData[col.field] = value;
if (col.field) rowData[col.field] = value;
});
return rowData;
})
Expand Down Expand Up @@ -609,6 +622,7 @@ export default function PatientListContextProvider({ children }) {
(e) => handleErrorCallback(e)
)
.then((result) => {
setOpenLoadingModal(false);
let response = result;
if (result && result.entry && result.entry[0]) {
response = result.entry[0];
Expand All @@ -630,20 +644,18 @@ export default function PatientListContextProvider({ children }) {
(appClients.length === 1 ||
(hasMultipleSoFClients() &&
getAppSettingByKey("LAUNCH_AFTER_PATIENT_CREATION")));
if (shouldLaunchApp()) {

if (shouldLaunchApp) {
// use config variable to determine whether to launch the first defined client application after account creation
handleLaunchApp(
_formatData(response)[0],
appClients[0]
);
handleLaunchApp(_formatData(response)[0], appClients[0]);
} else {
_handleRefresh();
_handleRefresh();
}
})
.catch((e) => {
//log error to console
console.log(`Patient search error: ${e}`);
setOpenLoadingModal(false);
handleLaunchError(fetchErrorMessage + `<p>See console for detail.</p>`);
});
};
Expand Down Expand Up @@ -916,11 +928,9 @@ export default function PatientListContextProvider({ children }) {
handleErrorCallback,
handleLaunchApp,
handleLaunchError,
handleMenuClick,
handleMenuClose,
handleMenuSelect,
handleSearch,
handleToggleDetailPanel,
hasMultipleSoFClients,
hasSoFClients,
getAppSettingByKey,
Expand All @@ -937,6 +947,7 @@ export default function PatientListContextProvider({ children }) {
onDetailPanelClose,
onFiltersDidChange,
onLaunchDialogClose,
onMyPatientsCheckboxChange,
onTestPatientsCheckboxChange,
shouldShowLegend,
shouldHideMoreMenu,
Expand All @@ -947,8 +958,6 @@ export default function PatientListContextProvider({ children }) {
currentRow,
data,
errorMessage,
filterByTestPatients,
setFilterByTestPatients,
openLoadingModal,
openLaunchInfoModal,
pagination,
Expand Down

0 comments on commit 9d5e4dd

Please sign in to comment.