Skip to content

Commit

Permalink
Resolve populate bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
fongsean committed Sep 4, 2023
1 parent 8c7ff37 commit 97257d2
Show file tree
Hide file tree
Showing 9 changed files with 71,233 additions and 4,001 deletions.
70,499 changes: 66,702 additions & 3,797 deletions apps/smart-forms-app/src/data/resources/FormsServerBundle.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

15 changes: 3 additions & 12 deletions packages/sdc-populate/src/constructResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ function getAnswerValues(
}

// Value is string at this point
if (qItem.type === 'date' && checkIsDate(value)) {
if (qItem.type === 'date' && checkIsDateTime(value)) {
return { valueDate: value };
}

Expand Down Expand Up @@ -319,24 +319,15 @@ function itemIsHidden(item: QuestionnaireItem): boolean {
);
}

/**
* Check if an answer is a date in the formats YYYY, YYYY-MM, YYYY-MM-DD
*
* @author Sean Fong
*/
export function checkIsDate(value: string): boolean {
const acceptedFormats = ['YYYY', 'YYYY-MM', 'YYYY-MM-DD'];
return dayjs(value, acceptedFormats, true).isValid();
}

/**
* Check if an answer is a datetime in the format YYYY, YYYY-MM, YYYY-MM-DD, YYYY-MM-DDThh:mm:ss+zz:zz
*
* @author Sean Fong
*/
export function checkIsDateTime(value: string): boolean {
const acceptedFormats = ['YYYY', 'YYYY-MM', 'YYYY-MM-DD', 'YYYY-MM-DDTHH:mm:ssZ'];
return moment(value, acceptedFormats, true).isValid();
const formattedDate = dayjs(value).format();
return moment(formattedDate, acceptedFormats, true).isValid();
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/sdc-populate/src/evaluateExpressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function evaluateExpressions(
}
continue;
}

initialExpressions[linkId] = initialExpression;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/sdc-populate/src/readPopulationExpressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function readPopulationExpressions(questionnaire: Questionnaire): Populat
if (!questionnaire.item) return populationExpressions;

questionnaire.item.forEach((item) => {
readQuestionnaireItem(item, populationExpressions);
readQuestionnaireItemRecursive(item, populationExpressions);
});
return populationExpressions;
}
Expand All @@ -42,15 +42,15 @@ export function readPopulationExpressions(questionnaire: Questionnaire): Populat
*
* @author Sean Fong
*/
function readQuestionnaireItem(
function readQuestionnaireItemRecursive(
item: QuestionnaireItem,
populationExpressions: PopulationExpressions
): PopulationExpressions {
const items = item.item;
if (items && items.length > 0) {
// iterate through items of item recursively
items.forEach((item) => {
readQuestionnaireItem(item, populationExpressions);
readQuestionnaireItemRecursive(item, populationExpressions);
});

// Read item population context of qGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ function DateItem(props: DateItemProps) {
// Init input value
let dateString: string | null = null;

if (qrItem?.answer && qrItem?.answer[0].valueDate) {
dateString = qrItem.answer[0].valueDate;
if (qrItem?.answer) {
if (qrItem?.answer[0].valueDate) {
dateString = qrItem.answer[0].valueDate;
} else if (qrItem?.answer[0].valueDateTime) {
dateString = qrItem.answer[0].valueDateTime;
}
}

const dateDayJs = dateString ? dayjs(dateString) : null;

// Event handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ function DateTimeItem(props: DateTimeItemProps) {

// Init input value
let dateTimeString: string | null = null;
if (qrItem?.answer && qrItem?.answer[0].valueDateTime) {
dateTimeString = qrItem.answer[0].valueDateTime;
if (qrItem?.answer) {
if (qrItem?.answer[0].valueDate) {
dateTimeString = qrItem.answer[0].valueDate;
} else if (qrItem?.answer[0].valueDateTime) {
dateTimeString = qrItem.answer[0].valueDateTime;
}
}
const dateTimeDayJs = dateTimeString ? dayjs(dateTimeString) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { GridAnswerTableCell, GridTextTableCell } from '../Tables/Table.styles';
import SingleItem from '../SingleItem/SingleItem';
import { getQrItemsIndex, mapQItemsIndex } from '../../../utils/mapItem';
import Typography from '@mui/material/Typography';
import useHidden from '../../../hooks/useHidden';

interface GridRowProps extends PropsWithQrItemChangeHandler<QuestionnaireResponseItem> {
qItem: QuestionnaireItem;
Expand All @@ -40,6 +41,11 @@ function GridRow(props: GridRowProps) {

const qItemsIndexMap = useMemo(() => mapQItemsIndex(qItem), [qItem]);

const itemIsHidden = useHidden(qItem);
if (itemIsHidden) {
return null;
}

if (!rowQItems || !rowQrItems) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
} from '../../../interfaces/renderProps.interface';
import useQuestionnaireStore from '../../../stores/useQuestionnaireStore';
import SingleItemSwitcher from './SingleItemSwitcher';
import useHidden from '../../../hooks/useHidden';

interface SingleItemProps
extends PropsWithQrItemChangeHandler<QuestionnaireResponseItem>,
Expand All @@ -48,6 +49,11 @@ function SingleItem(props: SingleItemProps) {
[updateEnableWhenItem, onQrItemChange, qItem.linkId]
);

const itemIsHidden = useHidden(qItem);
if (itemIsHidden) {
return null;
}

return (
<SingleItemSwitcher
qItem={qItem}
Expand Down

0 comments on commit 97257d2

Please sign in to comment.