Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule Appointment Reminders only daily #183

Merged
merged 4 commits into from
Nov 12, 2024
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
9 changes: 0 additions & 9 deletions functions/src/functions/onSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ export const onScheduleEveryMorning = onSchedule(
async () => getServiceFactory().trigger().everyMorning(),
)

export const onScheduleEvery15Minutes = onSchedule(
{
schedule: '*/15 * * * *',
timeZone: 'America/Los_Angeles',
serviceAccount: serviceAccount,
},
async () => getServiceFactory().trigger().every15Minutes(),
)

export const onScheduleUpdateMedicationRecommendations = onSchedule(
{
schedule: '0 0 * * *',
Expand Down
28 changes: 17 additions & 11 deletions functions/src/services/trigger/triggerService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { expect } from 'chai'
import { describeWithEmulators } from '../../tests/functions/testEnvironment.js'

describeWithEmulators('TriggerService', (env) => {
describe('every15Minutes', () => {
describe('everyMorning', () => {
it('should create a message for an upcoming appointment', async () => {
const ownerId = await env.createUser({
type: UserType.owner,
Expand Down Expand Up @@ -52,13 +52,17 @@ describeWithEmulators('TriggerService', (env) => {
const appointmentRef = env.collections.userAppointments(patientId).doc()
await appointmentRef.set(appointment)

await env.factory.trigger().every15Minutes()
await env.factory.trigger().everyMorning()

const patientMessages = await env.collections
.userMessages(patientId)
.get()
expect(patientMessages.docs).to.have.length(1)
const patientMessage = patientMessages.docs.at(0)?.data()
expect(patientMessages.docs).to.have.length(3)
const preAppointmentMessages = patientMessages.docs.filter(
(doc) => doc.data().type === UserMessageType.preAppointment,
)
expect(preAppointmentMessages).to.have.length(1)
const patientMessage = preAppointmentMessages.at(0)?.data()
expect(patientMessage?.type).to.equal(UserMessageType.preAppointment)
expect(patientMessage?.reference).to.equal(appointmentRef.path)
expect(patientMessage?.completionDate).to.be.undefined
Expand All @@ -70,7 +74,7 @@ describeWithEmulators('TriggerService', (env) => {
const clinicianMessage = clinicianMessages.docs.at(0)?.data()
expect(clinicianMessage?.type).to.equal(UserMessageType.preAppointment)
expect(clinicianMessage?.reference).to.equal(
patientMessages.docs.at(0)?.ref.path,
preAppointmentMessages.at(0)?.ref.path,
)
expect(clinicianMessage?.completionDate).to.be.undefined

Expand All @@ -79,7 +83,7 @@ describeWithEmulators('TriggerService', (env) => {
const ownerMessage = clinicianMessages.docs.at(0)?.data()
expect(ownerMessage?.type).to.equal(UserMessageType.preAppointment)
expect(ownerMessage?.reference).to.equal(
patientMessages.docs.at(0)?.ref.path,
preAppointmentMessages.at(0)?.ref.path,
)
expect(ownerMessage?.completionDate).to.be.undefined
})
Expand Down Expand Up @@ -124,13 +128,17 @@ describeWithEmulators('TriggerService', (env) => {
.doc()
await clinicianMessageRef.set(clinicianMessage)

await env.factory.trigger().every15Minutes()
await env.factory.trigger().everyMorning()

const patientMessages = await env.collections
.userMessages(patientId)
.get()
expect(patientMessages.docs).to.have.length(1)
const patientMessageData = patientMessages.docs.at(0)?.data()
expect(patientMessages.docs).to.have.length(3)
const preAppointmentMessages = patientMessages.docs.filter(
(doc) => doc.data().type === UserMessageType.preAppointment,
)
expect(preAppointmentMessages).to.have.length(1)
const patientMessageData = preAppointmentMessages.at(0)?.data()
expect(patientMessageData?.type).to.equal(UserMessageType.preAppointment)
expect(patientMessageData?.reference).to.equal(appointmentRef.path)
expect(patientMessageData?.completionDate).to.exist
Expand All @@ -146,9 +154,7 @@ describeWithEmulators('TriggerService', (env) => {
expect(clinicianMessageData?.reference).to.equal(patientMessageRef.path)
expect(clinicianMessageData?.completionDate).to.be.undefined // this message will need to be manually completed
})
})

describe('everyMorning', () => {
it('should create a message to remind about vitals', async () => {
const userId = await env.createUser({
type: UserType.patient,
Expand Down
Loading
Loading