Skip to content

Commit

Permalink
Merge pull request #535 from anantmittal/recent-cutoff-date-undefined
Browse files Browse the repository at this point in the history
Allow Recent Entry Cutoff to be Undefined
  • Loading branch information
jayfo authored Aug 12, 2024
2 parents ece2411 + 981206e commit 9066a23
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 29 deletions.
4 changes: 2 additions & 2 deletions web_registry/src/components/common/ContentsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface IContentItem {
export interface IContentsMenuProps {
contents: IContentItem[];
contentId: string;
recentEntryCutoffDateTime: Date;
recentEntryCutoffDateTime: Date | undefined;
recentEntryBadgeContent: React.ReactNode;
}

Expand Down Expand Up @@ -243,7 +243,7 @@ export const ContentsMenu: FunctionComponent<IContentsMenuProps> = observer(
<TitleContainer>
<Stack direction={"column"}>
<Typography>CONTENTS</Typography>
{!!recentEntryBadgeContent && (
{!!recentEntryCutoffDateTime && !!recentEntryBadgeContent && (
<FormHelperText>
New Since:
<br />
Expand Down
104 changes: 77 additions & 27 deletions web_registry/src/stores/PatientStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { differenceInYears, subDays } from "date-fns";
import { differenceInYears } from "date-fns";
import { action, computed, makeAutoObservable, toJS } from "mobx";
import {
behavioralActivationChecklistValues,
Expand Down Expand Up @@ -60,7 +60,7 @@ export interface IPatientStore extends IPatient {

// Recent patient entry properties
readonly recentEntryCaseloadSummary: string | undefined;
readonly recentEntryCutoffDateTime: Date;
readonly recentEntryCutoffDateTime: Date | undefined;
readonly recentEntryActivities: IActivity[] | undefined;
readonly recentEntryActivityLogsSortedByDateAndTimeDescending:
| IActivityLog[]
Expand Down Expand Up @@ -472,27 +472,39 @@ export class PatientStore implements IPatientStore {
}

@computed get recentEntryCutoffDateTime() {
// Initially, stub the function to return now minus two weeks.
// Eventually, this will be calculated based on when a social worker marks a patient as reviewed.
let cutoffDateTime = new Date();
cutoffDateTime = subDays(cutoffDateTime, 14);

return cutoffDateTime;
return this.profile.enrollmentDate;
}

@computed get recentEntryActivities() {
if (this.activities.length === 0) {
const recentEntryCutoffDateTime = this.recentEntryCutoffDateTime;

if (this.activities.length === 0 || !recentEntryCutoffDateTime) {
return undefined;
}

const filteredActivities = this.activities.filter(
(a) => a.editedDateTime >= recentEntryCutoffDateTime,
);

if (filteredActivities.length === 0) {
return undefined;
} else {
return this.activities.filter((a) => {
return a.editedDateTime >= this.recentEntryCutoffDateTime;
});
return filteredActivities;
}
}

@computed get recentEntryActivityLogsSortedByDateAndTimeDescending() {
const recentEntryCutoffDateTime = this.recentEntryCutoffDateTime;

if (
this.activityLogsSortedByDateAndTimeDescending.length === 0 ||
!recentEntryCutoffDateTime
) {
return undefined;
}

const indexEnd = this.activityLogsSortedByDateAndTimeDescending.findIndex(
(a) => a.recordedDateTime < this.recentEntryCutoffDateTime,
(a) => a.recordedDateTime < recentEntryCutoffDateTime,
);

if (indexEnd < 0) {
Expand All @@ -505,17 +517,23 @@ export class PatientStore implements IPatientStore {
}

@computed get recentEntryAssessmentLogsSortedByDateAndTimeDescending() {
const recentEntryCutoffDateTime = this.recentEntryCutoffDateTime;

if (
this.assessmentLogsSortedByDateAndTimeDescending.length === 0 ||
!recentEntryCutoffDateTime
) {
return undefined;
}

// Assessments submitted by a provider are not considered recent
const filteredAssessmentLogs =
this.assessmentLogsSortedByDateAndTimeDescending.filter((current) => {
if (!!current.submittedByProviderId) {
return false;
}
return true;
});
this.assessmentLogsSortedByDateAndTimeDescending.filter(
(current) => !current.submittedByProviderId,
);

const indexEnd = filteredAssessmentLogs.findIndex(
(a) => a.recordedDateTime < this.recentEntryCutoffDateTime,
(a) => a.recordedDateTime < recentEntryCutoffDateTime,
);

if (indexEnd < 0) {
Expand All @@ -529,8 +547,17 @@ export class PatientStore implements IPatientStore {
}

@computed get recentEntryMoodLogsSortedByDateAndTimeDescending() {
const recentEntryCutoffDateTime = this.recentEntryCutoffDateTime;

if (
this.moodLogsSortedByDateAndTimeDescending.length === 0 ||
!recentEntryCutoffDateTime
) {
return undefined;
}

const indexEnd = this.moodLogsSortedByDateAndTimeDescending.findIndex(
(a) => a.recordedDateTime < this.recentEntryCutoffDateTime,
(a) => a.recordedDateTime < recentEntryCutoffDateTime,
);

if (indexEnd < 0) {
Expand All @@ -543,20 +570,35 @@ export class PatientStore implements IPatientStore {
}

@computed get recentEntrySafetyPlan() {
const recentEntryCutoffDateTime = this.recentEntryCutoffDateTime;

if (!recentEntryCutoffDateTime) {
return undefined;
}

// The default empty safety plan will not have a lastUpdatedDateTime
if (
!!this.safetyPlan.lastUpdatedDateTime &&
this.safetyPlan.lastUpdatedDateTime >= this.recentEntryCutoffDateTime
this.safetyPlan.lastUpdatedDateTime >= recentEntryCutoffDateTime
) {
return this.safetyPlan;
}
return undefined;
}

@computed get recentEntryScheduledActivitiesSortedByDateAndTimeDescending() {
const recentEntryCutoffDateTime = this.recentEntryCutoffDateTime;

if (
this.scheduledActivitiesSortedByDateAndTimeDescending.length === 0 ||
!recentEntryCutoffDateTime
) {
return undefined;
}

const indexEnd =
this.scheduledActivitiesSortedByDateAndTimeDescending.findIndex(
(a) => a.dueDateTime < this.recentEntryCutoffDateTime,
(a) => a.dueDateTime < recentEntryCutoffDateTime,
);

if (indexEnd < 0) {
Expand All @@ -572,12 +614,20 @@ export class PatientStore implements IPatientStore {
}

@computed get recentEntryValues() {
if (this.values.length === 0) {
const recentEntryCutoffDateTime = this.recentEntryCutoffDateTime;

if (this.values.length === 0 || !recentEntryCutoffDateTime) {
return undefined;
}

const filteredValues = this.values.filter(
(a) => a.editedDateTime >= recentEntryCutoffDateTime,
);

if (filteredValues.length === 0) {
return undefined;
} else {
return this.values.filter((a) => {
return a.editedDateTime >= this.recentEntryCutoffDateTime;
});
return filteredValues;
}
}

Expand Down
20 changes: 20 additions & 0 deletions web_shared/guards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ok as assert } from "assert";

export function assertNotNull<T>(
arg: T,
): asserts arg is Exclude<T, null | undefined> {
assert(arg !== null, "Invalid null");
}

export function assertNotUndefined<T>(
arg: T,
): asserts arg is Exclude<T, undefined> {
assert(arg !== undefined, "Invalid undefined");
}

export function assertNotNullNotUndefined<T>(
arg: T,
): asserts arg is Exclude<T, null | undefined> {
assertNotNull(arg);
assertNotUndefined(arg);
}

0 comments on commit 9066a23

Please sign in to comment.