UNPKG

@hisptz/react-ui

Version:

A collection of reusable complex DHIS2 react ui components.

68 lines (65 loc) 4.03 kB
import { useDataQuery } from "@dhis2/app-runtime"; import i18n from "@dhis2/d2-i18n"; import React, { useEffect } from "react"; import Error from "../../../../Shared/Componets/Error/ErrorAPIResult"; import Loader from "../../../../Shared/Componets/Loaders/Loader"; import { lowerCaseAllWordsExceptFirstLetters } from "../../../../Utils/Functions/FormulaFunctions"; import { analyticsTypes } from "../../../../Utils/Models"; import BoundaryTable from "./Components/BoundaryTable/BoundaryTable"; import ExpressionDetailTable from "./Components/ExpressionDetailTable"; const query = { calculation: { resource: "programIndicators", id: _ref => { let { id } = _ref; return id; }, params: { fields: ["analyticsType", "aggregationType", "expression", "filter", "analyticsPeriodBoundaries[id,boundaryTarget,analyticsPeriodBoundaryType,offsetPeriods,offsetPeriodType]"] } } }; export default function CalculationDetails(_ref2) { let { id } = _ref2; const { loading, error, data, refetch } = useDataQuery(query, { variables: { id } }); useEffect(() => { refetch({ id }); }, [id]); if (loading) { return /*#__PURE__*/React.createElement(Loader, { text: "" }); } if (error) { return /*#__PURE__*/React.createElement(Error, { error: error }); } const res = data === null || data === void 0 ? void 0 : data.calculation; return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h3", null, i18n.t(" Calculation details")), /*#__PURE__*/React.createElement("p", null, i18n.t("Calculation of the values will be {{variables}} of {{variables2}} across orgunit and period.", { variables: res === null || res === void 0 ? void 0 : res.aggregationType, variables2: res === null || res === void 0 ? void 0 : res.analyticsType })), /*#__PURE__*/React.createElement("p", null, i18n.t("Program indicator calculation will be based on Analytics Type, for distinction purposes:")), /*#__PURE__*/React.createElement("ul", null, (res === null || res === void 0 ? void 0 : res.analyticsType) === analyticsTypes.EVENT ? /*#__PURE__*/React.createElement("li", null, i18n.t(" Events implies, each event from data source is considered as independent row to be counted, and properties and details of the event are used to filter events.")) : (res === null || res === void 0 ? void 0 : res.analyticsType) === analyticsTypes.ENROLLMENT ? /*#__PURE__*/React.createElement("li", null, i18n.t("Enrollment implies, each enrollment from data source is considered as independent row to be counted, and events from any stage and other properties and details of enrollment are used to filter enrollments.")) : ""), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("p", null, i18n.t("Below are expression details on computing program indicator and it\u2019s related data source"))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(ExpressionDetailTable, { expression: res === null || res === void 0 ? void 0 : res.expression, filter: res === null || res === void 0 ? void 0 : res.filter })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("p", null, i18n.t("Below are period boundaries that determines which {{variables}} will be included in calculations of the program indicators, where for", { variables: lowerCaseAllWordsExceptFirstLetters(res === null || res === void 0 ? void 0 : res.analyticsType) }), (res === null || res === void 0 ? void 0 : res.analyticsType) === analyticsTypes.EVENT ? i18n.t(" event date will be used.") : (res === null || res === void 0 ? void 0 : res.analyticsType) === analyticsTypes.ENROLLMENT ? i18n.t("enrollment analytics will be used.") : "")), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(BoundaryTable, { rows: res === null || res === void 0 ? void 0 : res.analyticsPeriodBoundaries }))); }