박정하 박정하 2023-07-03
230703 박정하 복용률 관련 작업중
@e587547454bd5887d35991e91d721c649f26980f
client/resources/css/main.css
--- client/resources/css/main.css
+++ client/resources/css/main.css
@@ -1594,4 +1594,9 @@
 
 .span4 {
   grid-column: span 4;
+}
+
+.table-size-fix {
+  max-height: 220px;
+  overflow-y: auto;
 }
(No newline at end of file)
client/views/component/chart/Chart2_govern.jsx
--- client/views/component/chart/Chart2_govern.jsx
+++ client/views/component/chart/Chart2_govern.jsx
@@ -2,142 +2,99 @@
 import * as am5 from "@amcharts/amcharts5";
 import * as am5xy from "@amcharts/amcharts5/xy";
 import am5themes_Animated from "@amcharts/amcharts5/themes/Animated";
+import CommonUtil from "../../../resources/js/CommonUtil";
 
-class Chart2 extends Component {
-  componentDidMount() {
+export default function Chart2({ data }) {
+  const createChart = () => {
+    console.log('createChart2 data : ', data);
+
     let root = am5.Root.new("Chart2");
-
     root._logo.dispose();
+
+
     // Set themes
     // https://www.amcharts.com/docs/v5/concepts/themes/
-    root.setThemes([am5themes_Animated.new(root)]);
+    root.setThemes([
+      am5themes_Animated.new(root)
+    ]);
+
 
     // Create chart
     // https://www.amcharts.com/docs/v5/charts/xy-chart/
-    let chart = root.container.children.push(
-      am5xy.XYChart.new(root, {
-        panX: true,
-        panY: true,
-        wheelX: "panX",
-        wheelY: "zoomX",
-        pinchZoomX: true,
-      })
-    );
+    let chart = root.container.children.push(am5xy.XYChart.new(root, {
+      panX: true,
+      panY: true,
+      wheelX: "panX",
+      wheelY: "zoomX",
+      pinchZoomX: true
+    }));
 
-    chart.get("colors").set("step", 3);
 
     // Add cursor
     // https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/
-    let cursor = chart.set("cursor", am5xy.XYCursor.new(root, {}));
+    let cursor = chart.set("cursor", am5xy.XYCursor.new(root, {
+      behavior: "none"
+    }));
     cursor.lineY.set("visible", false);
+
 
     // Create axes
     // https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
-    let xAxis = chart.xAxes.push(
-      am5xy.DateAxis.new(root, {
-        maxDeviation: 0.3,
-        baseInterval: {
-          timeUnit: "day",
-          count: 1,
-        },
-        renderer: am5xy.AxisRendererX.new(root, {}),
-        tooltip: am5.Tooltip.new(root, {}),
-      })
-    );
+    let xAxis = chart.xAxes.push(am5xy.DateAxis.new(root, {
+      maxDeviation: 0.2,
+      baseInterval: {
+        timeUnit: "day",
+        count: 1
+      },
+      renderer: am5xy.AxisRendererX.new(root, {}),
+      tooltip: am5.Tooltip.new(root, {})
+    }));
 
-    let yAxis = chart.yAxes.push(
-      am5xy.ValueAxis.new(root, {
-        maxDeviation: 0.3,
-        renderer: am5xy.AxisRendererY.new(root, {}),
-      })
-    );
+    let yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
+      renderer: am5xy.AxisRendererY.new(root, {})
+    }));
 
-    // Create series
+
+    // Add series
     // https://www.amcharts.com/docs/v5/charts/xy-chart/series/
-    let series = chart.series.push(
-      am5xy.LineSeries.new(root, {
-        name: "Series 1",
-        xAxis: xAxis,
-        yAxis: yAxis,
-        valueYField: "value",
-        valueXField: "date",
-        tooltip: am5.Tooltip.new(root, {
-          labelText: "{valueY}",
-        }),
+    let series = chart.series.push(am5xy.LineSeries.new(root, {
+      name: "Series",
+      xAxis: xAxis,
+      yAxis: yAxis,
+      valueYField: "average",
+      valueXField: "date",
+      tooltip: am5.Tooltip.new(root, {
+        labelText: "{valueY}"
       })
-    );
-    series.strokes.template.setAll({
-      strokeWidth: 2,
-      strokeDasharray: [3, 3],
-    });
+    }));
+
+
+    // Add scrollbar
+    // https://www.amcharts.com/docs/v5/charts/xy-chart/scrollbars/
+    chart.set("scrollbarX", am5.Scrollbar.new(root, {
+      orientation: "horizontal"
+    }));
+
 
     // Set data
-    let data = [
-      {
-        date: new Date(2022, 8).getTime(),
-        value: 0,
-      },
-      {
-        date: new Date(2022, 9).getTime(),
-        value: 10,
-      },
-      {
-        date: new Date(2022, 10).getTime(),
-        value: 10,
-      },
-      {
-        date: new Date(2022, 11).getTime(),
-        value: 20,
-      },
-      {
-        date: new Date(2022, 12).getTime(),
-        value: 50,
-      },
-      {
-        date: new Date(2023, 1).getTime(),
-        value: 30,
-      },
-      {
-        date: new Date(2023, 2).getTime(),
-        value: 70,
-      },
-      {
-        date: new Date(2023, 3).getTime(),
-        value: 60,
-      },
-      {
-        date: new Date(2023, 4).getTime(),
-        value: 80,
-      },
-      {
-        date: new Date(2023, 5).getTime(),
-        value: 70,
-      },
-      {
-        date: new Date(2023, 6).getTime(),
-        value: 80,
-      },
-    ];
-
     series.data.setAll(data);
+
 
     // Make stuff animate on load
     // https://www.amcharts.com/docs/v5/concepts/animations/
     series.appear(1000);
     chart.appear(1000, 100);
 
-    this.root = root;
   }
 
-  componentWillUnmount() {
-    if (this.root) {
-      this.root.dispose();
+  React.useEffect(() => {
+    console.log('React.useEffect chart2 data : ', data);
+    if (CommonUtil.isEmpty(data) == false) {
+      createChart();
     }
-  }
+  }, [data])
 
-  render() {
-    return <div id="Chart2" style={{ width: "100%", height: "15vh" }}></div>;
-  }
-}
-
-export default Chart2;
+  return (
+    <div id="Chart2" style={{ width: "100%", height: "15vh" }}></div>
+  )
+}
(No newline at end of file)
client/views/component/chart/Chart5_agency.jsx
--- client/views/component/chart/Chart5_agency.jsx
+++ client/views/component/chart/Chart5_agency.jsx
@@ -7,53 +7,53 @@
   componentDidMount() {
     let root = am5.Root.new("Chart5");
 
-   
-// Set themes
-// https://www.amcharts.com/docs/v5/concepts/themes/
-root.setThemes([
-  am5themes_Animated.new(root)
-]);
+
+    // Set themes
+    // https://www.amcharts.com/docs/v5/concepts/themes/
+    root.setThemes([
+      am5themes_Animated.new(root)
+    ]);
 
 
-// Create chart
-// https://www.amcharts.com/docs/v5/charts/percent-charts/sliced-chart/
-let chart = root.container.children.push(am5percent.SlicedChart.new(root, {
-  layout: root.verticalLayout
-}));
+    // Create chart
+    // https://www.amcharts.com/docs/v5/charts/percent-charts/sliced-chart/
+    let chart = root.container.children.push(am5percent.SlicedChart.new(root, {
+      layout: root.verticalLayout
+    }));
 
 
-// Create series
-// https://www.amcharts.com/docs/v5/charts/percent-charts/sliced-chart/#Series
-let series = chart.series.push(am5percent.PictorialStackedSeries.new(root, {
-  alignLabels: true,
-  orientation: "vertical",
-  valueField: "value",
-  categoryField: "category",
-  svgPath: "M53.5,476c0,14,6.833,21,20.5,21s20.5-7,20.5-21V287h21v189c0,14,6.834,21,20.5,21 c13.667,0,20.5-7,20.5-21V154h10v116c0,7.334,2.5,12.667,7.5,16s10.167,3.333,15.5,0s8-8.667,8-16V145c0-13.334-4.5-23.667-13.5-31 s-21.5-11-37.5-11h-82c-15.333,0-27.833,3.333-37.5,10s-14.5,17-14.5,31v133c0,6,2.667,10.333,8,13s10.5,2.667,15.5,0s7.5-7,7.5-13 V154h10V476 M61.5,42.5c0,11.667,4.167,21.667,12.5,30S92.333,85,104,85s21.667-4.167,30-12.5S146.5,54,146.5,42 c0-11.335-4.167-21.168-12.5-29.5C125.667,4.167,115.667,0,104,0S82.333,4.167,74,12.5S61.5,30.833,61.5,42.5z"
-}));
+    // Create series
+    // https://www.amcharts.com/docs/v5/charts/percent-charts/sliced-chart/#Series
+    let series = chart.series.push(am5percent.PictorialStackedSeries.new(root, {
+      alignLabels: true,
+      orientation: "vertical",
+      valueField: "value",
+      categoryField: "category",
+      svgPath: "M53.5,476c0,14,6.833,21,20.5,21s20.5-7,20.5-21V287h21v189c0,14,6.834,21,20.5,21 c13.667,0,20.5-7,20.5-21V154h10v116c0,7.334,2.5,12.667,7.5,16s10.167,3.333,15.5,0s8-8.667,8-16V145c0-13.334-4.5-23.667-13.5-31 s-21.5-11-37.5-11h-82c-15.333,0-27.833,3.333-37.5,10s-14.5,17-14.5,31v133c0,6,2.667,10.333,8,13s10.5,2.667,15.5,0s7.5-7,7.5-13 V154h10V476 M61.5,42.5c0,11.667,4.167,21.667,12.5,30S92.333,85,104,85s21.667-4.167,30-12.5S146.5,54,146.5,42 c0-11.335-4.167-21.168-12.5-29.5C125.667,4.167,115.667,0,104,0S82.333,4.167,74,12.5S61.5,30.833,61.5,42.5z"
+    }));
 
-series.labelsContainer.set("width", 100);
-series.ticks.template.set("location", 0.6);
+    series.labelsContainer.set("width", 100);
+    series.ticks.template.set("location", 0.6);
 
 
-// Set data
-// https://www.amcharts.com/docs/v5/charts/percent-charts/sliced-chart/#Setting_data
-series.data.setAll([
-  { value: 10, category: "부계면" },
-  { value: 9, category: "소보면" },
-  { value: 6, category: "군위읍" },
-  { value: 5, category: "우보면" },
-  { value: 4, category: "의흥면" },
-  { value: 3, category: "삼국유사면" },
-  { value: 3, category: "산성면" },
-  { value: 2, category: "효령면" }
-]);
+    // Set data
+    // https://www.amcharts.com/docs/v5/charts/percent-charts/sliced-chart/#Setting_data
+    series.data.setAll([
+      { value: 10, category: "부계면" },
+      { value: 9, category: "소보면" },
+      { value: 6, category: "군위읍" },
+      { value: 5, category: "우보면" },
+      { value: 4, category: "의흥면" },
+      { value: 3, category: "삼국유사면" },
+      { value: 3, category: "산성면" },
+      { value: 2, category: "효령면" }
+    ]);
 
 
-// Play initial series animation
-// https://www.amcharts.com/docs/v5/concepts/animations/#Animation_of_series
-chart.appear(1000, 100);
- // end am5.ready()
+    // Play initial series animation
+    // https://www.amcharts.com/docs/v5/concepts/animations/#Animation_of_series
+    chart.appear(1000, 100);
+    // end am5.ready()
     this.root = root;
   }
   componentWillUnmount() {
client/views/component/chart/Chart8.jsx
--- client/views/component/chart/Chart8.jsx
+++ client/views/component/chart/Chart8.jsx
@@ -1,14 +1,20 @@
 import React, { Component } from "react";
 import * as am5 from "@amcharts/amcharts5";
 import * as am5xy from "@amcharts/amcharts5/xy";
-import * as am5percent from "@amcharts/amcharts5/percent";
 import am5themes_Animated from "@amcharts/amcharts5/themes/Animated";
 import CommonUtil from "../../../resources/js/CommonUtil";
 
 
-export default function Chart8() {
+export default function Chart8({ data }) {
   const createChart = () => {
+    console.log('createChart8 data : ', data);
+
+    /* Chart code */
+
+    // Create root element
+    // https://www.amcharts.com/docs/v5/getting-started/#Root_element
     let root = am5.Root.new("Chart8");
+    root._logo.dispose();
 
 
     // Set themes
@@ -41,7 +47,7 @@
 
     let yAxis = chart.yAxes.push(am5xy.CategoryAxis.new(root, {
       maxDeviation: 0,
-      categoryField: "senior_name",
+      categoryField: "user_name",
       renderer: yRenderer,
       tooltip: am5.Tooltip.new(root, { themeTags: ["axis"] })
     }));
@@ -62,8 +68,8 @@
       name: "Series 1",
       xAxis: xAxis,
       yAxis: yAxis,
-      valueXField: "percent",
-      categoryYField: "senior_name",
+      valueXField: "average",
+      categoryYField: "user_name",
       tooltip: am5.Tooltip.new(root, {
         pointerOrientation: "left",
         labelText: "{valueX}"
@@ -89,20 +95,6 @@
 
 
     // Set data
-    let data = [
-      {
-        "senior_name": "보일",
-        "percent": 28
-      },
-      {
-        "senior_name": "보이",
-        "percent": 6
-      },
-      {
-        "senior_name": "보삼",
-        "percent": 16
-      },
-    ]
     yAxis.data.setAll(data);
     series.data.setAll(data);
     sortCategoryAxis();
@@ -172,11 +164,13 @@
   }
 
   React.useEffect(() => {
-    createChart();
-  }, [])
+    console.log('React.useEffect chart8 data : ', data);
+    if (CommonUtil.isEmpty(data) == false) {
+      createChart();
+    }
+  }, [data])
 
   return (
     <div id="Chart8" style={{ width: "100%", height: "100%" }}></div>
   )
-
 }
(No newline at end of file)
 
client/views/component/chart/Chart8_government.jsx (deleted)
--- client/views/component/chart/Chart8_government.jsx
@@ -1,170 +0,0 @@
-import React, { Component } from "react";
-import * as am5 from "@amcharts/amcharts5";
-import * as am5xy from "@amcharts/amcharts5/xy";
-import * as am5percent from "@amcharts/amcharts5/percent";
-import am5themes_Animated from "@amcharts/amcharts5/themes/Animated";
-import CommonUtil from "../../../resources/js/CommonUtil";
-
-
-export default function Chart8(chartData) {
-  console.log("chartData : ", chartData.data)
-
-  const createChart = (chartData) => {
-    let root = am5.Root.new("Chart8");
-
-    // Set themes
-    // https://www.amcharts.com/docs/v5/concepts/themes/
-    root.setThemes([
-      am5themes_Animated.new(root)
-    ]);
-
-
-    // Create chart
-    // https://www.amcharts.com/docs/v5/charts/xy-chart/
-    let chart = root.container.children.push(am5xy.XYChart.new(root, {
-      panX: false,
-      panY: false,
-      wheelX: "none",
-      wheelY: "none"
-    }));
-
-    // We don't want zoom-out button to appear while animating, so we hide it
-    chart.zoomOutButton.set("forceHidden", true);
-
-
-    // Create axes
-    // https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
-    let yRenderer = am5xy.AxisRendererY.new(root, {
-      minGridDistance: 30
-    });
-
-    yRenderer.grid.template.set("location", 1);
-
-    let yAxis = chart.yAxes.push(am5xy.CategoryAxis.new(root, {
-      maxDeviation: 0,
-      categoryField: "senior_name",
-      renderer: yRenderer,
-      tooltip: am5.Tooltip.new(root, { themeTags: ["axis"] })
-    }));
-
-    let xAxis = chart.xAxes.push(am5xy.ValueAxis.new(root, {
-      maxDeviation: 0,
-      min: 0,
-      extraMax: 0.1,
-      renderer: am5xy.AxisRendererX.new(root, {
-        strokeOpacity: 0.1
-      })
-    }));
-
-
-    // Add series
-    // https://www.amcharts.com/docs/v5/charts/xy-chart/series/
-    let series = chart.series.push(am5xy.ColumnSeries.new(root, {
-      name: "Series 1",
-      xAxis: xAxis,
-      yAxis: yAxis,
-      valueXField: "percent",
-      categoryYField: "user_name",
-      tooltip: am5.Tooltip.new(root, {
-        pointerOrientation: "left",
-        labelText: "{valueX}"
-      })
-    }));
-
-
-    // Rounded corners for columns
-    series.columns.template.setAll({
-      cornerRadiusTR: 5,
-      cornerRadiusBR: 5,
-      strokeOpacity: 0
-    });
-
-    // Make each column to be of a different color
-    series.columns.template.adapters.add("fill", function (fill, target) {
-      return chart.get("colors").getIndex(series.columns.indexOf(target));
-    });
-
-    series.columns.template.adapters.add("stroke", function (stroke, target) {
-      return chart.get("colors").getIndex(series.columns.indexOf(target));
-    });
-
-
-    // Set data
-    let data = chartData.data;
-    yAxis.data.setAll(data);
-    series.data.setAll(data);
-    sortCategoryAxis();
-
-    // Get series item by category
-    function getSeriesItem(category) {
-      for (var i = 0; i < series.dataItems.length; i++) {
-        let dataItem = series.dataItems[i];
-        if (dataItem.get("categoryY") == category) {
-          return dataItem;
-        }
-      }
-    }
-
-    chart.set("cursor", am5xy.XYCursor.new(root, {
-      behavior: "none",
-      xAxis: xAxis,
-      yAxis: yAxis
-    }));
-
-
-    // Axis sorting
-    function sortCategoryAxis() {
-
-      // Sort by value
-      series.dataItems.sort(function (x, y) {
-        return x.get("valueX") - y.get("valueX"); // descending
-        //return y.get("valueY") - x.get("valueX"); // ascending
-      })
-
-      // Go through each axis item
-      am5.array.each(yAxis.dataItems, function (dataItem) {
-        // get corresponding series item
-        let seriesDataItem = getSeriesItem(dataItem.get("category"));
-
-        if (seriesDataItem) {
-          // get index of series data item
-          let index = series.dataItems.indexOf(seriesDataItem);
-          // calculate delta position
-          let deltaPosition = (index - dataItem.get("index", 0)) / series.dataItems.length;
-          // set index to be the same as series data item index
-          dataItem.set("index", index);
-          // set deltaPosition instanlty
-          dataItem.set("deltaPosition", -deltaPosition);
-          // animate delta position to 0
-          dataItem.animate({
-            key: "deltaPosition",
-            to: 0,
-            duration: 1000,
-            easing: am5.ease.out(am5.ease.cubic)
-          })
-        }
-      });
-
-      // Sort axis items by index.
-      // This changes the order instantly, but as deltaPosition is set,
-      // they keep in the same places and then animate to true positions.
-      yAxis.dataItems.sort(function (x, y) {
-        return x.get("index") - y.get("index");
-      });
-    }
-
-    // Make stuff animate on load
-    // https://www.amcharts.com/docs/v5/concepts/animations/
-    series.appear(1000);
-    chart.appear(1000, 100);
-  }
-
-  React.useEffect(() => {
-    createChart(chartData);
-  }, [])
-
-  return (
-    <div id="Chart8" style={{ width: "100%", height: "100%" }}></div>
-  )
-
-}(No newline at end of file)
client/views/pages/main/Main_agency.jsx
--- client/views/pages/main/Main_agency.jsx
+++ client/views/pages/main/Main_agency.jsx
@@ -21,6 +21,8 @@
 import temperatureAgency from "../../../resources/files/images/temperatureAgency.png";
 import TitleSmall from "../../component/TitleSmall.jsx";
 
+import CommonUtil from "../../../resources/js/CommonUtil.js";
+
 export default function Main2() {
   //전역 변수 저장 객체
   const state = useSelector((state) => { return state });
@@ -105,10 +107,85 @@
     });
   }
 
+  // 최근 복용률
+  const [medicationSelectListByNew, setMedicationSelectListByNew] = React.useState([]);
+  // 최근 복용률 조회
+  const seniorMedicationSelectListByNew = () => {
+    fetch("/user/seniorMedicationSelectListByNew.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({ "agency_id": state.loginUser['agency_id'] }),
+    }).then((response) => response.json()).then((data) => {
+      console.log("seniorMedicationSelectListByNew : ", data);
+      setMedicationSelectListByNew(data)
+    }).catch((error) => {
+      console.log('seniorMedicationSelectListByNew() /user/seniorMedicationSelectListByNew.json error : ', error);
+    });
+  };
+
+  // 복용률 목록
+  const [medicationSelectListByMonth, setMedicationSelectListByMonth] = React.useState([]);
+  const [medicationSelectListByYear, setMedicationSelectListByYear] = React.useState([]);
+  // 복용률 목록 조회
+  const seniorMedicationSelectListByMonth = () => {
+    let totalYearArr = [];
+    let yearArr = [];
+
+    fetch("/user/seniorMedicationSelectListByMonth.json", {
+      method: "POST",
+      headers: {
+        'Content-Type': 'application/json; charset=UTF-8'
+      },
+      body: JSON.stringify({ "agency_id": state.loginUser['agency_id'] }),
+    }).then((response) => response.json()).then((data) => {
+      data.map((item, idx) => {
+        item['year'] = item['medication_default_date'].substr(0, 4);
+        item['month'] = item['medication_default_date'].substr(5, 2);
+        totalYearArr.push(item['medication_default_date'].substr(0, 4));
+        item['date'] = new Date(item['medication_default_date']);
+      })
+
+      const setYearArr = [...new Set(totalYearArr)];
+      console.log("totalYearArr: ", setYearArr);
+
+      setYearArr.map((year, yearIdx) => {
+        let sum = 0;
+        let count = 0;
+        let avg = 0;
+
+        let monthArr = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'];
+
+        data.map((item, idx) => {
+          if (item['year'] == year) {
+            sum += item['average'];
+            count++;
+            monthArr[Number(item['month'])] = item['average'];
+          }
+        })
+
+        avg = parseInt(sum / count);
+        yearArr.push({ "year": [year], "average": avg, "data": monthArr });
+      })
+
+      console.log("yearArr : ", yearArr);
+      setMedicationSelectListByYear(yearArr);
+
+      console.log("seniorMedicationSelectListByMonth : ", data);
+      setMedicationSelectListByMonth(data);
+    }).catch((error) => {
+      console.log('seniorMedicationSelectListByMonth() /user/seniorMedicationSelectListByMonth.json error : ', error);
+    });
+  };
+
+
   React.useEffect(() => {
     agentSeniorCount();
     temperatureRiskCount();
     batteryRiskCount();
+    seniorMedicationSelectListByNew();
+    seniorMedicationSelectListByMonth();
   }, []);
 
   return (
@@ -177,81 +254,23 @@
                 </tr>
               </thead>
               <tbody>
-                <tr>
-                  <td>2023</td>
-                  <td>87%</td>
-                  <td>86%</td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                </tr>
-                <tr>
-                  <td>2022</td>
-                  <td>83%</td>
-                  <td>81%</td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                </tr>
-                <tr>
-                  <td>2021</td>
-                  <td>81%</td>
-                  <td>80%</td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                </tr>
-                <tr>
-                  <td>2020</td>
-                  <td>82%</td>
-                  <td>83%</td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                </tr>
-                <tr>
-                  <td>2019</td>
-                  <td>80%</td>
-                  <td>81%</td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                  <td></td>
-                </tr>
+                {medicationSelectListByYear.map((item, idx) => {
+                  return (
+                    <tr>
+                      <td>{item['year']}</td>
+                      <td>{item['average'] == '-' ? '-' : item['average'] + '%'}</td>
+                      {CommonUtil.isEmpty(item['data']) == false ? (
+                        item['data'].map((item1, idx1) => {
+                          return (
+                            <>
+                              <td>{item1 == '-' ? '-' : item1 + '%'}</td>
+                            </>
+                          )
+                        })
+                      ) : null}
+                    </tr>
+                  )
+                })}
               </tbody>
             </table>
           </div>
@@ -272,7 +291,7 @@
         <div>
           <div className="flex-start margin-bottom2"><img src={medicinebox} alt="" /><TitleSmall title={"시니어 복용률 순위"} /></div>
           <div className="content-box combine-left-government3 visitlist margin-bottom2">
-            <Chart8 />
+            <Chart8 data={medicationSelectListByNew} />
           </div>
         </div>
         <div>
client/views/pages/main/Main_agencyAdmin.jsx
--- client/views/pages/main/Main_agencyAdmin.jsx
+++ client/views/pages/main/Main_agencyAdmin.jsx
@@ -163,69 +163,75 @@
     className: 'leaflet-background-radius-icon'//leaflet-div-icon
   });
 
-
-  //특정 대상자의 실제 복약 정보
-  const [seniorMedicationList, setSeniorMedicationList] = React.useState([]);
-  const [showMedicationTimeCode, setShowMedicationTimeCode] = React.useState({});
-  //특정 대상자의 실제 복약 정보 목록 조회
-  const seniorMedicationSelectList = (seniorNum) => {
-    fetch("/user/seniorMedicationSelectList.json", {
+  //특정 대상자의 최근 복용률
+  const [medicationSelectListByNew, setMedicationSelectListByNew] = React.useState([]);
+  //특정 대상자의 최근 복용률 조회
+  const seniorMedicationSelectListByNew = () => {
+    fetch("/user/seniorMedicationSelectListByNew.json", {
       method: "POST",
       headers: {
         'Content-Type': 'application/json; charset=UTF-8'
       },
-      body: JSON.stringify(seniorNum['senior_id']),
+      body: JSON.stringify({ "agency_id": state.loginUser['agency_id'] }),
     }).then((response) => response.json()).then((data) => {
-      setSeniorMedicationList(data, seniorNum);
-      seniorMedicationSelectListByDay(data, seniorNum);
-      console.log("seniorMedicationSelectList: ", seniorMedicationSelectList)
+      console.log("seniorMedicationSelectListByNew : ", data);
+      setMedicationSelectListByNew(data)
     }).catch((error) => {
-      console.log('seniorMedicationSelectList() /user/seniorMedicationSelectList.json error : ', error);
+      console.log('seniorMedicationSelectListByNew() /user/seniorMedicationSelectListByNew.json error : ', error);
     });
   };
 
-  //특정 대상자의 일별, 복약시간별 복약 목록
-  const [stackChartData, setStackChartData] = React.useState([]);
-  //특정 대상자의 일별, 복약시간별 복약 목록 조회
-  const seniorMedicationSelectListByDay = (seniorMedicationList, seniorNum) => {
-    fetch("/user/seniorMedicationSelectListByDay.json", {
+  // 복용률 목록
+  const [medicationSelectListByMonth, setMedicationSelectListByMonth] = React.useState([]);
+  const [medicationSelectListByYear, setMedicationSelectListByYear] = React.useState([]);
+  // 복용률 목록 조회
+  const seniorMedicationSelectListByMonth = () => {
+    let totalYearArr = [];
+    let yearArr = [];
+
+    fetch("/user/seniorMedicationSelectListByMonth.json", {
       method: "POST",
       headers: {
         'Content-Type': 'application/json; charset=UTF-8'
       },
-      body: JSON.stringify(seniorNum),
+      body: JSON.stringify({ "agency_id": state.loginUser['agency_id'] }),
     }).then((response) => response.json()).then((data) => {
-      let showMedicationTimeCode = {};
-      for (let i = 0; i < seniorMedicationList.length; i++) {
-        showMedicationTimeCode[seniorMedicationList[i]] = true;
-      }
-      setShowMedicationTimeCode(showMedicationTimeCode);
+      data.map((item, idx) => {
+        item['year'] = item['medication_default_date'].substr(0, 4);
+        item['month'] = item['medication_default_date'].substr(5, 2);
+        totalYearArr.push(item['medication_default_date'].substr(0, 4));
+        item['date'] = new Date(item['medication_default_date']);
+      })
 
-      if (CommonUtil.isEmpty(data) == false) {
-        let _stackChartData = [];
-        for (let i = data.length - 1; i >= data.length - 3; i--) {
-          let sum = 0;      // 실제 복약량
-          let counter = 0;  // 복약해야하는 양
-          let chartData = {
-            xName: data[i]['medication_default_date']
-          };
-          for (let j = 0; j < data[i]['medication_time_code_list'].length; j++) {
-            if (CommonUtil.isEmpty(showMedicationTimeCode[data[i]['medication_time_code_list'][j]]) == false) {
-              chartData[data[i]['medication_time_code_list'][j]] = data[i]['medication_time_code_count_list'][j];
-              counter++;
-              if (i > 0) {
-                sum += data[i]['medication_time_code_count_list'][j];
-              }
-            } else {
-              continue;
-            }
+      const setYearArr = [...new Set(totalYearArr)];
+      console.log("totalYearArr: ", setYearArr);
+
+      setYearArr.map((year, yearIdx) => {
+        let sum = 0;
+        let count = 0;
+        let avg = 0;
+
+        let monthArr = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'];
+
+        data.map((item, idx) => {
+          if (item['year'] == year) {
+            sum += item['average'];
+            count++;
+            monthArr[Number(item['month'])] = item['average'];
           }
-          _stackChartData.push({ "sum": sum, "total": counter })
-        }
-        seniorNum.seniorMedicationList = _stackChartData;
-      }
+        })
+
+        avg = parseInt(sum / count);
+        yearArr.push({ "year": [year], "average": avg, "data": monthArr });
+      })
+
+      console.log("yearArr : ", yearArr);
+      setMedicationSelectListByYear(yearArr);
+
+      console.log("seniorMedicationSelectListByMonth : ", data);
+      setMedicationSelectListByMonth(data);
     }).catch((error) => {
-      console.log('seniorMedicationSelectListByDay() /user/seniorMedicationSelectListByDay.json error : ', error);
+      console.log('seniorMedicationSelectListByMonth() /user/seniorMedicationSelectListByMonth.json error : ', error);
     });
   };
 
@@ -236,6 +242,8 @@
     batteryRiskCount();
     visitByMonthList();
     seniorByAgent();
+    seniorMedicationSelectListByNew();
+    seniorMedicationSelectListByMonth();
   }, []);
 
   return (
@@ -309,15 +317,14 @@
             <Title title={`${cityName} 복용률 순위`} explanation={""} />
           </div>
           <div style={{ height: 'calc(100% - 60px)' }}>
-            <Chart8 data={stackChartData} />
-            {/* <Chart8 /> */}
+            <Chart8 data={medicationSelectListByNew} />
           </div>
         </div>
         <div className="content-box combine-left-government2">
           <div className="flex">
             <Title title={`${cityName} 복용률 평균`} explanation={"해당 지역의 대상자 복용률이 그래프로 보여집니다."} />
           </div>
-          <Chart2_govern />
+          <Chart2_govern data={medicationSelectListByMonth} />
         </div>
         <div className="content-box combine-right-government2">
           <div className="flex">
@@ -352,81 +359,23 @@
               </tr>
             </thead>
             <tbody>
-              <tr>
-                <td>2023</td>
-                <td>87%</td>
-                <td>86%</td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-              </tr>
-              <tr>
-                <td>2022</td>
-                <td>83%</td>
-                <td>81%</td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-              </tr>
-              <tr>
-                <td>2021</td>
-                <td>81%</td>
-                <td>80%</td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-              </tr>
-              <tr>
-                <td>2020</td>
-                <td>82%</td>
-                <td>83%</td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-              </tr>
-              <tr>
-                <td>2019</td>
-                <td>80%</td>
-                <td>81%</td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-              </tr>
+              {medicationSelectListByYear.map((item, idx) => {
+                return (
+                  <tr>
+                    <td>{item['year']}</td>
+                    <td>{item['average'] == '-' ? '-' : item['average'] + '%'}</td>
+                    {CommonUtil.isEmpty(item['data']) == false ? (
+                      item['data'].map((item1, idx1) => {
+                        return (
+                          <>
+                            <td>{item1 == '-' ? '-' : item1 + '%'}</td>
+                          </>
+                        )
+                      })
+                    ) : null}
+                  </tr>
+                )
+              })}
             </tbody>
           </table>
         </div>
client/views/pages/main/Main_government.jsx
--- client/views/pages/main/Main_government.jsx
+++ client/views/pages/main/Main_government.jsx
@@ -12,7 +12,7 @@
 import Chart5 from "../../component/chart/Chart5.jsx";
 import Chart2_govern from "../../component/chart/Chart2_govern.jsx";
 import Donut1_govern from "../../component/chart/Donut1_govern.jsx";
-import Chart8 from "../../component/chart/Chart8_government.jsx";
+import Chart8 from "../../component/chart/Chart8.jsx";
 import RowChart_govern from "../../component/chart/RowChart_govern.jsx";
 import AddCircleIcon from "@mui/icons-material/AddCircle";
 import BatteryCharging20Icon from '@mui/icons-material/BatteryCharging20';
@@ -32,7 +32,6 @@
   const [cityName, setCityName] = useState(state.loginUser['government_name']);
 
   //대상자(시니어) 목록 조회
-  const [seniorNum, setSeniorNum] = React.useState();
   const [senior, setSenior] = React.useState({ userList: [], userListCount: 0 });
   const seniorSelectList = () => {
     fetch("/user/userSelectList.json", {
@@ -48,11 +47,6 @@
     }).then((response) => response.json()).then((data) => {
       console.log("대상자(시니어) 목록 조회 : ", data);
       setSenior(data);
-      data.userList.map((item, idx) => {
-        item['senior_id'] = item['user_id']
-        seniorMedicationSelectList(item);
-      })
-      console.log(medicationList)
     }).catch((error) => {
       console.log('seniorSelectList() /user/userSelectList.json error : ', error);
     });
@@ -176,81 +170,80 @@
     });
   }
 
-  //특정 대상자의 실제 복약 정보
-  const [seniorMedicationList, setSeniorMedicationList] = React.useState([]);
-  const [showMedicationTimeCode, setShowMedicationTimeCode] = React.useState({});
-  //특정 대상자의 실제 복약 정보 목록 조회
-  const seniorMedicationSelectList = (seniorData) => {
-    fetch("/user/seniorMedicationSelectList.json", {
+  // 최근 복용률
+  const [medicationSelectListByNew, setMedicationSelectListByNew] = React.useState([]);
+  // 최근 복용률 조회
+  const seniorMedicationSelectListByNew = () => {
+    fetch("/user/seniorMedicationSelectListByNew.json", {
       method: "POST",
       headers: {
         'Content-Type': 'application/json; charset=UTF-8'
       },
-      body: JSON.stringify(seniorData),
+      body: JSON.stringify({ "government_id": state.loginUser['government_id'] }),
     }).then((response) => response.json()).then((data) => {
-      setSeniorMedicationList(data);
-      seniorMedicationSelectListByDay(data, seniorData);
+      console.log("seniorMedicationSelectListByNew : ", data);
+      setMedicationSelectListByNew(data)
     }).catch((error) => {
-      console.log('seniorMedicationSelectList() /user/seniorMedicationSelectList.json error : ', error);
+      console.log('seniorMedicationSelectListByNew() /user/seniorMedicationSelectListByNew.json error : ', error);
     });
   };
 
-  //특정 대상자의 일별, 복약시간별 복약 목록
-  const [medicationList, setMedicationList] = React.useState([]);
-  //특정 대상자의 일별, 복약시간별 복약 목록 조회
-  const seniorMedicationSelectListByDay = (seniorMedicationList, seniorData) => {
-    fetch("/user/seniorMedicationSelectListByDay.json", {
+  // 복용률 목록
+  const [medicationSelectListByMonth, setMedicationSelectListByMonth] = React.useState([]);
+  const [medicationSelectListByYear, setMedicationSelectListByYear] = React.useState([]);
+  // 복용률 목록 조회
+  const seniorMedicationSelectListByMonth = () => {
+    let totalYearArr = [];
+    let yearArr = [];
+
+    fetch("/user/seniorMedicationSelectListByMonth.json", {
       method: "POST",
       headers: {
         'Content-Type': 'application/json; charset=UTF-8'
       },
-      body: JSON.stringify(seniorData),
+      body: JSON.stringify({ "government_id": state.loginUser['government_id'] }),
     }).then((response) => response.json()).then((data) => {
-      let showMedicationTimeCode = {};
-      for (let i = 0; i < seniorMedicationList.length; i++) {
-        showMedicationTimeCode[seniorMedicationList[i]] = true;
-      }
-      setShowMedicationTimeCode(showMedicationTimeCode);
+      data.map((item, idx) => {
+        item['year'] = item['medication_default_date'].substr(0, 4);
+        item['month'] = item['medication_default_date'].substr(5, 2);
+        totalYearArr.push(item['medication_default_date'].substr(0, 4));
+        item['date'] = new Date(item['medication_default_date']);
+      })
 
-      if (CommonUtil.isEmpty(data) == false) {
-        let _stackChartData = [];
-        let lenghs = 0;
-        if (data.length < 30) {
-          lenghs = data.length
-        } else {
-          lenghs = data.length - 30
-        }
-        let sum = 0;      // 실제 복약량
-        let counter = 0;  // 복약해야하는 양
-        let percent = 0;  // 복용률
-        for (let i = data.length - 1; i >= lenghs; i--) {
-          for (let j = 0; j < data[i]['medication_time_code_list'].length; j++) {
-            if (CommonUtil.isEmpty(showMedicationTimeCode[data[i]['medication_time_code_list'][j]]) == false) {
-              counter++;
-              if (i > 0) {
-                sum += data[i]['medication_time_code_count_list'][j];
-              }
-            } else {
-              continue;
-            }
+      const setYearArr = [...new Set(totalYearArr)];
+      console.log("totalYearArr: ", setYearArr);
+
+      setYearArr.map((year, yearIdx) => {
+        let sum = 0;
+        let count = 0;
+        let avg = 0;
+
+        let monthArr = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'];
+
+        data.map((item, idx) => {
+          if (item['year'] == year) {
+            sum += item['average'];
+            count++;
+            monthArr[Number(item['month'])] = item['average'];
           }
-        }
-        if (sum == 0 || counter == 0) {
-          percent = 0
-        } else {
-          percent = Math.floor((sum / counter) * 100);
-        }
-        _stackChartData = { "user_name": seniorData['user_name'], "percent": percent }
-        setMedicationList(_stackChartData);
-      }
+        })
+
+        avg = parseInt(sum / count);
+        yearArr.push({ "year": [year], "average": avg, "data": monthArr });
+      })
+
+      console.log("yearArr : ", yearArr);
+      setMedicationSelectListByYear(yearArr);
+
+      console.log("seniorMedicationSelectListByMonth : ", data);
+      setMedicationSelectListByMonth(data);
     }).catch((error) => {
-      console.log('seniorMedicationSelectListByDay() /user/seniorMedicationSelectListByDay.json error : ', error);
+      console.log('seniorMedicationSelectListByMonth() /user/seniorMedicationSelectListByMonth.json error : ', error);
     });
   };
 
 
   function updateList(agencyList, countList) {
-
     const result = [];
     for (let i = 0; i < agencyList.length; i++) {
       const agency = agencyList[i];
@@ -283,8 +276,9 @@
     visitByMonthList();
     equipmentByAgency();
     seniorByAgency();
+    seniorMedicationSelectListByNew();
+    seniorMedicationSelectListByMonth();
   }, []);
-
 
   return (
     <main>
@@ -363,14 +357,14 @@
             <Title title={`${cityName}  복용률 순위`} />
           </div>
           <div style={{ height: 'calc(100% - 60px)' }}>
-            <Chart8 data={medicationList} />
+            <Chart8 data={medicationSelectListByNew} />
           </div>
         </div>
         <div className="content-box combine-left-government2">
           <div className="flex">
             <Title title={`${cityName} 복용률 평균`} explanation={"해당 지역의 대상자 복용률이 그래프로 보여집니다."} />
           </div>
-          <Chart2_govern />
+          <Chart2_govern data={medicationSelectListByMonth} />
         </div>
         <div className="content-box combine-right-government2">
           <div className="flex">
@@ -384,7 +378,7 @@
           </div>
           <Donut1_govern data={equipmentUsage} />
         </div>
-        <div className="content-box span4">
+        <div className="content-box span4 table-size-fix">
           <table className="visit-data-table">
             <thead>
               <tr>
@@ -405,81 +399,23 @@
               </tr>
             </thead>
             <tbody>
-              <tr>
-                <td>2023</td>
-                <td>87%</td>
-                <td>86%</td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-              </tr>
-              <tr>
-                <td>2022</td>
-                <td>83%</td>
-                <td>81%</td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-              </tr>
-              <tr>
-                <td>2021</td>
-                <td>81%</td>
-                <td>80%</td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-              </tr>
-              <tr>
-                <td>2020</td>
-                <td>82%</td>
-                <td>83%</td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-              </tr>
-              <tr>
-                <td>2019</td>
-                <td>80%</td>
-                <td>81%</td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-                <td></td>
-              </tr>
+              {medicationSelectListByYear.map((item, idx) => {
+                return (
+                  <tr>
+                    <td>{item['year']}</td>
+                    <td>{item['average'] == '-' ? '-' : item['average'] + '%'}</td>
+                    {CommonUtil.isEmpty(item['data']) == false ? (
+                      item['data'].map((item1, idx1) => {
+                        return (
+                          <>
+                            <td>{item1 == '-' ? '-' : item1 + '%'}</td>
+                          </>
+                        )
+                      })
+                    ) : null}
+                  </tr>
+                )
+              })}
             </tbody>
           </table>
         </div>
Add a comment
List