Skip to content

Commit

Permalink
Questionnaire Updates (#194)
Browse files Browse the repository at this point in the history
# Questionnaire Updates

## ♻️ Current situation & Problem
We had incorrect questionnaire ids assigned and we want questionnaire
reminders to be sent out right on sign-up.


## ⚙️ 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).
  • Loading branch information
pauljohanneskraft authored Dec 3, 2024
1 parent 3d171e9 commit dce882f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
10 changes: 5 additions & 5 deletions functions/data/questionnaires.json
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,15 @@
{
"valueCoding": {
"id": "80df26e0-55a6-4d50-90de-b60cd851c4fb",
"code": "1",
"code": "5",
"system": "urn:uuid:2b2f9a9a-e721-495a-82d6-fbc1b22a27b2",
"display": "Extremely bothersome"
}
},
{
"valueCoding": {
"id": "473f99f2-b9d2-4e92-85ed-ca78f3e0141c",
"code": "2",
"code": "4",
"system": "urn:uuid:2b2f9a9a-e721-495a-82d6-fbc1b22a27b2",
"display": "Quite a bit bothersome"
}
Expand All @@ -753,23 +753,23 @@
{
"valueCoding": {
"id": "253f487a-f26b-442f-8757-8a2401465fed",
"code": "4",
"code": "2",
"system": "urn:uuid:2b2f9a9a-e721-495a-82d6-fbc1b22a27b2",
"display": "Slightly bothersome"
}
},
{
"valueCoding": {
"id": "7de45367-76b2-4b9b-8e4e-050bae6b309c",
"code": "5",
"code": "1",
"system": "urn:uuid:2b2f9a9a-e721-495a-82d6-fbc1b22a27b2",
"display": "Not at all bothersome"
}
},
{
"valueCoding": {
"id": "3d1a8f9b-e666-4ad4-9202-571313a2b5d1",
"code": "6",
"code": "0",
"system": "urn:uuid:2b2f9a9a-e721-495a-82d6-fbc1b22a27b2",
"display": "I've had no dizziness"
}
Expand Down
16 changes: 12 additions & 4 deletions functions/src/functions/enrollUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,17 @@ describeWithEmulators('function: enrollUser', (env) => {
}

const userMessages = await env.collections.userMessages(authUser.uid).get()
expect(userMessages.docs.length).to.equal(1)
expect(userMessages.docs.at(0)?.data().type).to.equal(
UserMessageType.welcome,
)
expect(userMessages.docs.length).to.equal(2)
expect(
userMessages.docs.find(
(message) => message.data().type == UserMessageType.welcome,
),
).to.exist
expect(
userMessages.docs.find(
(message) =>
message.data().type == UserMessageType.symptomQuestionnaire,
),
).to.exist
})
})
4 changes: 2 additions & 2 deletions functions/src/services/trigger/triggerService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describeWithEmulators('TriggerService', (env) => {
const patientMessages = await env.collections
.userMessages(patientId)
.get()
expect(patientMessages.docs).to.have.length(3)
expect(patientMessages.docs).to.have.length(2)
const preAppointmentMessages = patientMessages.docs.filter(
(doc) => doc.data().type === UserMessageType.preAppointment,
)
Expand Down Expand Up @@ -133,7 +133,7 @@ describeWithEmulators('TriggerService', (env) => {
const patientMessages = await env.collections
.userMessages(patientId)
.get()
expect(patientMessages.docs).to.have.length(3)
expect(patientMessages.docs).to.have.length(2)
const preAppointmentMessages = patientMessages.docs.filter(
(doc) => doc.data().type === UserMessageType.preAppointment,
)
Expand Down
17 changes: 16 additions & 1 deletion functions/src/services/trigger/triggerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ export class TriggerService {
`TriggerService.userEnrolled(${user.id}): Adding welcome message failed due to ${String(error)}`,
)
}

try {
await this.factory.message().addMessage(
user.id,
UserMessage.createSymptomQuestionnaire({
questionnaireReference: QuestionnaireReference.enUS,
}),
{ notify: true },
)
} catch (error) {
logger.error(
`TriggerService.userEnrolled(${user.id}): Adding symptom questionnaire message failed due to ${String(error)}`,
)
}
}

async userAllergyIntoleranceWritten(userId: string): Promise<void> {
Expand Down Expand Up @@ -601,7 +615,8 @@ export class TriggerService {
)
if (
enrollmentDuration % (durationOfOneDayInMilliseconds * 14) <
durationOfOneDayInMilliseconds
durationOfOneDayInMilliseconds &&
enrollmentDuration > durationOfOneDayInMilliseconds
) {
await options.messageService.addMessage(
user.id,
Expand Down

0 comments on commit dce882f

Please sign in to comment.