Skip to content

Commit

Permalink
fix: review comments fix
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Jan 1, 2024
1 parent 9d5ee66 commit abe846a
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 315 deletions.
43 changes: 26 additions & 17 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: 2023-12-18T07:38:38.697Z\n"
"PO-Revision-Date: 2023-12-18T07:38:38.697Z\n"
"POT-Creation-Date: 2024-01-01T15:15:58.433Z\n"
"PO-Revision-Date: 2024-01-01T15:15:58.433Z\n"

msgid "WHO privacy policy"
msgstr ""
Expand All @@ -17,9 +17,6 @@ msgstr ""
msgid "Log Out"
msgstr ""

msgid "Add new"
msgstr ""

msgid "Cancel"
msgstr ""

Expand All @@ -44,6 +41,9 @@ msgstr ""
msgid "Patients"
msgstr ""

msgid "Add new"
msgstr ""

msgid "Submission Success!"
msgstr ""

Expand All @@ -55,6 +55,9 @@ msgstr ""
msgid "Country"
msgstr ""

msgid "Filter by Status"
msgstr ""

msgid "COMPLETED"
msgstr ""

Expand All @@ -67,6 +70,9 @@ msgstr ""
msgid "ALL"
msgstr ""

msgid "Filter by Survey Type"
msgstr ""

msgid "SUPRANATIONAL"
msgstr ""

Expand All @@ -76,40 +82,43 @@ msgstr ""
msgid "HOSP"
msgstr ""

msgid "Root Survey Name"
msgid "Survey deleted!"
msgstr ""

msgid "Org Unit"
msgid "Error deleting the survery"
msgstr ""

msgid "Start Date"
msgid "Root Survey Name"
msgstr ""

msgid "Status"
msgid "Patient Id"
msgstr ""

msgid "Survey Type"
msgid "Patient Name"
msgstr ""

msgid "Patient Id"
msgid "Action"
msgstr ""

msgid "Patient Name"
msgid "No data found..."
msgstr ""

msgid "Ward Code"
msgid "Org Unit"
msgstr ""

msgid "Hospital Code"
msgid "Start Date"
msgstr ""

msgid "Action"
msgid "Status"
msgstr ""

msgid "Survey deleted!"
msgid "Survey Type"
msgstr ""

msgid "Error deleting the survery"
msgid "Ward Code"
msgstr ""

msgid "Hospital Code"
msgstr ""

msgid "Yes"
Expand Down
143 changes: 101 additions & 42 deletions src/domain/usecases/GetSurveyUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import {
WARD_ID_DATAELEMENT_ID,
} from "../../data/repositories/SurveyFormD2Repository";
import { Future } from "../entities/generic/Future";
import { Questionnaire } from "../entities/Questionnaire";
import {
Question,
Questionnaire,
QuestionnaireEntity,
QuestionnaireSection,
QuestionnaireStage,
} from "../entities/Questionnaire";
import { Id } from "../entities/Ref";
import { SURVEY_FORM_TYPES } from "../entities/Survey";

Expand All @@ -31,57 +37,110 @@ export class GetSurveyUseCase {
return this.surveyReporsitory
.getForm(programId, undefined, undefined)
.flatMap(questionnaire => {
//PPS Questionnaires have only 1 stage
const surveyIdSection = questionnaire.stages[0]?.sections.find(
s =>
s.questions.find(
q =>
q.id === SURVEY_ID_DATAELEMENT_ID ||
q.id === SURVEY_ID_PATIENT_DATAELEMENT_ID
) !== undefined
);
if (surveyIdSection) {
const surveyIdDataElement = surveyIdSection.questions.find(
q =>
q.id === SURVEY_ID_DATAELEMENT_ID ||
q.id === SURVEY_ID_PATIENT_DATAELEMENT_ID
);
if (surveyIdDataElement) {
surveyIdDataElement.value = parentPPSSurveyId;
}
}
if (questionnaire.stages && questionnaire.stages[0]) {
const updatedSections: QuestionnaireSection[] =
questionnaire.stages[0].sections.map(section => {
//PPS Questionnaires have only 1 stage
const isSurveyIdOrWardIdSection =
section.questions.find(
question =>
question.id === SURVEY_ID_DATAELEMENT_ID ||
question.id === SURVEY_ID_PATIENT_DATAELEMENT_ID ||
question.id === WARD_ID_DATAELEMENT_ID
) !== undefined;

//PPS Questionnaires have only 1 stage
const wardIdSection = questionnaire.stages[0]?.sections.find(
s => s.questions.find(q => q.id === WARD_ID_DATAELEMENT_ID) !== undefined
);
if (wardIdSection) {
const wardIdDataElement = wardIdSection.questions.find(
q => q.id === WARD_ID_DATAELEMENT_ID
);
if (wardIdDataElement) {
wardIdDataElement.value = parentWardRegisterId;
}
if (isSurveyIdOrWardIdSection) {
const updatedQuestions: Question[] = section.questions.map(
question => {
const isSurveyIdQuestion =
question.id === SURVEY_ID_DATAELEMENT_ID ||
question.id === SURVEY_ID_PATIENT_DATAELEMENT_ID;
const isWardIdQuestion =
question.id === WARD_ID_DATAELEMENT_ID;

if (isSurveyIdQuestion && question.type === "text") {
//Survey Id Question, pre-populate value to parent survey id
const updatedSurveyIdQuestion: Question = {
...question,
value: parentPPSSurveyId,
};
return updatedSurveyIdQuestion;
} else if (
isWardIdQuestion &&
question.type === "text"
) {
//Survey Id Question, pre-populate value to parent survey id
const updatedWardIdQuestion: Question = {
...question,
value: parentWardRegisterId,
};
return updatedWardIdQuestion;
} else {
//Not survey id question, return without any update
return question;
}
}
);

return {
...section,
questions: updatedQuestions,
};
}

//Not survey id section, return without any update
return section;
});

const updatedStage: QuestionnaireStage = {
...questionnaire.stages[0],
sections: updatedSections,
};

return Future.success({ ...questionnaire, stages: [updatedStage] });
} else {
return Future.success(questionnaire);
}
return Future.success(questionnaire);
});
} else if (parentPrevalenceSurveyId) {
return this.surveyReporsitory
.getForm(programId, undefined, undefined)
.flatMap(questionnaire => {
//The Survey Id is always part of Tracked Entity which is the Profile Section i.e questionnaire.entity
const surveyIdDataElement = questionnaire.entity?.questions.find(
q =>
q.id === SURVEY_ID_FACILITY_LEVEL_DATAELEMENT_ID ||
q.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_SSTF ||
q.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRL ||
q.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_PIS ||
q.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_SRL ||
q.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRF

if (!questionnaire.entity) {
return Future.success(questionnaire);
}
const updatedEntityQuestions: Question[] = questionnaire.entity.questions.map(
question => {
const isSurveyIdQuestion =
question.id === SURVEY_ID_FACILITY_LEVEL_DATAELEMENT_ID ||
question.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_SSTF ||
question.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRL ||
question.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_PIS ||
question.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_SRL ||
question.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRF;

if (isSurveyIdQuestion && question.type === "text") {
return {
...question,
value: parentPrevalenceSurveyId,
};
} else {
return question;
}
}
);
if (surveyIdDataElement) surveyIdDataElement.value = parentPrevalenceSurveyId;

return Future.success(questionnaire);
const updatedEntity: QuestionnaireEntity = {
...questionnaire.entity,
questions: updatedEntityQuestions,
};

return Future.success({
...questionnaire,
entity: updatedEntity,
});
});
} else return this.surveyReporsitory.getForm(programId, undefined, undefined);
}
Expand Down
5 changes: 3 additions & 2 deletions src/domain/usecases/SaveFormDataUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ export class SaveFormDataUseCase {
const programId = getProgramId(surveyFormType);

//All PPS Survey Forms are Global.
if (surveyFormType === "PPSSurveyForm" && orgUnitId === "") orgUnitId = GLOBAL_OU_ID;
const ouId =
surveyFormType === "PPSSurveyForm" && orgUnitId === "" ? GLOBAL_OU_ID : orgUnitId;

return this.surveyReporsitory.saveFormData(
questionnaire,
"CREATE_AND_UPDATE",
orgUnitId,
ouId,
eventId,
programId
);
Expand Down
13 changes: 3 additions & 10 deletions src/domain/utils/menuHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@ export const getUserAccess = (module: AMRSurveyModule, currentUserGroups: NamedR
const hasReadAccess =
currentUserGroups.filter(cug =>
module.userGroups.readAccess?.some(raug => raug.id === cug.id)
).length > 0
? true
: false;
).length > 0;
const hasCaptureAccess =
currentUserGroups.filter(cug =>
module.userGroups.captureAccess?.some(caug => caug.id === cug.id)
).length > 0
? true
: false;
).length > 0;
const hasAdminAccess =
currentUserGroups.filter(cug =>
module.userGroups.adminAccess?.some(aaug => aaug.id === cug.id)
).length > 0
? true
: false;

).length > 0;
return { hasReadAccess, hasCaptureAccess, hasAdminAccess };
};

Expand Down
Loading

0 comments on commit abe846a

Please sign in to comment.