import type { OperationOutcome, Questionnaire, QuestionnaireResponse, QuestionnaireResponseItem } from 'fhir/r4'; import type { Diff } from 'deep-diff'; /** * QuestionnaireResponseStore properties and methods * Properties can be accessed for fine-grain details. * Methods are usually used internally, but it is possible to use them externally to hook into the renderer for more fine-grain control. * * @property key - The React key of the questionnaireResponse, used internally for refreshing the BaseRenderer * @property sourceResponse - The original response created when the form is first initialised i.e. empty, pre-populated, opened saved draft * @property updatableResponse - The current state of the response that is being updated via form fields * @property updatableResponseItems - Key-value pair of updatableResponse items `Record` * @property formChangesHistory - Array of form changes history in the form of deep-diff objects * @property invalidItems - Key-value pair of invalid items based on defined value constraints in the questionnaire `Record`. For items outside a repeating group the errorKey is the bare `linkId`. For items inside one or more repeating group instances it is `linkId///path`, where path is the dot-separated indices of the enclosing instances **within the QuestionnaireResponse** e.g. `myField///1`, or `myField///0.2` when nested — so each instance tracks its own errors instead of all instances sharing one key. Use `getValidationErrorKey()` / `getBaseLinkIdFromErrorKey()` from `utils/validateErrorKey` to build or parse a key rather than assuming a bare linkId * @property requiredItemsIsHighlighted - Required items are not highlighted by default (to provide a less-jarring UX), but can be manually toggled to be highlighted * @property responseIsValid - Whether there are any invalid items in the response * @property validateQuestionnaireResponse - Used to validate the questionnaire response based on the questionnaire * @property buildSourceResponse - Used to build the source response when the form is first initialised * @property updateResponse - Used to update the current response, initialUpdate flag is to ensure formChangesHistory is not updated during the first update after form build * @property setUpdatableResponseAsSaved - Used to set a saved response as the current response * @property setUpdatableResponseAsEmpty - Used to set an empty response as the current response * @property destroySourceResponse - Used to destroy the source response and reset all properties * @property highlightRequiredItems - Used to highlight invalid items and show error feedback in the UI * * @author Sean Fong */ export interface QuestionnaireResponseStoreType { key: string; sourceResponse: QuestionnaireResponse; updatableResponse: QuestionnaireResponse; updatableResponseItems: Record; formChangesHistory: (Diff[] | null)[]; invalidItems: Record; requiredItemsIsHighlighted: boolean; responseIsValid: boolean; responseHasErrors: boolean; validateResponse: (questionnaire: Questionnaire, updatedResponse: QuestionnaireResponse) => void; buildSourceResponse: (response: QuestionnaireResponse) => void; updateResponse: (updatedResponse: QuestionnaireResponse, isInitialUpdate: boolean) => void; setUpdatableResponseAsSaved: (savedResponse: QuestionnaireResponse) => void; setUpdatableResponseAsEmpty: (clearedResponse: QuestionnaireResponse) => void; destroySourceResponse: () => void; highlightRequiredItems: () => void; } /** * QuestionnaireResponse state management store which contains all properties and methods to manage the state of the questionnaireResponse. * This is the vanilla version of the store which can be used in non-React environments. * @see {@link QuestionnaireResponseStoreType} for available properties and methods. * * @author Sean Fong */ export declare const questionnaireResponseStore: import("zustand/vanilla").StoreApi; /** * QuestionnaireResponse state management store which contains all properties and methods to manage the state of the questionnaire. * This is the React version of the store which can be used as React hooks in React functional components. * @see {@link QuestionnaireResponseStoreType} for available properties and methods. * @see {@link questionnaireResponseStore} for the vanilla store. * * @author Sean Fong */ export declare const useQuestionnaireResponseStore: import("zustand/vanilla").StoreApi & { use: { key: () => string; sourceResponse: () => QuestionnaireResponse; updatableResponse: () => QuestionnaireResponse; updatableResponseItems: () => Record; formChangesHistory: () => (Diff[] | null)[]; invalidItems: () => Record; requiredItemsIsHighlighted: () => boolean; responseIsValid: () => boolean; responseHasErrors: () => boolean; validateResponse: () => (questionnaire: Questionnaire, updatedResponse: QuestionnaireResponse) => void; buildSourceResponse: () => (response: QuestionnaireResponse) => void; updateResponse: () => (updatedResponse: QuestionnaireResponse, isInitialUpdate: boolean) => void; setUpdatableResponseAsSaved: () => (savedResponse: QuestionnaireResponse) => void; setUpdatableResponseAsEmpty: () => (clearedResponse: QuestionnaireResponse) => void; destroySourceResponse: () => () => void; highlightRequiredItems: () => () => void; }; };