Skip to content

Commit

Permalink
#1328 | Restrict program select based on subject selection during enc…
Browse files Browse the repository at this point in the history
…ounter create/edit
  • Loading branch information
1t5j0y committed Oct 11, 2024
1 parent db21e8b commit 91cee0e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
27 changes: 18 additions & 9 deletions src/adminApp/EncounterType/EditEncounterTypeFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AvniFormLabel } from "../../common/components/AvniFormLabel";
import RuleDesigner from "../../formDesigner/components/DeclarativeRule/RuleDesigner";
import { sampleEncounterEligibilityCheckRule } from "../../formDesigner/common/SampleRule";
import { confirmBeforeRuleEdit } from "../../formDesigner/util";
import React from "react";
import React, { useEffect } from "react";
import {
findEncounterCancellationForms,
findEncounterForms,
Expand All @@ -26,18 +26,29 @@ const EditEncounterTypeFields = ({
updateProgram,
program,
formList,
ruleValidationError
ruleValidationError,
formMappings,
setProgram,
allPrograms
}) => {
function getCancellationForms() {
return _.isEmpty(programT)
? findEncounterCancellationForms(formList)
: findProgramEncounterCancellationForms(formList);
return _.isEmpty(programT) ? findEncounterCancellationForms(formList) : findProgramEncounterCancellationForms(formList);
}

function getEncounterForms() {
return _.isEmpty(programT) ? findEncounterForms(formList) : findProgramEncounterForms(formList);
}

useEffect(() => {
if (!_.isEmpty(subjectT)) {
const matchingFormMappings = formMappings.filter(
formMapping => formMapping.subjectTypeUUID === subjectT.uuid && !_.isNil(formMapping.programUUID)
);
setProgram(allPrograms.filter(program => _.includes(matchingFormMappings.map(formMapping => formMapping.programUUID), program.uuid)));
updateProgram({});
}
}, [subjectT]);

return (
<div>
<AvniTextField
Expand Down Expand Up @@ -74,6 +85,7 @@ const EditEncounterTypeFields = ({
</MenuItem>
))}
toolTipKey={"APP_DESIGNER_ENCOUNTER_TYPE_PROGRAM"}
isClearable={true}
/>
<p />
<AvniSelectForm
Expand Down Expand Up @@ -102,10 +114,7 @@ const EditEncounterTypeFields = ({
toolTipKey={"APP_DESIGNER_ENCOUNTER_TYPE_CANCELLATION_FORM"}
/>
<p />
<AvniFormLabel
label={"Encounter Eligibility Check Rule"}
toolTipKey={"APP_DESIGNER_ENCOUNTER_TYPE_ELIGIBILITY_RULE"}
/>
<AvniFormLabel label={"Encounter Eligibility Check Rule"} toolTipKey={"APP_DESIGNER_ENCOUNTER_TYPE_ELIGIBILITY_RULE"} />
{encounterType.loaded && (
<RuleDesigner
rulesJson={encounterType.encounterEligibilityCheckDeclarativeRule}
Expand Down
8 changes: 7 additions & 1 deletion src/adminApp/EncounterType/EncounterTypeCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const EncounterTypeCreate = ({ organisationConfig }) => {
const [subjectType, setSubjectType] = useState([]);
const [programT, setProgramT] = useState({});
const [program, setProgram] = useState([]);
const [allPrograms, setAllPrograms] = useState([]);
const [formMappings, setFormMappings] = useState([]);
const [error, setError] = useState("");
const [alert, setAlert] = useState(false);
const [id, setId] = useState();
Expand All @@ -50,9 +52,10 @@ const EncounterTypeCreate = ({ organisationConfig }) => {
http.get("/web/operationalModules").then(response => {
const formMap = response.data.formMappings;
formMap.map(l => (l["isVoided"] = false));
setFormMappings(formMap);
setFormList(response.data.forms);
setSubjectType(response.data.subjectTypes);
setProgram(response.data.programs);
setAllPrograms(response.data.programs);
});
}, []);

Expand Down Expand Up @@ -154,6 +157,9 @@ const EncounterTypeCreate = ({ organisationConfig }) => {
program={program}
formList={formList}
ruleValidationError={ruleValidationError}
formMappings={formMappings}
setProgram={setProgram}
allPrograms={allPrograms}
/>
{organisationConfig && organisationConfig.enableMessaging ? (
<MessageRules
Expand Down
8 changes: 7 additions & 1 deletion src/adminApp/EncounterType/EncounterTypeEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const EncounterTypeEdit = ({ organisationConfig, ...props }) => {
const [subjectType, setSubjectType] = useState([]);
const [programT, setProgramT] = useState({});
const [program, setProgram] = useState([]);
const [allPrograms, setAllPrograms] = useState([]);
const [formMappings, setFormMappings] = useState([]);
const [formList, setFormList] = useState([]);
const [subjectValidation, setSubjectValidation] = useState(false);
const [ruleValidationError, setRuleValidationError] = useState();
Expand Down Expand Up @@ -64,9 +66,10 @@ const EncounterTypeEdit = ({ organisationConfig, ...props }) => {
http.get("/web/operationalModules").then(response => {
const formMap = response.data.formMappings;
formMap.map(l => (l["isVoided"] = false));
setFormMappings(formMap);
setFormList(response.data.forms);
setSubjectType(response.data.subjectTypes);
setProgram(response.data.programs);
setAllPrograms(response.data.programs);

const encounterTypeMappings = response.data.formMappings.filter(l => l.encounterTypeUUID === result.uuid);

Expand Down Expand Up @@ -192,6 +195,9 @@ const EncounterTypeEdit = ({ organisationConfig, ...props }) => {
program={program}
formList={formList}
ruleValidationError={ruleValidationError}
formMappings={formMappings}
setProgram={setProgram}
allPrograms={allPrograms}
/>
{organisationConfig && organisationConfig.enableMessaging ? (
<MessageRules
Expand Down

0 comments on commit 91cee0e

Please sign in to comment.