diff --git a/src/adminApp/EncounterType/EditEncounterTypeFields.js b/src/adminApp/EncounterType/EditEncounterTypeFields.js index f3d105f0e..028010b30 100644 --- a/src/adminApp/EncounterType/EditEncounterTypeFields.js +++ b/src/adminApp/EncounterType/EditEncounterTypeFields.js @@ -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, @@ -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 (
))} toolTipKey={"APP_DESIGNER_ENCOUNTER_TYPE_PROGRAM"} + isClearable={true} />

- + {encounterType.loaded && ( { 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(); @@ -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); }); }, []); @@ -154,6 +157,9 @@ const EncounterTypeCreate = ({ organisationConfig }) => { program={program} formList={formList} ruleValidationError={ruleValidationError} + formMappings={formMappings} + setProgram={setProgram} + allPrograms={allPrograms} /> {organisationConfig && organisationConfig.enableMessaging ? ( { 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(); @@ -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); @@ -192,6 +195,9 @@ const EncounterTypeEdit = ({ organisationConfig, ...props }) => { program={program} formList={formList} ruleValidationError={ruleValidationError} + formMappings={formMappings} + setProgram={setProgram} + allPrograms={allPrograms} /> {organisationConfig && organisationConfig.enableMessaging ? (