Skip to content

Commit

Permalink
Merge branch 'feature/antibiotic-blacklist' of https://github.com/Eye…
Browse files Browse the repository at this point in the history
…SeeTea/amr-surveys into feature/antibiotic-blacklist
  • Loading branch information
davidbgomes committed May 24, 2024
2 parents 6eb2c3b + 2b02e4e commit 08e6e8e
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 33 deletions.
2 changes: 1 addition & 1 deletion i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2024-05-23T16:02:03.207Z\n"
"POT-Creation-Date: 2024-05-22T13:24:01.336Z\n"
"PO-Revision-Date: 2018-10-25T09:02:35.143Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "amr-surveys",
"description": "AMR Surveys App",
"version": "0.2.0",
"version": "0.5.0",
"license": "GPL-3.0",
"author": "EyeSeeTea team",
"homepage": ".",
Expand Down
4 changes: 4 additions & 0 deletions src/CompositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { GetASTGuidelinesUseCase } from "./domain/usecases/GetASTGuidelinesUseCa
import { ASTGuidelinesD2Repository } from "./data/repositories/ASTGuidelinesD2Repository";
import { ASTGuidelinesTestRepository } from "./data/repositories/testRepositories/ASTGuidelinesTestRepository";
import { GetSurveyAntibioticsBlacklistUseCase } from "./domain/usecases/GetSurveyAntibioticsBlacklistUseCase";
import { RemoveRepeatableProgramStageUseCase } from "./domain/usecases/RemoveRepeatableProgramStageUseCase";

export type CompositionRoot = ReturnType<typeof getCompositionRoot>;

Expand Down Expand Up @@ -91,6 +92,9 @@ function getCompositionRoot(repositories: Repositories) {
getSurveyAntibioticsBlacklist: new GetSurveyAntibioticsBlacklistUseCase(
repositories.surveyFormRepository
),
removeRepeatableStage: new RemoveRepeatableProgramStageUseCase(
repositories.surveyFormRepository
),
},
astGuidelines: {
getGuidelines: new GetASTGuidelinesUseCase(repositories.astGuidelinesRepository),
Expand Down
18 changes: 14 additions & 4 deletions src/data/repositories/SurveyFormD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
AMR_SURVEYS_PREVALENCE_DEA_CUSTOM_AST_GUIDE,
AMR_SURVEYS_PREVALENCE_DEA_AST_GUIDELINES,
} from "../entities/D2Survey";
import { ProgramMetadata } from "../entities/D2Program";
import { ProgramDataElement, ProgramMetadata } from "../entities/D2Program";
import {
mapProgramToQuestionnaire,
mapQuestionnaireToEvent,
Expand Down Expand Up @@ -60,6 +60,16 @@ export class SurveyD2Repository implements SurveyRepository {
const programDataElements = resp.programStageDataElements.map(
psde => psde.dataElement
);
const dataElementsWithSortOrder: ProgramDataElement[] = resp.dataElements.map(
de => {
return {
...de,
sortOrder: resp.programStageDataElements.find(
psde => psde.dataElement.id === de.id
)?.sortOrder,
};
}
);

const sortedTrackedentityAttr = resp.programTrackedEntityAttributes
? _(
Expand Down Expand Up @@ -93,7 +103,7 @@ export class SurveyD2Repository implements SurveyRepository {
undefined,
trackedEntity,
programDataElements,
resp.dataElements,
dataElementsWithSortOrder,
sortedOptions,
resp.programStages,
resp.programStageSections,
Expand All @@ -119,7 +129,7 @@ export class SurveyD2Repository implements SurveyRepository {
event,
undefined,
programDataElements,
resp.dataElements,
dataElementsWithSortOrder,
resp.options,
resp.programStages,
resp.programStageSections,
Expand All @@ -143,7 +153,7 @@ export class SurveyD2Repository implements SurveyRepository {
undefined,
undefined,
programDataElements,
resp.dataElements,
dataElementsWithSortOrder,
resp.options,
resp.programStages,
resp.programStageSections,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { ASTGUIDELINE_TYPES } from "../../../domain/entities/ASTGuidelines";
import { SurveyChildCountType } from "../../utils/surveyChildCountHelper";

export class SurveyTestRepository implements SurveyRepository {
deleteEventSurvey(_eventId: string, _orgUnitId: string, _programId: string): FutureData<void> {
throw new Error("Method not implemented.");
}
getSurveyNameAndASTGuidelineFromId(
id: string,
surveyFormType: SURVEY_FORM_TYPES
Expand Down
1 change: 1 addition & 0 deletions src/data/utils/questionHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export const mapProgramDataElementToQuestions = (
})
)
.compact()
.sortBy(q => q.sortOrder)
.value();

return questions;
Expand Down
4 changes: 2 additions & 2 deletions src/data/utils/surveyFormMappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const getRepeatedStageEvents = (
dataElements: ProgramDataElement[],
options: Option[],
programStageSections?: ProgramStageSection[]
) => {
): QuestionnaireStage[] | undefined => {
const repeatedStageEvents = trackedEntity?.enrollments
?.at(0)
?.events.filter(e => e.programStage === stage.id);
Expand Down Expand Up @@ -254,7 +254,7 @@ const getRepeatedStageEvents = (
instanceId: repeatedStageEvt.event,
sortOrder: stage.sortOrder,
repeatable: stage.repeatable,
userAdded: index === 0 ? false : true,
isAddedByUser: index === 0 ? false : true,
};
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/domain/entities/AMRSurveyModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type SURVEY_TYPE = "NationalSurvey" | "HospitalSurvey" | "SupranationalSu

type UserGroups = { captureAccess: NamedRef[]; readAccess: NamedRef[]; adminAccess: NamedRef[] };

type SurveyRuleType = "HIDEFIELD" | "HIDESECTION";
type SurveyRuleType = "HIDEFIELD" | "HIDESECTION" | "HIDESTAGE";

type Rule = {
id: Id;
Expand Down
26 changes: 26 additions & 0 deletions src/domain/entities/Questionnaire/Questionnaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ export class Questionnaire {
const updatedStages = questionnaire.stages.map(stage => {
return {
...stage,
isVisible: !surveyRule.rules.find(rule =>
rule.toHide?.find(ruleStage => ruleStage === stage.id)
),
sections: stage.sections.map(section => {
const currentSectionRule = surveyRule.rules.find(rule =>
rule.toHide?.find(de => de === section.code)
Expand Down Expand Up @@ -208,6 +211,29 @@ export class Questionnaire {
updatedStages
);

const hideEntityQuestionRule = surveyRule.rules.find(
rule =>
rule.type === "HIDEFIELD" &&
rule.toHide.find(id =>
updatedQuestionnaire.entity?.questions.find(q => q.id === id)
)
);
if (hideEntityQuestionRule && questionnaire.entity) {
const updatedEntityQuestions: Question[] = questionnaire.entity.questions.map(
question => {
return {
...question,
isVisible: hideEntityQuestionRule.toHide.find(id => id === question.id)
? false
: true,
};
}
);

const updatedEntity = { ...questionnaire.entity, questions: updatedEntityQuestions };
return Questionnaire.updateQuestionnaireEntity(updatedQuestionnaire, updatedEntity);
}

return updatedQuestionnaire;
}

Expand Down
1 change: 1 addition & 0 deletions src/domain/repositories/SurveyRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface SurveyRepository {
): FutureData<Questionnaire>;

deleteSurvey(id: Id, orgUnitId: Id, programId: Id): FutureData<void>;
deleteEventSurvey(eventId: Id, orgUnitId: Id, programId: Id): FutureData<void>;

getSurveyNameAndASTGuidelineFromId(
id: Id,
Expand Down
28 changes: 28 additions & 0 deletions src/domain/usecases/RemoveRepeatableProgramStageUseCase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { FutureData } from "../../data/api-futures";
import { PREVALENCE_FACILITY_LEVEL_FORM_ID } from "../../data/entities/D2Survey";
import { Questionnaire } from "../entities/Questionnaire/Questionnaire";
import { Future } from "../entities/generic/Future";
import { SurveyRepository } from "../repositories/SurveyRepository";

export class RemoveRepeatableProgramStageUseCase {
constructor(private surveyRepository: SurveyRepository) {}

execute(questionnaire: Questionnaire, stageId: string): FutureData<Questionnaire> {
//Repeatable Program Stages are only applicable to Prevalence Facility forms

const eventId = questionnaire.stages.find(stage => stage.id === stageId)?.instanceId;

if (!eventId)
return Future.error(new Error("Cannot find event Id correspoding to the stage"));

return this.surveyRepository
.deleteEventSurvey(eventId, questionnaire.orgUnit.id, PREVALENCE_FACILITY_LEVEL_FORM_ID)
.flatMap(() => {
const updatedQuestionnaire = Questionnaire.removeProgramStage(
questionnaire,
stageId
);
return Future.success(updatedQuestionnaire);
});
}
}
2 changes: 1 addition & 1 deletion src/domain/usecases/SaveFormDataUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class SaveFormDataUseCase {
surveyFormType === "PPSSurveyForm" && orgUnitId === "" ? GLOBAL_OU_ID : orgUnitId;

//Do not allow creation of multiple Prevalence Facility Level Forms for the same facility.
if (surveyFormType === "PrevalenceFacilityLevelForm") {
if (!eventId && surveyFormType === "PrevalenceFacilityLevelForm") {
return this.surveyReporsitory
.getSurveys(surveyFormType, programId, ouId, false)
.flatMap(surveys => {
Expand Down
14 changes: 1 addition & 13 deletions src/webapp/components/survey-questions/QuestionWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import TextWidget from "./widgets/TextWidget";
import YesNoWidget from "./widgets/YesNoWidget";
import DatePickerWidget from "./widgets/DatePickerWidget";
import { Maybe, assertUnreachable } from "../../../utils/ts-utils";
import DropdownSelectWidget from "./widgets/DropdownSelectWidget";
import DateTimePickerWidget from "./widgets/DateTimePickerWidget";
import SearchableSelect from "./widgets/SearchableSelect";
import {
Expand All @@ -28,18 +27,7 @@ export const QuestionWidget: React.FC<QuestionWidgetProps> = React.memo(props =>

switch (type) {
case "select": {
if (question.options.length > 5 && question.options.length < 10) {
return (
<DropdownSelectWidget
value={question.value?.id}
options={question.options}
onChange={(value: Maybe<QuestionOption>) =>
onChange(update(question, value))
}
disabled={disabled}
/>
);
} else if (question.options.length > 10) {
if (question.options.length > 5) {
return (
<SearchableSelect
value={question.options.find(op => op.id === question.value?.id) || null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const DatePickerWidget: React.FC<DatePickerWidgetProps> = props => {
value={stateValue}
disabled={props.disabled}
onChange={newValue => notifyChange(newValue)}
format="dd-MM-yyyy"
/>
</LocalizationProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const DateTimePickerWidget: React.FC<DateTimePickerWidgetProps> = props => {
disabled={props.disabled}
onChange={newValue => notifyChange(newValue?.toISOString() ?? "")}
ampm={false}
format="dd-MM-yyyy HH:mm"
/>
</LocalizationProvider>
);
Expand Down
16 changes: 11 additions & 5 deletions src/webapp/components/survey/hook/useSurveyForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,20 @@ export function useSurveyForm(
const removeProgramStage = useCallback(
(stageId: Id) => {
if (questionnaire) {
const updatedQuestionnaire = Questionnaire.removeProgramStage(
questionnaire,
stageId
setLoading(true);
compositionRoot.surveys.removeRepeatableStage.execute(questionnaire, stageId).run(
updatedQuestionnaire => {
setQuestionnaire(updatedQuestionnaire);
setLoading(false);
},
err => {
setLoading(false);
setError(err.message);
}
);
setQuestionnaire(updatedQuestionnaire);
}
},
[questionnaire]
[compositionRoot.surveys, questionnaire]
);

return {
Expand Down
5 changes: 0 additions & 5 deletions src/webapp/pages/survey-list/useRedirectHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export function useRedirectHome() {
const {
currentPPSSurveyForm,
currentPrevalenceSurveyForm,
currentCountryQuestionnaire,
currentHospitalForm,
currentWardRegister,
currentFacilityLevelForm,
Expand All @@ -30,9 +29,6 @@ export function useRedirectHome() {

if (
(formType === "PPSCountryQuestionnaire" && !currentPPSSurveyForm) ||
(hasAdminAccess &&
formType === "PPSHospitalForm" &&
!currentCountryQuestionnaire) ||
(formType === "PPSWardRegister" && !currentHospitalForm) ||
(formType === "PPSPatientRegister" && !currentWardRegister) ||
(hasAdminAccess &&
Expand All @@ -52,7 +48,6 @@ export function useRedirectHome() {
currentModule,
userGroups,
currentPPSSurveyForm,
currentCountryQuestionnaire,
currentHospitalForm,
currentWardRegister,
currentPrevalenceSurveyForm,
Expand Down

0 comments on commit 08e6e8e

Please sign in to comment.