Skip to content

Commit

Permalink
Schedule Appointment Reminders only daily (#183)
Browse files Browse the repository at this point in the history
# Schedule Appointment Reminders only daily

## ♻️ Current situation & Problem
*Link any open issues or pull requests (PRs) related to this PR. Please
ensure that all non-trivial PRs are first tracked and discussed in an
existing GitHub issue or discussion.*


## ⚙️ Release Notes 
*Add a bullet point list summary of the feature and possible migration
guides if this is a breaking change so this section can be added to the
release notes.*
*Include code snippets that provide examples of the feature implemented
or links to the documentation if it appends or changes the public
interface.*


## 📚 Documentation
*Please ensure that you properly document any additions in conformance
to [Spezi Documentation
Guide](https://github.com/StanfordSpezi/.github/blob/main/DOCUMENTATIONGUIDE.md).*
*You can use this section to describe your solution, but we encourage
contributors to document your reasoning and changes using in-line
documentation.*


## ✅ Testing
*Please ensure that the PR meets the testing requirements set by CodeCov
and that new functionality is appropriately tested.*
*This section describes important information about the tests and why
some elements might not be testable.*


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).

---------

Co-authored-by: Paul Schmiedmayer <PSchmiedmayer@users.noreply.github.com>
  • Loading branch information
pauljohanneskraft and PSchmiedmayer authored Nov 12, 2024
1 parent 00466c8 commit 1d106bb
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 195 deletions.
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

0 comments on commit 1d106bb

Please sign in to comment.