Skip to content

Commit

Permalink
feat: auto populate case report patient id in child forms
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed May 15, 2024
1 parent 7d8ca3a commit c763c78
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
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
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
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

0 comments on commit c763c78

Please sign in to comment.