-
Notifications
You must be signed in to change notification settings - Fork 74
Show statin nudge for 90 calendar days and recalculate cvd risk after 90 days #5185
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
Conversation
f57b392 to
78d9ff4
Compare
68242a4 to
61c7e6b
Compare
61c7e6b to
be8a96f
Compare
be8a96f to
7371b6b
Compare
Update refer text for cvd risk min value greater than or equal to 10
a610ed4 to
43d9b55
Compare
| dao.saveRisk(cvdRisk) | ||
| } | ||
|
|
||
| fun save(cvdRisk: CVDRisk, updateTime: Instant) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the name consistent with the data, rename to updatedAt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
|
||
| val wasCVDCalculatedWithin90Days = cvdRisk.timestamps.updatedAt > ninetyDaysAgo | ||
|
|
||
| val patientAttribute = patientAttributeRepository.getPatientAttributeImmediate(patientUuid = patient.uuid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirming, if the patient attribute changes, don't we have to recalculate or load the info again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, patient attribute only change when BMI is added, and we have a event to handle this case. So we don't need to observe this situation
| import androidx.room.RawQuery | ||
| import androidx.sqlite.db.SimpleSQLiteQuery | ||
| import io.reactivex.Flowable | ||
| import io.reactivex.Observable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| medicalHistoryRepository.hasMedicalHistoryForPatientChangedSince( | ||
| patientUuid = patient.uuid, | ||
| instant = cvdRisk?.timestamps?.updatedAt ?: today, | ||
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am just thinking, can't we just place a observable to get medical history for patient and then compare the updatedAt time with the CVD risk created time if it's not null in the update function?
Do we need another query to do this? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. Sounds really good and implemented that
| .atStartOfDay(userClock.zone) | ||
| .toInstant() | ||
| val wasBPMeasuredWithin90Days = newestBp.firstOrNull()?.updatedAt?.let { updatedAt -> | ||
| updatedAt > ninetyDaysAgo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According the naming semantics shouldn't the condition be updatedAt < ninetyDaysAgo? Only then it would be true, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, i think it should be the way it has been done. We need the BP to be calculated after the ninety day time. So updatedAt has to greater than ninetyDayAgo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's why I was mentioning that condition. This variable will be false if the BP is measured with in 90 days right? Unless I misunderstand it.
So shouldn't the variable name be isBPMeasuredMoreThan90DaysAgo or the condition needs to be <, no?
| } ?: false | ||
|
|
||
| val wasCVDCalculatedWithin90Days = cvdRisk?.let { risk -> | ||
| risk.timestamps.updatedAt > ninetyDaysAgo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above regarding the condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above
| var risk: CVDRiskRange? = null | ||
|
|
||
| if (bloodPressure != null) { | ||
| risk = cvdRiskCalculator.calculateCvdRisk( | ||
| CVDRiskInput( | ||
| gender = patient.gender, | ||
| age = patient.ageDetails.estimateAge(userClock), | ||
| systolic = bloodPressure.reading.systolic, | ||
| isSmoker = medicalHistory.isSmoking, | ||
| bmi = patientAttribute?.bmiReading?.calculateBMI(), | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| if (risk != null) { | ||
| val existingCvdRisk = cvdRiskRepository.getCVDRiskImmediate(patient.uuid) | ||
| if (existingCvdRisk != null) { | ||
| cvdRiskRepository.save( | ||
| existingCvdRisk.copy(riskScore = risk), | ||
| updateTime = Instant.now(clock) | ||
| ) | ||
| } else { | ||
| cvdRiskRepository.save( | ||
| riskScore = risk, | ||
| patientUuid = patient.uuid, | ||
| uuid = uuidGenerator.v4() | ||
| ) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these conditions should be part of the effect handler, Update function should make the decision on whether to update or create a new one and trigger respective side effects. Please make that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we are technically doing 2 separate side effects here. We are calculating the risk and also saving/updating them right there. Calculating them and modifying them are 2 separate actions. We can break them down accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Broke this into new events and effects
| if (event.cvdRiskRange == null || | ||
| event.hasMedicalHistoryChanged || | ||
| !event.wasCVDCalculatedWithin90Days) { | ||
| dispatch(CalculateCVDRisk(model.patientSummaryProfile!!.patient)) | ||
| } else { | ||
| dispatch(LoadStatinInfo(model.patientUuid)) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nested conditional, let's break it down
| IntOffset( | ||
| x = clampedOffsetX.toInt(), | ||
| y = 0 | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check code styling once? Diff shows whitespaces being added here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| is StatinPrescriptionCheckInfoLoaded -> statinPrescriptionCheckInfoLoaded(event, model) | ||
| is CVDRiskCalculated -> dispatch(LoadStatinInfo(model.patientUuid)) | ||
| is CVDRiskCalculated -> saveOrUpdateCVDRisk(event, model) | ||
| is CVDRiskUpdated -> dispatch(LoadStatinInfo(model.patientUuid)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the reason why I thought we can use a observable stream for CVD risk, since that will load the statin info automatically without having to call it manually everytime it's updated or saved.
You can make this change later though
https://app.shortcut.com/simpledotorg/story/14495/statin-nudge-v2-android-engineering-discussions?team_id=1&iteration_ids=14465