-
Notifications
You must be signed in to change notification settings - Fork 124
#1116 | Enhance concept screen to display form, section, and question… #1267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
d1vyanshu-kumar
wants to merge
2
commits into
avniproject:master
Choose a base branch
from
d1vyanshu-kumar:form-location02
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,12 +19,75 @@ import UserInfo from "../../common/model/UserInfo"; | |
| import { connect } from "react-redux"; | ||
| import { Privilege } from "openchs-models"; | ||
|
|
||
| function ConceptDetails({ userInfo, ...props }) { | ||
| function ConceptDetails({ subjectType, formMappings, 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 [fdata, setFdata] = useState({}); | ||
| const [idToNameConverter, setIdToNameConverter] = useState({}); | ||
|
|
||
| const fetchFormData = async formUuid => { | ||
| try { | ||
| const response = await http.get(`/forms/export?formUUID=${formUuid}`); | ||
| const form = response.data; | ||
| const formDetails = {}; | ||
| const idToName = {}; | ||
| form.formElementGroups.forEach(feg => { | ||
| feg.formElements.forEach(fe => { | ||
| const concept = fe.concept; | ||
| if (!feg.voided && !fe.voided) { | ||
| if (!formDetails[form.name]) { | ||
| formDetails[form.name] = []; | ||
| } | ||
| const elementDetails = { | ||
| formName: form.name, | ||
| sectionName: feg.name, | ||
| questionName: fe.name, | ||
| parentUUID: fe.parentFormElementUuid, | ||
| conceptName: concept.name, | ||
| dataType: concept.dataType | ||
| }; | ||
| formDetails[form.name].push(elementDetails); | ||
| idToName[fe.uuid] = fe.name; | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| setFdata(prevFdata => ({ | ||
| ...prevFdata, | ||
| ...formDetails | ||
| })); | ||
| setIdToNameConverter(prevdata => ({ | ||
| ...prevdata, | ||
| ...idToName | ||
| })); | ||
| } catch (error) { | ||
| console.error("Error fetching form data:", error); | ||
| alert("Failed to fetch form data. Please try again later."); | ||
| } | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| const fetchUsageAndFormDetails = async () => { | ||
| try { | ||
| const usageResponse = await http.get(`/web/concept/usage/${props.match.params.uuid}`); | ||
| setUsage(usageResponse.data); | ||
|
|
||
| if (usageResponse.data.forms) { | ||
| usageResponse.data.forms.forEach(form => { | ||
| fetchFormData(form.formUUID); | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| console.error("Error fetching usage data:", error); | ||
|
||
| } | ||
| }; | ||
|
|
||
| fetchUsageAndFormDetails(); | ||
| }, [props.match.params.uuid]); | ||
|
|
||
| useEffect(() => { | ||
| http.get("/web/concept/" + props.match.params.uuid).then(response => { | ||
| setData(response.data); | ||
|
|
@@ -48,12 +111,14 @@ function ConceptDetails({ userInfo, ...props }) { | |
| }); | ||
| } | ||
| }); | ||
|
|
||
| http.get("/web/concept/usage/" + props.match.params.uuid).then(response => { | ||
| setUsage(response.data); | ||
| }); | ||
| }, [props.match.params.uuid]); | ||
|
|
||
| const hasEditPrivilege = UserInfo.hasPrivilege(userInfo, Privilege.PrivilegeType.EditConcept); | ||
|
|
||
| return ( | ||
| <> | ||
| <Box boxShadow={2} p={3} bgcolor="background.paper"> | ||
|
|
@@ -86,41 +151,31 @@ function ConceptDetails({ userInfo, ...props }) { | |
| <div> | ||
| <FormLabel style={{ fontSize: "13px" }}>Low absolute</FormLabel> | ||
| <br /> | ||
| <span style={{ fontSize: "15px" }}> | ||
| {!isNil(data.lowAbsolute) ? data.lowAbsolute : <RemoveIcon />} | ||
| </span> | ||
| <span style={{ fontSize: "15px" }}>{!isNil(data.lowAbsolute) ? data.lowAbsolute : <RemoveIcon />}</span> | ||
| </div> | ||
| <p /> | ||
| <div> | ||
| <FormLabel style={{ fontSize: "13px" }}>High Absolute</FormLabel> | ||
| <br /> | ||
| <span style={{ fontSize: "15px" }}> | ||
| {!isNil(data.highAbsolute) ? data.highAbsolute : <RemoveIcon />} | ||
| </span> | ||
| <span style={{ fontSize: "15px" }}>{!isNil(data.highAbsolute) ? data.highAbsolute : <RemoveIcon />}</span> | ||
| </div> | ||
| <p /> | ||
| <div> | ||
| <FormLabel style={{ fontSize: "13px" }}>Low Normal</FormLabel> | ||
| <br /> | ||
| <span style={{ fontSize: "15px" }}> | ||
| {!isNil(data.lowNormal) ? data.lowNormal : <RemoveIcon />} | ||
| </span> | ||
| <span style={{ fontSize: "15px" }}>{!isNil(data.lowNormal) ? data.lowNormal : <RemoveIcon />}</span> | ||
| </div> | ||
| <p /> | ||
| <div> | ||
| <FormLabel style={{ fontSize: "13px" }}>High normal</FormLabel> | ||
| <br /> | ||
| <span style={{ fontSize: "15px" }}> | ||
| {!isNil(data.highNormal) ? data.highNormal : <RemoveIcon />} | ||
| </span> | ||
| <span style={{ fontSize: "15px" }}>{!isNil(data.highNormal) ? data.highNormal : <RemoveIcon />}</span> | ||
| </div> | ||
| <p /> | ||
| <div> | ||
| <FormLabel style={{ fontSize: "13px" }}>Unit</FormLabel> | ||
| <br /> | ||
| <span style={{ fontSize: "15px" }}> | ||
| {!isNil(data.unit) ? data.unit : <RemoveIcon />} | ||
| </span> | ||
| <span style={{ fontSize: "15px" }}>{!isNil(data.unit) ? data.unit : <RemoveIcon />}</span> | ||
| </div> | ||
| </> | ||
| )} | ||
|
|
@@ -133,25 +188,15 @@ function ConceptDetails({ userInfo, ...props }) { | |
| return ( | ||
| !answer.voided && ( | ||
| <div key={index} style={{ width: "100%" }}> | ||
| <TextField | ||
| id="name" | ||
| value={answer.answerConcept.name} | ||
| style={{ width: "300px" }} | ||
| margin="normal" | ||
| disabled={true} | ||
| /> | ||
| <TextField id="name" value={answer.answerConcept.name} style={{ width: "300px" }} margin="normal" disabled={true} /> | ||
| <FormControlLabel | ||
| control={ | ||
| <Checkbox checked={answer.abnormal ? true : false} name="abnormal" /> | ||
| } | ||
| control={<Checkbox checked={answer.abnormal ? true : false} name="abnormal" />} | ||
| label="abnormal" | ||
| style={{ marginLeft: "5px" }} | ||
| disabled={true} | ||
| /> | ||
| <FormControlLabel | ||
| control={ | ||
| <Checkbox checked={answer.unique ? true : false} name="unique" /> | ||
| } | ||
| control={<Checkbox checked={answer.unique ? true : false} name="unique" />} | ||
| label="unique" | ||
| disabled={true} | ||
| /> | ||
|
|
@@ -169,10 +214,7 @@ function ConceptDetails({ userInfo, ...props }) { | |
| <FormLabel style={{ fontSize: "13px" }}>Within Catchment</FormLabel> | ||
| <br /> | ||
| <span style={{ fontSize: "15px" }}> | ||
| {data.keyValues.find(keyValue => keyValue.key === "isWithinCatchment").value === | ||
| true | ||
| ? "Yes" | ||
| : "No"} | ||
| {data.keyValues.find(keyValue => keyValue.key === "isWithinCatchment").value === true ? "Yes" : "No"} | ||
| </span> | ||
| </div> | ||
| <p /> | ||
|
|
@@ -182,29 +224,20 @@ function ConceptDetails({ userInfo, ...props }) { | |
| <span style={{ fontSize: "15px" }}> | ||
| {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 ? "" : ", "))} | ||
| </span> | ||
| </div> | ||
| <p /> | ||
| <div> | ||
| <FormLabel style={{ fontSize: "13px" }}>Highest Location Level</FormLabel> | ||
| <br /> | ||
| <span style={{ fontSize: "15px" }}> | ||
| {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 | ||
| ) : ( | ||
| <RemoveIcon /> | ||
|
|
@@ -221,9 +254,7 @@ function ConceptDetails({ userInfo, ...props }) { | |
| <span style={{ fontSize: "15px" }}> | ||
| { | ||
| 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 | ||
| } | ||
| </span> | ||
|
|
@@ -239,13 +270,7 @@ function ConceptDetails({ userInfo, ...props }) { | |
| data.keyValues.map((keyValue, index) => { | ||
| return ( | ||
| <div key={index}> | ||
| <TextField | ||
| id="outlined-required" | ||
| label="Key" | ||
| variant="outlined" | ||
| disabled={true} | ||
| value={keyValue.key} | ||
| /> | ||
| <TextField id="outlined-required" label="Key" variant="outlined" disabled={true} value={keyValue.key} /> | ||
| <TextField | ||
| id="outlined-required" | ||
| label="Value" | ||
|
|
@@ -266,35 +291,55 @@ function ConceptDetails({ userInfo, ...props }) { | |
| <> | ||
| {data.dataType !== "NA" && ( | ||
| <> | ||
| <FormLabel style={{ fontSize: "13px" }}>Used in forms</FormLabel> | ||
| <FormLabel style={{ fontSize: "13px" }}>Used in forms (Form name → Page name → Question Name)</FormLabel> | ||
| <br /> | ||
| {isEmpty(usage.forms) && ( | ||
| <span style={{ fontSize: "15px" }}>Not used in the form.</span> | ||
| )} | ||
| {isEmpty(usage.forms) && <span style={{ fontSize: "15px" }}>Not used in the form.</span>} | ||
|
|
||
| {usage.forms && ( | ||
| <ul> | ||
| {" "} | ||
| {usage.forms.map((form, index) => { | ||
| <div> | ||
| {Object.keys(fdata).map(formName => { | ||
| const form = usage.forms.find(form => form.formName === formName); | ||
| // Group elements by section name | ||
| const sections = fdata[formName].reduce((acc, element) => { | ||
| if (!acc[element.sectionName]) { | ||
| acc[element.sectionName] = []; | ||
| } | ||
| acc[element.sectionName].push(element); | ||
| return acc; | ||
| }, {}); | ||
|
|
||
| return ( | ||
| <> | ||
| <li key={index}> | ||
| <a href={`#/appDesigner/forms/${form.formUUID}`}>{form.formName}</a> | ||
| <p /> | ||
| </li> | ||
| </> | ||
| <div key={formName}> | ||
| {Object.keys(sections).map(sectionName => ( | ||
| <div key={sectionName} style={{ marginBottom: "10px" }}> | ||
| {/* Render questions under the section */} | ||
| {sections[sectionName].map((element, index) => ( | ||
| <div key={index} style={{ display: "flex", alignItems: "center" }}> | ||
| {element.conceptName === data.name && ( | ||
| <span style={{ fontSize: "15px" }}> | ||
| <a href={`#/appDesigner/forms/${form.formUUID}`} style={{ textDecoration: "none" }}> | ||
| {formName} | ||
| </a> | ||
| → {sectionName} | ||
| {element.parentUUID && <> → {idToNameConverter[element.parentUUID]}</>} | ||
| → {element.questionName} | ||
| </span> | ||
| )} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| })} | ||
| </ul> | ||
| </div> | ||
| )} | ||
| </> | ||
| )} | ||
|
|
||
| <FormLabel style={{ fontSize: "13px" }}>Answer to</FormLabel> | ||
| <br /> | ||
| {isEmpty(usage.concepts) && ( | ||
| <span style={{ fontSize: "15px" }}>Not used in any answer.</span> | ||
| )} | ||
| {isEmpty(usage.concepts) && <span style={{ fontSize: "15px" }}>Not used in any answer.</span>} | ||
| {usage.concepts && ( | ||
| <ul> | ||
| {usage.concepts.map(concept => { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of doing this, why not enhance the /web/concept/usage url to give you all the data instead?