Skip to content

Commit

Permalink
Merge pull request #47 from EyeSeeTea/fix/child-count-case-report
Browse files Browse the repository at this point in the history
fix child count for case report form
  • Loading branch information
MiquelAdell authored May 22, 2024
2 parents 15c4f19 + c763c78 commit 066847b
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/data/entities/D2Survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const PREVALENCE_SURVEY_NAME_DATAELEMENT_ID = "HXnhZ8rsDts";
export const AMR_SURVEYS_PREVALENCE_DEA_AST_GUIDELINES = "SmuESJHyhC2";
export const AMR_SURVEYS_PREVALENCE_DEA_CUSTOM_AST_GUIDE = "lyeNV8Ag6lp";

export const AMR_SURVEYS_PREVALENCE_TEA_PATIENT_ID = "mUaaSzbeMmj";
export const AMR_SURVEYS_PREVALENCE_TEA_PATIENT_IDA19 = "yq8en6ZkENB";

//Prevalence Tracked Entity Attribute types
export const PREVALENCE_FACILITY_LEVEL_TET = "eY4BDBKXegX";
export const PREVALENCE_CASE_REPORT_TET = "hyR1eTHLX8B";
Expand Down
6 changes: 5 additions & 1 deletion src/data/utils/questionHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { Id } from "../../domain/entities/Ref";
import { Option, ProgramDataElement, TrackedEntityAttibute } from "../entities/D2Program";
import {
AMR_SURVEYS_PREVALENCE_DEA_SURVEY_ID,
AMR_SURVEYS_PREVALENCE_TEA_PATIENT_ID,
AMR_SURVEYS_PREVALENCE_TEA_PATIENT_IDA19,
AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRF,
AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRL,
AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_PIS,
Expand Down Expand Up @@ -352,7 +354,9 @@ export const mapTrackedAttributesToQuestions = (
currentQuestion.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRL ||
currentQuestion.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_PIS ||
currentQuestion.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_SRL ||
currentQuestion.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRF)
currentQuestion.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRF ||
currentQuestion.id === AMR_SURVEYS_PREVALENCE_TEA_PATIENT_ID ||
currentQuestion.id === AMR_SURVEYS_PREVALENCE_TEA_PATIENT_IDA19)
) {
currentQuestion.disabled = true;
}
Expand Down
17 changes: 13 additions & 4 deletions src/data/utils/surveyChildCountHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,23 @@ export const getSurveyChildCount = (
const eventCount = getTrackerSurveyCount(childId, orgUnitId, parentSurveyId, api);

return { type: "value", value: eventCount };
} else {
} else if (secondaryparentId) {
const eventCounts = childIds.value.map(id => {
return getTrackerSurveyCount(id, orgUnitId, parentSurveyId, api).map(count => {
return { id: id, count: count };
});
return getTrackerSurveyCount(id, orgUnitId, secondaryparentId, api).map(
count => {
return { id: id, count: count };
}
);
});

return { type: "map", value: Future.sequential(eventCounts) };
} else {
return {
type: "map",
value: Future.error(
new Error("secondaryparentId not provided for multichild program")
),
};
}
} else {
if (childIds.type === "singleChild") {
Expand Down
12 changes: 4 additions & 8 deletions src/data/utils/surveyProgramHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { Id } from "../../domain/entities/Ref";
import { SURVEY_FORM_TYPES } from "../../domain/entities/Survey";
import {
AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRF,
AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRL,
AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_PIS,
AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_SRL,
AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_SSTF,
PPS_COUNTRY_QUESTIONNAIRE_ID,
PPS_HOSPITAL_FORM_ID,
PPS_PATIENT_REGISTER_ID,
Expand All @@ -27,6 +23,8 @@ import {
SURVEY_ID_DATAELEMENT_ID,
SURVEY_ID_FACILITY_LEVEL_DATAELEMENT_ID,
WARD_ID_DATAELEMENT_ID,
AMR_SURVEYS_PREVALENCE_TEA_PATIENT_ID,
AMR_SURVEYS_PREVALENCE_TEA_PATIENT_IDA19,
} from "../entities/D2Survey";

export const isTrackerProgram = (programId: Id) => {
Expand Down Expand Up @@ -99,13 +97,11 @@ export const getParentDataElementForProgram = (programId: Id): Id => {
case PREVALENCE_CASE_REPORT_FORM_ID:
return AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRF;
case PREVALENCE_SAMPLE_SHIP_TRACK_FORM_ID:
return AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_SSTF;
case PREVALENCE_CENTRAL_REF_LAB_FORM_ID:
return AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRL;
case PREVALENCE_PATHOGEN_ISO_STORE_TRACK_ID:
return AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_PIS;
return AMR_SURVEYS_PREVALENCE_TEA_PATIENT_ID;
case PREVALENCE_SUPRANATIONAL_REF_LAB_ID:
return AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_SRL;
return AMR_SURVEYS_PREVALENCE_TEA_PATIENT_IDA19;
case PPS_COUNTRY_QUESTIONNAIRE_ID:
case PPS_HOSPITAL_FORM_ID:
case PPS_WARD_REGISTER_ID:
Expand Down
11 changes: 8 additions & 3 deletions src/domain/usecases/GetPaginatedPatientSurveysUseCase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FutureData } from "../../data/api-futures";
import { Id } from "../entities/Ref";
import { Survey, SURVEY_FORM_TYPES, SurveyBase } from "../entities/Survey";
import { getProgramId } from "../utils/PPSProgramsHelper";
import { getProgramId, isPrevalencePatientChild } from "../utils/PPSProgramsHelper";
import { PaginatedReponse } from "../entities/TablePagination";
import { PaginatedSurveyRepository } from "../repositories/PaginatedSurveyRepository";
import { SurveyRepository } from "../repositories/SurveyRepository";
Expand All @@ -21,13 +21,17 @@ export class GetPaginatedPatientSurveysUseCase {
orgUnitId: Id,
parentSurveyId: Id | undefined,
parentWardRegisterId: Id | undefined,
parentPatientId: Id | undefined,
page: number,
pageSize: number
): FutureData<PaginatedReponse<Survey[]>> {
const programId = getProgramId(surveyFormType);

const parentId =
surveyFormType === "PPSPatientRegister" ? parentWardRegisterId : parentSurveyId;
const parentId = isPrevalencePatientChild(surveyFormType)
? parentPatientId
: surveyFormType === "PPSPatientRegister"
? parentWardRegisterId
: parentSurveyId;

return this.paginatedSurveyRepo
.getSurveys(surveyFormType, programId, orgUnitId, parentId, page, pageSize)
Expand All @@ -42,6 +46,7 @@ export class GetPaginatedPatientSurveysUseCase {
surveyFormType: surveyFormType,
orgUnitId: survey.assignedOrgUnit.id,
parentSurveyId: survey.rootSurvey.id,
secondaryparentId: survey.id,
surveyReporsitory: this.paginatedSurveyRepo,
})
).map(([parentDetails, childCount]): Survey => {
Expand Down
23 changes: 20 additions & 3 deletions src/domain/usecases/GetSurveyUseCase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { FutureData } from "../../data/api-futures";
import {
AMR_SURVEYS_PREVALENCE_TEA_PATIENT_ID,
AMR_SURVEYS_PREVALENCE_TEA_PATIENT_IDA19,
AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRF,
AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRL,
AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_PIS,
Expand Down Expand Up @@ -30,13 +32,18 @@ export class GetSurveyUseCase {
surveyFormType: SURVEY_FORM_TYPES,
parentPPSSurveyId: Id | undefined,
parentWardRegisterId: Id | undefined,
parentPrevalenceSurveyId: Id | undefined
parentPrevalenceSurveyId: Id | undefined,
parentCaseReportId: Id | undefined
): FutureData<Questionnaire> {
const programId = getProgramId(surveyFormType);
if (parentPPSSurveyId) {
return this.getPPSSurveyForm(programId, parentPPSSurveyId, parentWardRegisterId);
} else if (parentPrevalenceSurveyId) {
return this.getPrevalenceSurveyForm(programId, parentPrevalenceSurveyId);
return this.getPrevalenceSurveyForm(
programId,
parentPrevalenceSurveyId,
parentCaseReportId
);
} else return this.surveyReporsitory.getForm(programId, undefined, undefined);
}

Expand Down Expand Up @@ -116,7 +123,8 @@ export class GetSurveyUseCase {

getPrevalenceSurveyForm(
programId: Id,
parentPrevalenceSurveyId: Id
parentPrevalenceSurveyId: Id,
parentCaseReportId: Id | undefined
): FutureData<Questionnaire> {
return this.surveyReporsitory
.getForm(programId, undefined, undefined)
Expand All @@ -136,11 +144,20 @@ export class GetSurveyUseCase {
question.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_SRL ||
question.id === AMR_SURVEYS_PREVALENCE_TEA_SURVEY_ID_CRF;

const isPatientIdQuestion =
question.id === AMR_SURVEYS_PREVALENCE_TEA_PATIENT_ID ||
question.id === AMR_SURVEYS_PREVALENCE_TEA_PATIENT_IDA19;

if (isSurveyIdQuestion && question.type === "text") {
return {
...question,
value: parentPrevalenceSurveyId,
};
} else if (isPatientIdQuestion && question.type === "text") {
return {
...question,
value: parentCaseReportId,
};
} else {
return question;
}
Expand Down
12 changes: 12 additions & 0 deletions src/domain/utils/PPSProgramsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,15 @@ export const isPaginatedSurveyList = (surveyFormType: SURVEY_FORM_TYPES): boolea
return false;
}
};

export const isPrevalencePatientChild = (surveyFormType: SURVEY_FORM_TYPES): boolean => {
switch (surveyFormType) {
case "PrevalenceCentralRefLabForm":
case "PrevalencePathogenIsolatesLog":
case "PrevalenceSampleShipTrackForm":
case "PrevalenceSupranationalRefLabForm":
return true;
default:
return false;
}
};
5 changes: 4 additions & 1 deletion src/webapp/components/survey/hook/useSurveyForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function useSurveyForm(formType: SURVEY_FORM_TYPES, eventId: string | und
currentWardRegister,
currentPrevalenceSurveyForm,
currentFacilityLevelForm,
currentCaseReportForm,
} = useCurrentSurveys();
const { hasReadOnlyAccess } = useReadOnlyAccess();

Expand All @@ -46,7 +47,8 @@ export function useSurveyForm(formType: SURVEY_FORM_TYPES, eventId: string | und
formType,
currentPPSSurveyForm?.id,
currentWardRegister?.id,
currentPrevalenceSurveyForm?.id
currentPrevalenceSurveyForm?.id,
currentCaseReportForm?.id
)
.run(
questionnaireForm => {
Expand Down Expand Up @@ -146,6 +148,7 @@ export function useSurveyForm(formType: SURVEY_FORM_TYPES, eventId: string | und
currentFacilityLevelForm,
currentPrevalenceSurveyForm,
currentModule,
currentCaseReportForm?.id,
]);

const updateQuestion = useCallback((question: Question, stageId?: string) => {
Expand Down
3 changes: 3 additions & 0 deletions src/webapp/hooks/useSurveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function useSurveys(surveyFormType: SURVEY_FORM_TYPES) {
currentWardRegister,
currentPrevalenceSurveyForm,
currentFacilityLevelForm,
currentCaseReportForm,
} = useCurrentSurveys();

const { currentModule } = useCurrentModule();
Expand Down Expand Up @@ -105,6 +106,7 @@ export function useSurveys(surveyFormType: SURVEY_FORM_TYPES) {
orgUnitId,
parentSurveyId,
currentWardRegister?.id,
currentCaseReportForm?.id,
page,
PAGE_SIZE
)
Expand Down Expand Up @@ -149,6 +151,7 @@ export function useSurveys(surveyFormType: SURVEY_FORM_TYPES) {
getOrgUnitByFormType,
isAdmin,
hospitalState,
currentCaseReportForm?.id,
]);

return {
Expand Down

0 comments on commit 066847b

Please sign in to comment.