Skip to content

Commit

Permalink
fix: default to global OrgUnit to get PPS HOSP surveys. Fail before a…
Browse files Browse the repository at this point in the history
…pi call if getOrgUnitByFormType returns undefined.
  • Loading branch information
MatiasArriola committed Feb 25, 2025
1 parent 5241144 commit 6824d0d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
7 changes: 5 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2025-02-13T17:58:53.810Z\n"
"PO-Revision-Date: 2025-02-13T17:58:53.810Z\n"
"POT-Creation-Date: 2025-02-25T14:41:42.341Z\n"
"PO-Revision-Date: 2025-02-25T14:41:42.341Z\n"

msgid "There was a problem with \"{{name}}\" - {{prop}} is not set"
msgstr ""
Expand Down Expand Up @@ -292,3 +292,6 @@ msgstr ""

msgid "Error updating database language."
msgstr ""

msgid "Could not resolve Org Unit for current form"
msgstr ""
24 changes: 16 additions & 8 deletions src/webapp/hooks/useSurveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isPaginatedSurveyList } from "../../domain/utils/PPSProgramsHelper";
import { getUserAccess } from "../../domain/utils/menuHelper";
import { useCurrentModule } from "../contexts/current-module-context";
import { GLOBAL_OU_ID } from "../../domain/usecases/SaveFormDataUseCase";
import i18n from "../../utils/i18n";

const PAGE_SIZE = 10;
export function useSurveys(surveyFormType: SURVEY_FORM_TYPES) {
Expand Down Expand Up @@ -42,14 +43,16 @@ export function useSurveys(surveyFormType: SURVEY_FORM_TYPES) {

switch (surveyFormType) {
case "PPSHospitalForm":
return currentCountryQuestionnaire?.orgUnitId ?? "";
// default to GLOBAL_OU_ID for "HOSP" since there is no country to use as OrgUnit
return currentPPSSurveyForm?.surveyType === "HOSP"
? GLOBAL_OU_ID
: currentCountryQuestionnaire?.orgUnitId;
case "PPSWardRegister":
case "PPSPatientRegister":
return currentHospitalForm?.orgUnitId ?? "";

return currentHospitalForm?.orgUnitId;
case "PrevalenceFacilityLevelForm":
return isAdmin
? currentPrevalenceSurveyForm?.orgUnitId ?? ""
? currentPrevalenceSurveyForm?.orgUnitId
: currentPrevalenceHospitals;
case "PrevalenceCaseReportForm":
case "PrevalenceCentralRefLabForm":
Expand All @@ -59,8 +62,7 @@ export function useSurveys(surveyFormType: SURVEY_FORM_TYPES) {
case "PrevalenceD28FollowUp":
case "PrevalenceCohortEnrolment":
case "PrevalenceDischarge":
return currentFacilityLevelForm?.orgUnitId ?? "";

return currentFacilityLevelForm?.orgUnitId;
default:
return GLOBAL_OU_ID;
}
Expand All @@ -72,11 +74,10 @@ export function useSurveys(surveyFormType: SURVEY_FORM_TYPES) {
isAdmin,
prevalenceHospitals,
surveyFormType,
currentPPSSurveyForm?.surveyType,
]);

useEffect(() => {
setLoadingSurveys(true);

const parentSurveyId =
!isAdmin &&
(surveyFormType === "PrevalenceFacilityLevelForm" ||
Expand All @@ -95,6 +96,13 @@ export function useSurveys(surveyFormType: SURVEY_FORM_TYPES) {

const orgUnitId = getOrgUnitByFormType();

if (!orgUnitId) {
setSurveysError(i18n.t("Could not resolve Org Unit for current form"));
return;
}

setLoadingSurveys(true);

//Only Patient Forms are paginated.
if (isPaginatedSurveyList(surveyFormType)) {
compositionRoot.surveys.getPaginatedSurveys
Expand Down

0 comments on commit 6824d0d

Please # to comment.