Skip to content

Commit

Permalink
(feat) Support for pre-filled questions (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
icrc-jofrancisco authored Feb 1, 2024
1 parent b7b50c3 commit d88ad31
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FormDataSourceService } from '../form-data-source/form-data-source.serv
import { ConfigResourceService } from '../services/config-resource.service';
import { MonthlyScheduleResourceService } from '../services/monthly-scheduled-resource.service';
import { SingleSpaPropsService } from '../single-spa-props/single-spa-props.service';
import { Encounter, FormSchema, Identifier } from '../types';
import { Encounter, FormSchema, Identifier, PreFilledQuestions } from '../types';
import { Session } from '@openmrs/esm-framework';
import { isFunction } from 'lodash-es';

Expand Down Expand Up @@ -36,6 +36,11 @@ export interface CreateFormParams {
* Patient identifiers
*/
patientIdentifiers: Array<Identifier>;

/**
* Pre-filled questions
*/
preFilledQuestions?: PreFilledQuestions;
}

const loadedCustomDataSources: Record<string, unknown> = {};
Expand Down Expand Up @@ -275,6 +280,15 @@ export class FormCreationService {
if (encounterProvider.length > 0 && session?.currentProvider) {
encounterProvider[0].control.setValue(session.currentProvider.uuid);
}

// Pre-filled questions.
const preFilledQuestions = this.singleSpaPropsService.getProp('preFilledQuestions');
if (preFilledQuestions) {
Object.entries(preFilledQuestions).forEach(([questionId, value]) => {
const question = form.searchNodeByQuestionId(questionId);
question[0]?.control?.setValue(value);
});
}
}

private setUpPayloadProcessingInformation(form: Form, createFormParams: CreateFormParams) {
Expand Down
4 changes: 4 additions & 0 deletions packages/esm-form-entry-app/src/app/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ export interface FormSchemaAndTranslations extends FormSchema {
translations?: Record<string, string>;
}

export interface PreFilledQuestions {
[key: string]: string;
}

interface Sections {
isExpanded: boolean;
label: string;
Expand Down
5 changes: 5 additions & 0 deletions packages/esm-form-entry-app/src/single-spa-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type Form = {
formUuid: string;
};

type PreFilledQuestions = {
[key: string]: string;
};

// Add any custom single-spa props you have to this type def
// https://single-spa.js.org/docs/building-applications.html#custom-props
export type SingleSpaProps = AppProps &
Expand All @@ -46,6 +50,7 @@ export type SingleSpaProps = AppProps &
EncounterProperties &
PatientProperties &
UIBehavior &
PreFilledQuestions &
ApplicationStatus & {
additionalProps?: any;
};

0 comments on commit d88ad31

Please sign in to comment.