Skip to content

Commit

Permalink
Make tsconfig more strict
Browse files Browse the repository at this point in the history
  • Loading branch information
fongsean committed Sep 11, 2024
1 parent 89bff2a commit 527b745
Show file tree
Hide file tree
Showing 70 changed files with 581 additions and 468 deletions.
22 changes: 0 additions & 22 deletions apps/smart-forms-app/src/utils/qrItem.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function AttachmentItem(props: AttachmentItemProps) {
const readOnly = useReadOnly(qItem, parentIsReadOnly);

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
let valueString = '';
if (qrItem?.answer && qrItem?.answer[0].valueString) {
if (qrItem?.answer && qrItem?.answer[0]?.valueString) {
valueString = qrItem.answer[0].valueString;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function BooleanItem(props: BooleanItemProps) {
const readOnly = useReadOnly(qItem, parentIsReadOnly);

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
let valueBoolean: boolean | undefined = undefined;
if (qrItem?.answer?.[0]?.valueBoolean !== undefined) {
valueBoolean = qrItem.answer[0].valueBoolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ function ChoiceAutocompleteItem(props: ChoiceAutocompleteItemProps) {
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrChoice = qrItem ?? createEmptyQrItem(qItem, answerKey);

let valueCoding: Coding | undefined;
if (qrChoice.answer) {
valueCoding = qrChoice.answer[0].valueCoding;
valueCoding = qrChoice.answer[0]?.valueCoding;
}

const readOnly = useReadOnly(qItem, parentIsReadOnly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function ChoiceCheckboxAnswerOptionItem(props: ChoiceCheckboxAnswerOptionItemPro
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrChoiceCheckbox = qrItem ?? createEmptyQrItem(qItem, answerKey);
const answers = qrChoiceCheckbox.answer ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function ChoiceCheckboxAnswerValueSetItem(props: ChoiceCheckboxAnswerValueSetIte
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrChoiceCheckbox = qrItem ?? createEmptyQrItem(qItem, answerKey);
const answers = qrChoiceCheckbox.answer ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function ChoiceRadioAnswerOptionItem(props: ChoiceRadioAnswerOptionItemProps) {
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrChoice = qrItem ?? createEmptyQrItem(qItem, answerKey);
const valueChoice = getQrChoiceValue(qrChoice);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ function ChoiceRadioAnswerValueSetItem(props: ChoiceRadioAnswerValueSetItemProps
const readOnly = useReadOnly(qItem, parentIsReadOnly);

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrChoiceRadio = qrItem ?? createEmptyQrItem(qItem, answerKey);

let valueRadio: string | null = null;
if (qrChoiceRadio.answer) {
valueRadio = qrChoiceRadio.answer[0].valueCoding?.code ?? null;
valueRadio = qrChoiceRadio.answer[0]?.valueCoding?.code ?? null;
}

// Get codings/options from valueSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function ChoiceSelectAnswerOptionItem(props: ChoiceSelectAnswerOptionItemProps)
const readOnly = useReadOnly(qItem, parentIsReadOnly);

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrChoice = qrItem ?? createEmptyQrItem(qItem, answerKey);
const valueChoice = getQrChoiceValue(qrChoice);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ function ChoiceSelectAnswerValueSetItem(props: ChoiceSelectAnswerValueSetItemPro
const readOnly = useReadOnly(qItem, parentIsReadOnly);

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrChoiceSelect = qrItem ?? createEmptyQrItem(qItem, answerKey);

let valueCoding: Coding | null = null;
if (qrChoiceSelect.answer) {
valueCoding = qrChoiceSelect.answer[0].valueCoding ?? null;
valueCoding = qrChoiceSelect.answer[0]?.valueCoding ?? null;
}

// Get codings/options from valueSet
Expand All @@ -74,7 +74,7 @@ function ChoiceSelectAnswerValueSetItem(props: ChoiceSelectAnswerValueSetItemPro
// but will fail if answer provided is not within options
useEffect(
() => {
if (qrChoiceSelect.answer && qrChoiceSelect.answer[0].valueString) {
if (qrChoiceSelect.answer && qrChoiceSelect.answer[0]?.valueString) {
onQrItemChange(createEmptyQrItem(qItem, answerKey));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ function CustomDateItem(props: CustomDateItemProps) {
const { displayPrompt, entryFormat } = useRenderingExtensions(qItem);

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrDate = qrItem ?? createEmptyQrItem(qItem, answerKey);

let valueDate: string = '';
if (qrDate.answer) {
if (qrDate.answer[0].valueDate) {
if (qrDate.answer[0]?.valueDate) {
valueDate = qrDate.answer[0].valueDate;
} else if (qrDate.answer[0].valueDateTime) {
} else if (qrDate.answer[0]?.valueDateTime) {
valueDate = qrDate.answer[0].valueDateTime;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ function CustomDateTimeItem(props: CustomDateTimeItemProps) {
const { displayPrompt, entryFormat } = useRenderingExtensions(qItem);

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrDateTime = qrItem ?? createEmptyQrItem(qItem, answerKey);

let valueDate: string = '';
let dateTimeDayJs: Dayjs | null = null;
if (qrDateTime.answer) {
let tempDateTime = '';
if (qrDateTime.answer[0].valueDate) {
tempDateTime = qrDateTime.answer[0].valueDate;
} else if (qrDateTime.answer[0].valueDateTime) {
tempDateTime = qrDateTime.answer[0].valueDateTime;
if (qrDateTime.answer[0]?.valueDate) {
tempDateTime = qrDateTime.answer[0]?.valueDate;
} else if (qrDateTime.answer[0]?.valueDateTime) {
tempDateTime = qrDateTime.answer[0]?.valueDateTime;
}

// split date and time at "T", 2015-02-07T13:28:17-05:00
if (tempDateTime.includes('T')) {
valueDate = tempDateTime.split('T')[0];
valueDate = tempDateTime.split('T')[0] ?? '';
dateTimeDayJs = dayjs(tempDateTime);
} else {
valueDate = tempDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export function validateDateInput(input: string) {
return false;
}

if (!matches[1] || !matches[2]) {
return false;
}

// Handle MM/YYYY format
if (matches.length === 2) {
return validateTwoMatches(matches[0], matches[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function getTimeSegments(timeInput: string): {
return { hourSegment: null, minuteSegment: null };
}

return { hourSegment: timeInputSegments[0], minuteSegment: timeInputSegments[1] };
return { hourSegment: timeInputSegments[0] ?? null, minuteSegment: timeInputSegments[1] ?? null };
}

export function validateTimeInput(
Expand Down Expand Up @@ -102,7 +102,7 @@ export function parseDateTimeToDisplayTime(dateTime: Dayjs | null): {

function convertTo12HourFormat(timeInput: string) {
const timeSegments = timeInput.split(':');
const hour = parseInt(timeSegments[0], 10);
const hour = parseInt(timeSegments[0] ?? '', 10) || 0;
if (hour >= 12) {
timeSegments[0] = `${hour - 12}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ function DecimalItem(props: DecimalItemProps) {
const { displayUnit, displayPrompt, entryFormat } = useRenderingExtensions(qItem);

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
let valueDecimal = 0.0;
let initialInput = '';
if (qrItem?.answer) {
if (qrItem?.answer[0].valueDecimal) {
if (qrItem?.answer[0]?.valueDecimal) {
valueDecimal = qrItem.answer[0].valueDecimal;
}

if (qrItem?.answer[0].valueInteger) {
if (qrItem?.answer[0]?.valueInteger) {
valueDecimal = qrItem.answer[0].valueInteger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function GridGroup(props: GridGroupProps) {
const qItemsIndexMap = useMemo(() => mapQItemsIndex(qItem), [qItem]);

const columnLabels: string[] = useMemo(
() => qRowItems?.[0].item?.map((firstItem) => firstItem.text ?? ' ') ?? [],
() => qRowItems?.[0]?.item?.map((firstItem) => firstItem.text ?? ' ') ?? [],
[qRowItems]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ function IntegerItem(props: IntegerItemProps) {
const { displayUnit, displayPrompt, entryFormat } = useRenderingExtensions(qItem);

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
let valueInteger = 0;
let initialInput = '';
if (qrItem?.answer) {
if (qrItem?.answer[0].valueInteger) {
if (qrItem?.answer[0]?.valueInteger) {
valueInteger = qrItem.answer[0].valueInteger;
}

if (qrItem?.answer[0].valueDecimal) {
if (qrItem?.answer[0]?.valueDecimal) {
valueInteger = Math.round(qrItem.answer[0].valueDecimal);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ function OpenChoiceAutocompleteItem(props: OpenChoiceAutocompleteItemProps) {

const readOnly = useReadOnly(qItem, parentIsReadOnly);

const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrOpenChoice = qrItem ?? createEmptyQrItem(qItem, answerKey);

// Init input value
let valueAutocomplete: Coding | string | undefined;
if (qrOpenChoice.answer) {
const answer = qrOpenChoice.answer[0];
valueAutocomplete = answer.valueCoding ? answer.valueCoding : answer.valueString;
valueAutocomplete = answer?.valueCoding ? answer.valueCoding : answer?.valueString;
}

if (!valueAutocomplete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function OpenChoiceCheckboxAnswerOptionItem(props: OpenChoiceCheckboxAnswerOptio
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrOpenChoiceCheckbox = qrItem ?? createEmptyQrItem(qItem, answerKey);
const answers = qrOpenChoiceCheckbox.answer ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function OpenChoiceCheckboxAnswerValueSetItem(props: OpenChoiceCheckboxAnswerVal
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrOpenChoiceCheckbox = qrItem ?? createEmptyQrItem(qItem, answerKey);
const answers = qrOpenChoiceCheckbox.answer ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function OpenChoiceRadioAnswerOptionItem(props: OpenChoiceRadioAnswerOptionItemP
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();

// Init answers
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrOpenChoiceRadio = qrItem ?? createEmptyQrItem(qItem, answerKey);
let valueRadio: string | null = getQrChoiceValue(qrOpenChoiceRadio, true);
const answers = qrOpenChoiceRadio.answer ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function OpenChoiceRadioAnswerValueSetItem(props: OpenChoiceRadioAnswerValueSetI
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();

// Init answers
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrOpenChoiceRadio = qrItem ?? createEmptyQrItem(qItem, answerKey);
let valueRadio: string | null = getQrChoiceValue(qrOpenChoiceRadio, true);
const answers = qrOpenChoiceRadio.answer ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function OpenChoiceSelectAnswerOptionItem(props: OpenChoiceSelectAnswerOptionIte
const readOnly = useReadOnly(qItem, parentIsReadOnly);

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const answerOptions = qItem.answerOption;
if (!answerOptions) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ function OpenChoiceSelectAnswerValueSetItem(props: OpenChoiceSelectAnswerValueSe
const readOnly = useReadOnly(qItem, parentIsReadOnly);

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
const qrOpenChoice = qrItem ?? createEmptyQrItem(qItem, answerKey);

let valueSelect: Coding | null = null;
if (qrOpenChoice['answer']) {
valueSelect = qrOpenChoice['answer'][0].valueCoding ?? null;
valueSelect = qrOpenChoice['answer'][0]?.valueCoding ?? null;
}

// Get codings/options from valueSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ function QuantityItem(props: QuantityItemProps) {
);

// Init inputs
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
let valueQuantity: Quantity = {};
let initialValueInput = '';
let initialComparatorInput: Quantity['comparator'] | null = null;
let initialUnitInput: QuestionnaireItemAnswerOption | null =
quantityUnit ?? unitOptions?.at(0) ?? null;
if (qrItem?.answer) {
if (qrItem?.answer[0].valueQuantity) {
if (qrItem?.answer[0]?.valueQuantity) {
valueQuantity = qrItem.answer[0].valueQuantity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ function RepeatGroup(props: RepeatGroupProps) {
function handleAnswerChange(newQrItem: QuestionnaireResponseItem, index: number) {
const updatedRepeatGroups = [...repeatGroups];

if (newQrItem.item) {
updatedRepeatGroups[index].qrItem = {
const updatedRepeatGroup = updatedRepeatGroups[index];
if (newQrItem.item && updatedRepeatGroup) {
updatedRepeatGroup.qrItem = {
linkId: newQrItem.linkId,
text: newQrItem.text,
item: newQrItem.item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function RepeatItem(props: RepeatItemProps) {
// Event Handlers
function handleAnswerChange(newQrItem: QuestionnaireResponseItem, index: number) {
const updatedRepeatAnswers = [...repeatAnswers];
updatedRepeatAnswers[index] = newQrItem.answer ? newQrItem.answer[0] : null;
updatedRepeatAnswers[index] = newQrItem.answer ? newQrItem.answer[0] ?? null : null;

onQrItemChange({
...createEmptyQrItem(qItem, undefined),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ function SliderItem(props: SliderItemProps) {
const isInteracted = !!qrItem?.answer;

// Init input value
const answerKey = qrItem?.answer?.[0].id;
const answerKey = qrItem?.answer?.[0]?.id;
let valueInteger = 0;
if (qrItem?.answer) {
if (qrItem?.answer[0].valueInteger) {
if (qrItem?.answer[0]?.valueInteger) {
valueInteger = qrItem.answer[0].valueInteger;
}
if (qrItem?.answer[0].valueDecimal) {
if (qrItem?.answer[0]?.valueDecimal) {
valueInteger = Math.round(qrItem.answer[0].valueDecimal);
}
}
Expand Down
Loading

0 comments on commit 527b745

Please sign in to comment.