Skip to content

Commit

Permalink
Use some helper functions from fhir-sdc-helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
fongsean committed Dec 20, 2023
1 parent 51eda35 commit f7eb968
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 102 deletions.
48 changes: 0 additions & 48 deletions apps/smart-forms-app/src/api/local.ts

This file was deleted.

19 changes: 0 additions & 19 deletions apps/smart-forms-app/src/features/renderer/utils/itemControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,6 @@ export function getShortText(qItem: QuestionnaireItem): string | null {
return null;
}

/**
* Check if the extension has url for hidden questions
*
* @author Sean Fong
*/
export function hasHiddenExtension(qItem: QuestionnaireItem): boolean {
const itemControl = qItem.extension?.find(
(extension: Extension) =>
extension.url === 'http://hl7.org/fhir/StructureDefinition/questionnaire-hidden'
);

if (itemControl) {
if (itemControl.valueBoolean) {
return true;
}
}
return false;
}

/**
* Check if an answerExpression extension is present
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,3 @@ export function responseToQuestionnaireResource(
console.error(response);
}
}

export function getLaunchIntent(client: Client): string | null {
const tokenResponse = client.state.tokenResponse as tokenResponseCustomised;
const launchIntent = tokenResponse.intent;

return launchIntent ?? null;
}
4 changes: 2 additions & 2 deletions packages/smart-forms-renderer/src/hooks/useHidden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
*/

import type { QuestionnaireItem } from 'fhir/r4';
import { hasHiddenExtension } from '../utils/itemControl';
import { useQuestionnaireStore } from '../stores';
import { isHiddenByEnableWhens } from '../utils/qItem';
import { structuredDataCapture } from 'fhir-sdc-helpers';

function useHidden(qItem: QuestionnaireItem): boolean {
const enableWhenIsActivated = useQuestionnaireStore.use.enableWhenIsActivated();
const enableWhenItems = useQuestionnaireStore.use.enableWhenItems();
const enableWhenExpressions = useQuestionnaireStore.use.enableWhenExpressions();

if (hasHiddenExtension(qItem)) {
if (structuredDataCapture.getHidden(qItem)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

import {
getEntryFormat,
getMaxLength,
getReadOnly,
getRegexValidation,
Expand All @@ -26,6 +25,7 @@ import {
} from '../utils/itemControl';
import type { QuestionnaireItem } from 'fhir/r4';
import type { RegexValidation } from '../interfaces/regex.interface';
import { structuredDataCapture } from 'fhir-sdc-helpers';

interface RenderingExtensions {
displayUnit: string;
Expand All @@ -43,7 +43,7 @@ function useRenderingExtensions(qItem: QuestionnaireItem): RenderingExtensions {
displayPrompt: getTextDisplayPrompt(qItem),
displayInstructions: getTextDisplayInstructions(qItem),
readOnly: getReadOnly(qItem),
entryFormat: getEntryFormat(qItem),
entryFormat: structuredDataCapture.getEntryFormat(qItem) ?? '',
regexValidation: getRegexValidation(qItem),
maxLength: getMaxLength(qItem)
};
Expand Down
4 changes: 2 additions & 2 deletions packages/smart-forms-renderer/src/utils/qItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/

import type { Extension, Questionnaire, QuestionnaireItem } from 'fhir/r4';
import { hasHiddenExtension } from './itemControl';
import { getChoiceControlType } from './choice';
import { ChoiceItemControl, OpenChoiceItemControl } from '../interfaces/choice.enum';
import { getOpenChoiceControlType } from './openChoice';
import type { EnableWhenExpression, EnableWhenItems } from '../interfaces/enableWhen.interface';
import { structuredDataCapture } from 'fhir-sdc-helpers';

interface isHiddenParams {
questionnaireItem: QuestionnaireItem;
Expand All @@ -39,7 +39,7 @@ interface isHiddenParams {
export function isHidden(params: isHiddenParams): boolean {
const { questionnaireItem, enableWhenIsActivated, enableWhenItems, enableWhenExpressions } =
params;
if (hasHiddenExtension(questionnaireItem)) {
if (structuredDataCapture.getHidden(questionnaireItem)) {
return true;
}

Expand Down
25 changes: 3 additions & 22 deletions packages/smart-forms-renderer/src/utils/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import type { Tabs } from '../interfaces/tab.interface';
import type { EnableWhenExpression, EnableWhenItems } from '../interfaces/enableWhen.interface';
import type { Coding, QuestionnaireItem } from 'fhir/r4';
import { hasHiddenExtension, isSpecificItemControl } from './itemControl';
import { isSpecificItemControl } from './itemControl';
import { isHidden, isHiddenByEnableWhens } from './qItem';
import { structuredDataCapture } from 'fhir-sdc-helpers';

export function getFirstVisibleTab(
tabs: Tabs,
Expand Down Expand Up @@ -134,7 +135,7 @@ export function constructTabsWithProperties(
tabs[qItem.linkId] = {
tabIndex: i,
isComplete: false,
isHidden: hasHiddenExtension(qItem)
isHidden: structuredDataCapture.getHidden(qItem) ?? false
};
}
return tabs;
Expand Down Expand Up @@ -201,26 +202,6 @@ export function getNextVisibleTabIndex(params: getNextVisibleTabIndexParams): nu

return nextTabIndex;
}
/**
*
* Get index of first visible tab
*
* @author Sean Fong
*/
export function getFirstVisibleTabIndex(
tabs: Tabs,
enableWhenIsActivated: boolean,
enableWhenItems: EnableWhenItems,
enableWhenExpressions: Record<string, EnableWhenExpression>
): number | undefined {
const tabsWithVisibility = constructTabsWithVisibility({
tabs,
enableWhenIsActivated,
enableWhenItems,
enableWhenExpressions
});
return tabsWithVisibility.findIndex((tab) => tab.isVisible);
}

/**
*
Expand Down

0 comments on commit f7eb968

Please sign in to comment.