Skip to content

Commit

Permalink
Merge pull request #327 from noharm-ai/develop
Browse files Browse the repository at this point in the history
v3.1.10
  • Loading branch information
marceloarocha authored Jun 1, 2024
2 parents ccf3bbb + 0463423 commit ae4af57
Show file tree
Hide file tree
Showing 16 changed files with 463 additions and 65 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "noharm-app",
"version": "3.1.9",
"version": "3.1.10",
"private": true,
"dependencies": {
"@ckeditor/ckeditor5-build-classic": "^35.0.1",
Expand Down
58 changes: 47 additions & 11 deletions src/features/reports/InterventionReport/Filter/Filter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PrinterOutlined,
DownloadOutlined,
QuestionCircleOutlined,
HistoryOutlined,
} from "@ant-design/icons";
import { useReactToPrint } from "react-to-print";

Expand All @@ -20,6 +21,8 @@ import {
setFilteredResult,
setFilters,
setHelpModal,
setHistoryModal,
setActiveReport,
} from "../InterventionReportSlice";
import { getReportData, filterAndExportCSV } from "../transformers";
import MainFilters from "./MainFilters";
Expand All @@ -30,6 +33,8 @@ import {
decompressDatasource,
} from "utils/report";
import useFetchReport from "hooks/useFetchReport";
import HistoryModal from "features/reports/components/HistoryModal/HistoryModal";
import HistoryAlert from "features/reports/components/HistoryAlert/HistoryAlert";

export default function Filter({ printRef }) {
const { t } = useTranslation();
Expand All @@ -46,6 +51,15 @@ export default function Filter({ printRef }) {
(state) => state.reportsArea.intervention.updatedAt
);
const userId = useSelector((state) => state.user.account.userId);
const activeReport = useSelector(
(state) => state.reportsArea.intervention.activeReport
);
const historyModalOpen = useSelector(
(state) => state.reportsArea.intervention.historyModal
);
const availableReports = useSelector(
(state) => state.reportsArea.intervention.availableReports
);
const handlePrint = useReactToPrint({
content: () => printRef.current,
onBeforeGetContent: onBeforePrint,
Expand All @@ -70,7 +84,7 @@ export default function Filter({ printRef }) {
prescriptionError: "",
};

useFetchReport({
const reportManager = useFetchReport({
action: fetchReportData,
reset,
onAfterFetch: (body, header) => {
Expand All @@ -92,6 +106,11 @@ export default function Filter({ printRef }) {
filterAndExportCSV(ds, currentFilters, t);
};

const loadArchive = (filename) => {
dispatch(setActiveReport(filename));
reportManager.loadArchive(filename);
};

const showHelp = () => {
dispatch(setHelpModal(true));
};
Expand All @@ -116,16 +135,28 @@ export default function Filter({ printRef }) {
<React.Fragment>
<Spin spinning={isFetching}>
{!isFetching && (
<AdvancedFilter
initialValues={initialValues}
mainFilters={<MainFilters />}
secondaryFilters={<SecondaryFilters />}
onSearch={search}
loading={isFetching}
skipFilterList={["dateRange", "segmentList", "departmentList"]}
memoryType={memoryFilterType}
skipMemoryList={{ dateRange: "daterange" }}
/>
<>
<AdvancedFilter
initialValues={initialValues}
mainFilters={<MainFilters />}
secondaryFilters={<SecondaryFilters />}
onSearch={search}
loading={isFetching}
skipFilterList={["dateRange", "segmentList", "departmentList"]}
memoryType={memoryFilterType}
skipMemoryList={{ dateRange: "daterange" }}
/>
<HistoryAlert
activeReport={activeReport}
loadArchive={loadArchive}
/>
<HistoryModal
availableReports={availableReports}
loadArchive={loadArchive}
open={historyModalOpen}
setOpen={setHistoryModal}
/>
</>
)}
</Spin>
{!isFetching && (
Expand All @@ -146,6 +177,11 @@ export default function Filter({ printRef }) {
onClick={exportCSV}
tooltip="Exportar CSV"
/>
<FloatButton
icon={<HistoryOutlined />}
onClick={() => dispatch(setHistoryModal(true))}
tooltip="Histórico"
/>
<FloatButton
icon={<PrinterOutlined />}
onClick={handlePrint}
Expand Down
22 changes: 21 additions & 1 deletion src/features/reports/InterventionReport/Filter/MainFilters.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useContext } from "react";
import { useSelector } from "react-redux";
import { useSelector, useDispatch } from "react-redux";
import { useTranslation } from "react-i18next";
import { HistoryOutlined } from "@ant-design/icons";

import { RangeDatePicker, Select } from "components/Inputs";
import Heading from "components/Heading";
Expand All @@ -11,9 +12,13 @@ import {
dateRangeValid,
getFilterDepartment,
} from "utils/report";
import Button from "components/Button";
import { setHistoryModal } from "../InterventionReportSlice";

export default function MainFilters() {
const { t } = useTranslation();
const dispatch = useDispatch();

const departments = useSelector(
(state) => state.reportsArea.intervention.departments
);
Expand All @@ -26,6 +31,12 @@ export default function MainFilters() {
);
const { values, setFieldValue } = useContext(AdvancedFilterContext);

const showHistory = () => {
document.querySelector(".ant-picker-presets li:nth-child(2)").click();

dispatch(setHistoryModal(true));
};

return (
<>
<Col md={7} lg={5} xxl={5}>
Expand All @@ -41,6 +52,15 @@ export default function MainFilters() {
popupClassName="noArrow"
allowClear={false}
style={{ width: "100%" }}
renderExtraFooter={() => (
<Button
icon={<HistoryOutlined />}
style={{ margin: "10px 0" }}
onClick={() => showHistory()}
>
Ver períodos anteriores
</Button>
)}
/>
</Col>
<Col md={7} lg={5} xxl={5}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ const initialState = {
error: null,
result: {},
},
availableReports: [],
activeReport: "current",
filters: {},
helpModal: false,
historyModal: false,
};

export const fetchReportData = createAsyncThunk(
Expand All @@ -45,7 +48,12 @@ export const fetchReportData = createAsyncThunk(
const decompressedResponse = new Response(cacheReadableStream);
const cache = await decompressedResponse.json();

return { ...response, cacheData: cache, gzipped };
return {
...response,
cacheData: cache,
gzipped,
availableReports: response.data.data.availableReports,
};
} catch (err) {
console.error(err);
return thunkAPI.rejectWithValue(err.response.data);
Expand All @@ -72,6 +80,12 @@ const interventionReportSlice = createSlice({
setHelpModal(state, action) {
state.helpModal = action.payload;
},
setHistoryModal(state, action) {
state.historyModal = action.payload;
},
setActiveReport(state, action) {
state.activeReport = action.payload;
},
},
extraReducers(builder) {
builder
Expand All @@ -86,6 +100,7 @@ const interventionReportSlice = createSlice({
state.list = action.payload.gzipped;
state.updatedAt = action.payload.cacheData.header.date;
state.version = action.payload.cacheData.header.version;
state.availableReports = action.payload.availableReports;
state.responsibles = getUniqList(
action.payload.cacheData.body,
"responsible"
Expand Down Expand Up @@ -121,6 +136,8 @@ export const {
setFilteredResult,
setFilters,
setHelpModal,
setHistoryModal,
setActiveReport,
} = interventionReportSlice.actions;

export default interventionReportSlice.reducer;
58 changes: 47 additions & 11 deletions src/features/reports/PatientDayReport/Filter/Filter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PrinterOutlined,
DownloadOutlined,
QuestionCircleOutlined,
HistoryOutlined,
} from "@ant-design/icons";
import { useReactToPrint } from "react-to-print";

Expand All @@ -20,6 +21,8 @@ import {
setFilteredResult,
setFilters,
setHelpModal,
setHistoryModal,
setActiveReport,
} from "../PatientDayReportSlice";
import { getReportData, filterAndExportCSV } from "../transformers";
import MainFilters from "./MainFilters";
Expand All @@ -30,6 +33,8 @@ import {
onAfterPrint,
decompressDatasource,
} from "utils/report";
import HistoryModal from "features/reports/components/HistoryModal/HistoryModal";
import HistoryAlert from "features/reports/components/HistoryAlert/HistoryAlert";

export default function Filter({ printRef }) {
const { t } = useTranslation();
Expand All @@ -44,6 +49,15 @@ export default function Filter({ printRef }) {
(state) => state.reportsArea.patientDay.updatedAt
);
const userId = useSelector((state) => state.user.account.userId);
const activeReport = useSelector(
(state) => state.reportsArea.patientDay.activeReport
);
const historyModalOpen = useSelector(
(state) => state.reportsArea.patientDay.historyModal
);
const availableReports = useSelector(
(state) => state.reportsArea.patientDay.availableReports
);
const handlePrint = useReactToPrint({
content: () => printRef.current,
onBeforeGetContent: onBeforePrint,
Expand All @@ -63,7 +77,7 @@ export default function Filter({ printRef }) {
maxScore: null,
};

useFetchReport({
const reportManager = useFetchReport({
action: fetchReportData,
reset,
onAfterFetch: (body, header) => {
Expand All @@ -85,6 +99,11 @@ export default function Filter({ printRef }) {
filterAndExportCSV(ds, currentFilters, t);
};

const loadArchive = (filename) => {
dispatch(setActiveReport(filename));
reportManager.loadArchive(filename);
};

const showHelp = () => {
dispatch(setHelpModal(true));
};
Expand All @@ -110,16 +129,28 @@ export default function Filter({ printRef }) {
<React.Fragment>
<Spin spinning={isFetching}>
{!isFetching && (
<AdvancedFilter
initialValues={initialValues}
mainFilters={<MainFilters />}
secondaryFilters={<SecondaryFilters />}
onSearch={search}
loading={isFetching}
skipFilterList={["dateRange"]}
memoryType={memoryFilterType}
skipMemoryList={{ dateRange: "daterange" }}
/>
<>
<AdvancedFilter
initialValues={initialValues}
mainFilters={<MainFilters />}
secondaryFilters={<SecondaryFilters />}
onSearch={search}
loading={isFetching}
skipFilterList={["dateRange"]}
memoryType={memoryFilterType}
skipMemoryList={{ dateRange: "daterange" }}
/>
<HistoryAlert
activeReport={activeReport}
loadArchive={loadArchive}
/>
<HistoryModal
availableReports={availableReports}
loadArchive={loadArchive}
open={historyModalOpen}
setOpen={setHistoryModal}
/>
</>
)}
</Spin>
{!isFetching && (
Expand All @@ -140,6 +171,11 @@ export default function Filter({ printRef }) {
onClick={exportCSV}
tooltip="Exportar CSV"
/>
<FloatButton
icon={<HistoryOutlined />}
onClick={() => dispatch(setHistoryModal(true))}
tooltip="Histórico"
/>
<FloatButton
icon={<PrinterOutlined />}
onClick={handlePrint}
Expand Down
22 changes: 21 additions & 1 deletion src/features/reports/PatientDayReport/Filter/MainFilters.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useContext } from "react";
import { useSelector } from "react-redux";
import { useSelector, useDispatch } from "react-redux";
import { useTranslation } from "react-i18next";
import { HistoryOutlined } from "@ant-design/icons";

import { RangeDatePicker, Select } from "components/Inputs";
import Heading from "components/Heading";
Expand All @@ -11,9 +12,13 @@ import {
dateRangeValid,
getFilterDepartment,
} from "utils/report";
import Button from "components/Button";
import { setHistoryModal } from "../PatientDayReportSlice";

export default function MainFilters() {
const { t } = useTranslation();
const dispatch = useDispatch();

const departments = useSelector(
(state) => state.reportsArea.patientDay.departments
);
Expand All @@ -28,6 +33,12 @@ export default function MainFilters() {

const rangePresets = getDateRangePresets(reportDate);

const showHistory = () => {
document.querySelector(".ant-picker-presets li:nth-child(2)").click();

dispatch(setHistoryModal(true));
};

return (
<>
<Col md={7} lg={5} xxl={5}>
Expand All @@ -43,6 +54,15 @@ export default function MainFilters() {
popupClassName="noArrow"
allowClear={false}
style={{ width: "100%" }}
renderExtraFooter={() => (
<Button
icon={<HistoryOutlined />}
style={{ margin: "10px 0" }}
onClick={() => showHistory()}
>
Ver períodos anteriores
</Button>
)}
/>
</Col>
<Col md={7} lg={5} xxl={5}>
Expand Down
Loading

0 comments on commit ae4af57

Please sign in to comment.