Skip to content

Commit

Permalink
#69 Restore functionality of the SDC-IDE fix reference
Browse files Browse the repository at this point in the history
  • Loading branch information
ialakey committed Jul 1, 2024
1 parent d003dea commit 18338a9
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions web/src/components/QRFormWrapper/components/reference/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { useFieldController } from '@beda.software/fhir-questionnaire/components/QuestionnaireResponseForm';
import {
parseFhirQueryExpression,
QuestionItemProps,
} from '@beda.software/fhir-questionnaire/vendor/sdc-qrf';
import { ResourcesMap } from '@beda.software/fhir-react';
import { isSuccess, buildQueryParams } from '@beda.software/remote-data';
import fhirpath from 'fhirpath';
import { ActionMeta, MultiValue, SingleValue } from 'react-select';
import { loadResourceOptions } from 'web/src/services/questionnaire';

import { isSuccess, buildQueryParams } from '@beda.software/remote-data';
import { ResourcesMap } from '@beda.software/fhir-react';

import {
QuestionnaireItemAnswerOption,
QuestionnaireResponseItemAnswer,
Expand Down Expand Up @@ -40,8 +38,6 @@ export function useAnswerReference<R extends Resource = any, IR extends Resource

const fieldName = fieldPath.join('.');

const { onChange } = useFieldController(fieldPath, questionItem);

// TODO: add support for fhirpath and application/x-fhir-query
const [resourceType, searchParams] = parseFhirQueryExpression(
answerExpression!.expression!,
Expand All @@ -62,18 +58,14 @@ export function useAnswerReference<R extends Resource = any, IR extends Resource
return [];
};

const handleChange = (
selectedValue:
const onChange = (
_value:
| SingleValue<QuestionnaireItemAnswerOption>
| MultiValue<QuestionnaireItemAnswerOption>,
action: ActionMeta<QuestionnaireItemAnswerOption>,
) => {
if (!repeats || action.action !== 'select-option') {
if (Array.isArray(selectedValue)) {
onChange(selectedValue as MultiValue<QuestionnaireItemAnswerOption>);
} else {
onChange(selectedValue as SingleValue<QuestionnaireItemAnswerOption>);
}
return;
}
};

Expand Down Expand Up @@ -101,7 +93,7 @@ export function useAnswerReference<R extends Resource = any, IR extends Resource
rootFieldName,
fieldName,
loadOptions,
onChange: handleChange,
onChange,
validate,
searchParams,
resourceType,
Expand Down

0 comments on commit 18338a9

Please sign in to comment.