diff --git a/src/formDesigner/components/ConceptDetails.js b/src/formDesigner/components/ConceptDetails.js index bb3d88071..c924dace5 100644 --- a/src/formDesigner/components/ConceptDetails.js +++ b/src/formDesigner/components/ConceptDetails.js @@ -19,41 +19,31 @@ import UserInfo from "../../common/model/UserInfo"; import { connect } from "react-redux"; import { Privilege } from "openchs-models"; -function ConceptDetails({ userInfo, ...props }) { +function ConceptDetails({ subjectType, userInfo, ...props }) { const [editAlert, setEditAlert] = useState(false); const [data, setData] = useState({}); const [usage, setUsage] = useState({}); - const [addressLevelTypes, setAddressLevelTypes] = useState([]); - const [subjectTypeOptions, setSubjectTypeOptions] = React.useState([]); + const [addressLevelTypes] = useState([]); + const [subjectTypeOptions] = React.useState([]); + useEffect(() => { - http.get("/web/concept/" + props.match.params.uuid).then(response => { - setData(response.data); - if (response.data.dataType === "Location") { - http.get("/addressLevelType/?page=0&size=10&sort=level%2CDESC").then(response => { - if (response.status === 200) { - const addressLevelTypes = response.data.content.map(addressLevelType => ({ - label: addressLevelType.name, - value: addressLevelType.uuid, - level: addressLevelType.level, - parent: addressLevelType.parent - })); - setAddressLevelTypes(addressLevelTypes); - } - }); - } + const fetchUsageAndConceptDetails = async () => { + try { + const usageResponse = await http.get(`/web/concept/usage/${props.match.params.uuid}`); + setUsage(usageResponse.data); - if (response.data.dataType === "Subject") { - http.get("/web/operationalModules").then(response => { - setSubjectTypeOptions(response.data.subjectTypes); - }); + const conceptResponse = await http.get("/web/concept/" + props.match.params.uuid); + setData(conceptResponse.data); + } catch (error) { + console.error("Error fetching data:", error); } - }); - http.get("/web/concept/usage/" + props.match.params.uuid).then(response => { - setUsage(response.data); - }); + }; + + fetchUsageAndConceptDetails(); }, [props.match.params.uuid]); const hasEditPrivilege = UserInfo.hasPrivilege(userInfo, Privilege.PrivilegeType.EditConcept); + return ( <> @@ -86,41 +76,31 @@ function ConceptDetails({ userInfo, ...props }) {
Low absolute
- - {!isNil(data.lowAbsolute) ? data.lowAbsolute : } - + {!isNil(data.lowAbsolute) ? data.lowAbsolute : }

High Absolute
- - {!isNil(data.highAbsolute) ? data.highAbsolute : } - + {!isNil(data.highAbsolute) ? data.highAbsolute : }

Low Normal
- - {!isNil(data.lowNormal) ? data.lowNormal : } - + {!isNil(data.lowNormal) ? data.lowNormal : }

High normal
- - {!isNil(data.highNormal) ? data.highNormal : } - + {!isNil(data.highNormal) ? data.highNormal : }

Unit
- - {!isNil(data.unit) ? data.unit : } - + {!isNil(data.unit) ? data.unit : }
)} @@ -133,25 +113,15 @@ function ConceptDetails({ userInfo, ...props }) { return ( !answer.voided && (
- + - } + control={} label="abnormal" style={{ marginLeft: "5px" }} disabled={true} /> - } + control={} label="unique" disabled={true} /> @@ -169,10 +139,7 @@ function ConceptDetails({ userInfo, ...props }) { Within Catchment
- {data.keyValues.find(keyValue => keyValue.key === "isWithinCatchment").value === - true - ? "Yes" - : "No"} + {data.keyValues.find(keyValue => keyValue.key === "isWithinCatchment").value === true ? "Yes" : "No"}

@@ -182,14 +149,9 @@ function ConceptDetails({ userInfo, ...props }) { {addressLevelTypes .filter(addressLevelType => - data.keyValues - .find(keyValue => keyValue.key === "lowestAddressLevelTypeUUIDs") - .value.includes(addressLevelType.value) + data.keyValues.find(keyValue => keyValue.key === "lowestAddressLevelTypeUUIDs").value.includes(addressLevelType.value) ) - .map( - (addressLevelType, index, array) => - addressLevelType.label + (index === array.length - 1 ? "" : ", ") - )} + .map((addressLevelType, index, array) => addressLevelType.label + (index === array.length - 1 ? "" : ", "))}

@@ -197,14 +159,10 @@ function ConceptDetails({ userInfo, ...props }) { Highest Location Level
- {data.keyValues.find( - keyValue => keyValue.key === "highestAddressLevelTypeUUID" - ) !== undefined ? ( + {data.keyValues.find(keyValue => keyValue.key === "highestAddressLevelTypeUUID") !== undefined ? ( addressLevelTypes.find( addressLevelType => - data.keyValues.find( - keyValue => keyValue.key === "highestAddressLevelTypeUUID" - ).value === addressLevelType.value + data.keyValues.find(keyValue => keyValue.key === "highestAddressLevelTypeUUID").value === addressLevelType.value ).label ) : ( @@ -221,9 +179,7 @@ function ConceptDetails({ userInfo, ...props }) { { subjectTypeOptions.find( - subjectType => - data.keyValues.find(keyValue => keyValue.key === "subjectTypeUUID") - .value === subjectType.uuid + subjectType => data.keyValues.find(keyValue => keyValue.key === "subjectTypeUUID").value === subjectType.uuid ).name } @@ -239,13 +195,7 @@ function ConceptDetails({ userInfo, ...props }) { data.keyValues.map((keyValue, index) => { return (

- + {data.dataType !== "NA" && ( <> - Used in forms + Used in forms (Form name → Page name → Question Name)
- {isEmpty(usage.forms) && ( - Not used in the form. - )} + {isEmpty(usage.forms) && Not used in the form.} {usage.forms && ( -
    - {" "} - {usage.forms.map((form, index) => { - return ( - <> -
  • - {form.formName} -

    -

  • - - ); - })} -
+
+ {usage.forms.map(form => ( +
+ + {form.formName} + + + {" "} + → {form.formElementGroupName} → {form.formElementName} + +
+ ))} +
)} )} Answer to
- {isEmpty(usage.concepts) && ( - Not used in any answer. - )} + {isEmpty(usage.concepts) && Not used in any answer.} {usage.concepts && (
    {usage.concepts.map(concept => {