Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

MAT-7662: Ignore partial dateTime entries by checking MUI validation results. #720

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions src/components/common/dateTimeInput/DateTimeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@

dayjs.extend(utc);
dayjs.utc();

export const getCQLDateTime = (value, first = false) => {
const newDateTime = first ? dayjs(value) : dayjs.utc(value);
/**
* Converts dayjs value to CQL DateTime.
* @param value dayjs representation of the user entered dateTime.
* @param wasNull Indicates whether previous value was null. Going from null to a value,
* use the dayjs value as opposed to making it utc, so it's relative to the local time.
*/
export const getCQLDateTime = (value, wasNull = false) => {
if (!value) {
// Clears out a populated field.
return null;
}
const newDateTime = wasNull ? dayjs(value) : dayjs.utc(value);
const newCQLDateTime: CQL.DateTime = new CQL.DateTime(
newDateTime.year(),
newDateTime.month() + 1,
Expand Down Expand Up @@ -51,19 +60,13 @@
canEdit,
attributeName,
}: DateTimeInputProps) => {
const handleDateTimeChange = (newValue) => {
for (const prop in newValue) {
if (Number.isNaN(newValue[prop])) {
onDateTimeChange(null, attributeName);
return;
}
}
if (newValue) {
onDateTimeChange(
getCQLDateTime(newValue, dateTime ? false : true),
attributeName
);
const handleDateTimeChange = (newValue, context) => {
// Use MUI validation to identify complete dateTime entry.
if (context?.validationError === "invalidDate") {
// Partial dateTime entry.
return;

Check warning on line 67 in src/components/common/dateTimeInput/DateTimeInput.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/common/dateTimeInput/DateTimeInput.tsx#L67

Added line #L67 was not covered by tests
}
onDateTimeChange(getCQLDateTime(newValue, !dateTime), attributeName);
};
return (
<DateTimeField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const DemographicsSection = ({ canEdit }) => {
}
};

const handleTimeChange = (val) => {
const handleDateTimeChange = (val) => {
const formatted = dayjs.utc(val).format();
const existingElement = getDataElementByStatus("birthdate", patient);
const newTimeElement = getBirthDateElement(formatted, existingElement);
Expand Down Expand Up @@ -227,7 +227,7 @@ const DemographicsSection = ({ canEdit }) => {
}
attributeName="DateTime"
onDateTimeChange={(newValue) => {
handleTimeChange(newValue);
handleDateTimeChange(newValue);
}}
/>
<FormControl>
Expand Down
Loading