Skip to content

Commit 2aa4134

Browse files
committed
Refactor
1 parent 6f97527 commit 2aa4134

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/utils.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ import {
2525
} from './types';
2626
import { FCEQuestionnaireItem } from 'fce.types';
2727

28+
const FHIRPrimitiveTypes = [
29+
'base64Binary',
30+
'boolean',
31+
'canonical',
32+
'code',
33+
'date',
34+
'dateTime',
35+
'decimal',
36+
'id',
37+
'instant',
38+
'integer',
39+
'integer64',
40+
'markdown',
41+
'oid',
42+
'positiveInt',
43+
'string',
44+
'time',
45+
'unsignedInt',
46+
'uri',
47+
'url',
48+
'uuid',
49+
];
50+
2851
export function wrapAnswerValue(type: QuestionnaireItem['type'], answer: any) {
2952
if (type === 'choice') {
3053
if (isPlainObject(answer)) {
@@ -401,7 +424,7 @@ export function compareValue(firstAnswerValue: AnswerValue, secondAnswerValue: A
401424
if (firstValueType !== secondValueType) {
402425
throw new Error('Enable when must be used for the same type');
403426
}
404-
if (!_.includes(['string', 'date', 'dateTime', 'time', 'uri', 'boolean', 'integer', 'decimal'], firstValueType)) {
427+
if (!_.includes(FHIRPrimitiveTypes, firstValueType)) {
405428
throw new Error('Impossible to compare non-primitive type');
406429
}
407430

@@ -770,29 +793,6 @@ function getChoiceTypeValue(obj: Record<any, any>, prefix: string): any | undefi
770793
return prefixKey ? obj[prefixKey] : undefined;
771794
}
772795

773-
const FHIRPrimitiveTypes = [
774-
'base64Binary',
775-
'boolean',
776-
'canonical',
777-
'code',
778-
'date',
779-
'dateTime',
780-
'decimal',
781-
'id',
782-
'instant',
783-
'integer',
784-
'integer64',
785-
'markdown',
786-
'oid',
787-
'positiveInt',
788-
'string',
789-
'time',
790-
'unsignedInt',
791-
'uri',
792-
'url',
793-
'uuid',
794-
];
795-
796796
function toAnswerValue(obj: Record<any, any>, prefix: string): AnswerValue | undefined {
797797
const prefixKey = Object.keys(obj).filter((key: string) => key.startsWith(prefix))[0];
798798

0 commit comments

Comments
 (0)