Skip to content
Open
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,15 @@ export function EncounterQuestion({
});

useEffect(() => {
const isStartDateInFuture =
encounter.period.start && new Date(encounter.period.start) > new Date();
Comment thread
Jacobjeevan marked this conversation as resolved.
Outdated
Comment thread
Jacobjeevan marked this conversation as resolved.
Outdated

if (
encounter.status === EncounterStatus.DISCHARGED ||
encounter.status === EncounterStatus.COMPLETED ||
encounter.status === EncounterStatus.CANCELLED ||
encounter.status === EncounterStatus.DISCONTINUED ||
encounter.status === EncounterStatus.ENTERED_IN_ERROR
encounter.status === EncounterStatus.COMPLETED
) {
Comment thread
Jacobjeevan marked this conversation as resolved.
// Always set end date — if start is in the future, BE will reject it
if (!encounter.period.end) {
handleUpdateEncounter({
period: {
Expand All @@ -150,6 +152,28 @@ export function EncounterQuestion({
},
});
}
} else if (
encounter.status === EncounterStatus.CANCELLED ||
encounter.status === EncounterStatus.ENTERED_IN_ERROR
Comment thread
Jacobjeevan marked this conversation as resolved.
) {
if (isStartDateInFuture) {
// Valid transition from future encounters — don't set end date
if (encounter.period.end) {
handleUpdateEncounter({
period: {
...encounter.period,
end: undefined,
},
});
}
} else if (!encounter.period.end) {
handleUpdateEncounter({
period: {
...encounter.period,
end: new Date().toISOString(),
},
});
}
} else {
handleUpdateEncounter({
period: {
Expand Down
Loading