Overstay Predictor Project Algorithm: Difference between revisions
Ttenbergen (talk | contribs) mNo edit summary |
Ttenbergen (talk | contribs) m Text replacement - "[[Category: " to "[[Category:" |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{LegacyContent | |||
|explanation= no more [[overstay]] | |||
|content= | |||
See \\ad.wrha.mb.ca\WRHA\HSC\shared\MED\MED_CCMED\Julie\MedProjects\LegacyByName\RodrigoVivanco for project details. | |||
<pre> | <pre> | ||
Option Compare Database | Option Compare Database | ||
Option Explicit | Option Explicit | ||
' colours used on viewer to direct collector action | ' colours used on viewer to direct collector action | ||
Public Const overstay_green = 2537789 | Public Const overstay_green = 2537789 | ||
| Line 12: | Line 14: | ||
Public Const overstay_red = 206 | Public Const overstay_red = 206 | ||
Public Const overstay_gray = -2147483633 | Public Const overstay_gray = -2147483633 | ||
' logistic regression coefficients etc | ' logistic regression coefficients etc | ||
'2013-03-20 was Const Log_Reg_threshold = 0.23 'threshold determines how many come through, .23 provided by Leigh Anne | '2013-03-20 was Const Log_Reg_threshold = 0.23 'threshold determines how many come through, .23 provided by Leigh Anne | ||
| Line 36: | Line 38: | ||
Const L_c_charlson_nh = -0.106952 | Const L_c_charlson_nh = -0.106952 | ||
Const L_c_cons = -11.23138 | Const L_c_cons = -11.23138 | ||
Public Function Transition_Coordinator_colour(Pat_ID As Long) As Long | Public Function Transition_Coordinator_colour(Pat_ID As Long) As Long | ||
On Error GoTo Err_goto | On Error GoTo Err_goto | ||
Dim colour As String | Dim colour As String | ||
Dim DOB As Date | Dim DOB As Date | ||
| Line 68: | Line 70: | ||
Dim NFE As String | Dim NFE As String | ||
Dim pt_from_PCH As String | Dim pt_from_PCH As String | ||
' if patient is transferred, msg so and be done with | ' if patient is transferred, msg so and be done with | ||
' If Not IsNull(DLookup("Pat_ID", "L_TmpV2", "Pat_ID = " & Form_View.Pat_ID & " and Project = ""Overstay"" and Item = ""Transferred form""")) Then | |||
' Transition_Coordinator_colour = overstay_gray | |||
' MsgBox "Patient transferred in from other unit, you should not update the sticker colour." | |||
GoTo | ' GoTo Exit_sub | ||
' End If | |||
' Commented out 2017-07-29 as part of Overstay changes abandoning DPST component. | |||
' | |||
' if Nursing Discharge Screen Tool indicated no discharge trouble make green be done with | |||
' NFE = NurseFormEval(Form_View.Pat_ID) | |||
' If NFE = "green" Then 'i.e. if "red" or "undefined", keep checking. | |||
' Transition_Coordinator_colour = overstay_green | |||
' GoTo Got_Colour | |||
' Else | |||
' If NFE = "undefined" Then | |||
' Transition_Coordinator_colour = overstay_gray | |||
' GoTo Got_Colour | |||
' End If | |||
' End If ' if "red" keep checking, pt can become red or yellow | |||
' check if patient comes from a ward where we collect, if so msg and make gray | |||
If DLookup("Pat_ID", "check_overstay_pt_from_our_med", "Pat_ID = " & Pat_ID) = Pat_ID Then | |||
MsgBox "Patient was admitted from ward at your site where we collect data; use the colour that was generated there. " | |||
Transition_Coordinator_colour = overstay_gray | |||
GoTo Got_Colour | |||
End If | End If | ||
' populate variables | ' populate variables | ||
DOB = CDate(Nz(Form_View.Birth, #1/1/1800#)) | DOB = CDate(Nz(Form_View.Birth, #1/1/1800#)) | ||
| Line 103: | Line 114: | ||
GoTo Got_Colour | GoTo Got_Colour | ||
End If | End If | ||
bath = adl_sc(Nz(Form_View.ADL_Bathing)) | bath = adl_sc(Nz(Form_View.ADL_Bathing)) | ||
dress = adl_sc(Nz(Form_View.ADL_Dressing)) | dress = adl_sc(Nz(Form_View.ADL_Dressing)) | ||
| Line 115: | Line 126: | ||
GoTo Exit_sub | GoTo Exit_sub | ||
End If | End If | ||
adlscore = feeding + bath + dress + toilet + transfer + continence | adlscore = feeding + bath + dress + toilet + transfer + continence | ||
pt_from_PCH = pt_is_from_PCH(Form_View.Pat_ID) | pt_from_PCH = pt_is_from_PCH(Form_View.Pat_ID) | ||
If InStr(pt_from_PCH, "undefined") > 0 Then | If InStr(pt_from_PCH, "undefined") > 0 Then ' error msg is generated in that function | ||
Transition_Coordinator_colour = overstay_gray | Transition_Coordinator_colour = overstay_gray | ||
GoTo Exit_sub | GoTo Exit_sub | ||
End If | End If | ||
from_PCH = (pt_from_PCH = "yes") | from_PCH = (pt_from_PCH = "yes") | ||
'OutsideWpg | 'OutsideWpg | ||
'OutsideWpg = transferred in from a facility outside of Winnipeg | 'OutsideWpg = transferred in from a facility outside of Winnipeg | ||
| Line 130: | Line 141: | ||
'OutsideWpg = -1 * (Mid(Form_View.R_AdmitFrom, 1, 1) = "x" Or Mid(Form_View.R_AdmitFrom, 1, 1) = "y") | 'OutsideWpg = -1 * (Mid(Form_View.R_AdmitFrom, 1, 1) = "x" Or Mid(Form_View.R_AdmitFrom, 1, 1) = "y") | ||
OutsideWpg = -1 * (Not IsNull(DLookup("Pat_ID", "check_from_out_of_town", "Pat_ID = " & Form_View.Pat_ID))) | OutsideWpg = -1 * (Not IsNull(DLookup("Pat_ID", "check_from_out_of_town", "Pat_ID = " & Form_View.Pat_ID))) | ||
If IsNull(Form_View.R_Province) Then | If IsNull(Form_View.R_Province) Then | ||
MsgBox "No ""Province"" entry found. Please enter and re-evaluate if this is not a Manitoba patient. (see http://ccmdb.kuality.ca/index.php/Overstay_Predictor_Project_Collection_Instructions)" | MsgBox "No ""Province"" entry found. Please enter and re-evaluate if this is not a Manitoba patient. (see http://ccmdb.kuality.ca/index.php/Overstay_Predictor_Project_Collection_Instructions)" | ||
| Line 137: | Line 148: | ||
End If | End If | ||
mb = ((Form_View.R_Province = "MB") * -1) | mb = ((Form_View.R_Province = "MB") * -1) | ||
If IsNull(Form_View.Ap_Eye) Or IsNull(Form_View.Ap_Verbal) Then | If IsNull(Form_View.Ap_Eye) Or IsNull(Form_View.Ap_Verbal) Then | ||
MsgBox "Can't evaluate overstay algorithm without Glasgow Coma Scale." | MsgBox "Can't evaluate overstay algorithm without Glasgow Coma Scale." | ||
| Line 146: | Line 157: | ||
verb = GCS_Verbal_pts(Form_View.Ap_Verbal) | verb = GCS_Verbal_pts(Form_View.Ap_Verbal) | ||
End If | End If | ||
adlmean_nh = adlmean_nh_function(adlscore, from_PCH) | adlmean_nh = adlmean_nh_function(adlscore, from_PCH) | ||
Adlmean_age = adlmean_age_function(adlscore, age) | Adlmean_age = adlmean_age_function(adlscore, age) | ||
Charlson_nh = Charlson_nh_function(Form_View.Pat_ID, Charlson_score_function(Form_View.Pat_ID), from_PCH) | Charlson_nh = Charlson_nh_function(Form_View.Pat_ID, Charlson_score_function(Form_View.Pat_ID), from_PCH) | ||
'2018-12-26 pre-ICD10 codes that were WRONG | |||
' mi = IIf(DCount("Charlson_category", "s_tmp_overstay_c_mi", "Pat_ID = " & Pat_ID) > 0, 1, 0) | |||
' Pulmonary = IIf(DCount("Charlson_category", "s_tmp_overstay_c_mi", "Pat_ID = " & Pat_ID) > 0, 1, 0) | |||
' Connective = IIf(DCount("Charlson_category", "s_tmp_overstay_c_mi", "Pat_ID = " & Pat_ID) > 0, 1, 0) | |||
' Renal = IIf(DCount("Charlson_category", "s_tmp_overstay_c_mi", "Pat_ID = " & Pat_ID) > 0, 1, 0) | |||
mi = IIf(Nz(DLookup("group", "L_ICD10_Charlson_component_points", "Pat_ID = " & 12687 & " and group = ""myo""")) > "", 1, 0) | |||
Pulmonary = IIf(Nz(DLookup("group", "L_ICD10_Charlson_component_points", "Pat_ID = " & 12687 & " and group = ""pulmonary""")) > "", 1, 0) | |||
Connective = IIf(Nz(DLookup("group", "L_ICD10_Charlson_component_points", "Pat_ID = " & 12687 & " and group = ""connective""")) > "", 1, 0) | |||
Renal = IIf(Nz(DLookup("group", "L_ICD10_Charlson_component_points", "Pat_ID = " & 12687 & " and group = ""renal""")) > "", 1, 0) | |||
' Dementia_AdCo = has either admit or comorbid dementia dx | ' Dementia_AdCo = has either admit or comorbid dementia dx | ||
Dementia_AdCo = -1 * (Nz(DLookup("Pat_ID", "s_tmp_overstay_Dementia_adm_como", "Pat_ID = " & Form_View.Pat_ID), 0) > 0) | Dementia_AdCo = -1 * (Nz(DLookup("Pat_ID", "s_tmp_overstay_Dementia_adm_como", "Pat_ID = " & Form_View.Pat_ID), 0) > 0) | ||
' if none of above have kicked out of function, then make sure we have data to eval the rest | ' if none of above have kicked out of function, then make sure we have data to eval the rest | ||
If bath = -1 Then | If bath = -1 Then | ||
| Line 192: | Line 209: | ||
GoTo Exit_sub | GoTo Exit_sub | ||
End If | End If | ||
Dim LRS As Double | Dim LRS As Double | ||
LRS = Log_reg_shafer(age, OutsideWpg, mb, mi, Pulmonary, Connective, Renal, _ | LRS = Log_reg_shafer(age, OutsideWpg, mb, mi, Pulmonary, Connective, Renal, _ | ||
| Line 200: | Line 217: | ||
If LRS > Log_Reg_threshold Then | If LRS > Log_Reg_threshold Then | ||
Transition_Coordinator_colour = overstay_red | Transition_Coordinator_colour = overstay_red | ||
CreateMail "Patient " & Form_View.FirstName & " " & Form_View.LastName & " has overstay color red. (EOM)" | |||
Else | Else | ||
Transition_Coordinator_colour = overstay_yellow | Transition_Coordinator_colour = overstay_yellow | ||
End If | End If | ||
Got_Colour: | Got_Colour: | ||
colour = "" | colour = "" | ||
If Transition_Coordinator_colour = overstay_red Then colour = "red" | If Transition_Coordinator_colour = overstay_red Then colour = "red" | ||
If Transition_Coordinator_colour = overstay_yellow Then colour = "yellow" | If Transition_Coordinator_colour = overstay_yellow Then colour = "yellow" | ||
If Transition_Coordinator_colour = overstay_green Then colour = "green" | If Transition_Coordinator_colour = overstay_gray Then colour = "gray" | ||
'If Transition_Coordinator_colour = overstay_green Then colour = "green" | |||
If colour > "" Then | If colour > "" Then | ||
If MsgBox("Is this the final colour you want to actually send?", vbYesNo) = vbYes Then | If MsgBox("Is this the final colour you want to actually send?", vbYesNo) = vbYes Then | ||
| Line 219: | Line 238: | ||
End If | End If | ||
End If | End If | ||
Exit_sub: | Exit_sub: | ||
Exit Function | Exit Function | ||
Err_goto: | Err_goto: | ||
MsgBox | MsgBox err.description | ||
Resume Exit_sub | Resume Exit_sub | ||
End Function | End Function | ||
Public Function Log_reg_shafer(ByVal age As Double, OutsideWpg As Integer, ByVal mb As Integer, ByVal mi As Integer, ByVal Pulmonary As Integer, ByVal Connective As Integer, ByVal Renal As Integer, ByVal _ | Public Function Log_reg_shafer(ByVal age As Double, OutsideWpg As Integer, ByVal mb As Integer, ByVal mi As Integer, ByVal Pulmonary As Integer, ByVal Connective As Integer, ByVal Renal As Integer, ByVal _ | ||
bath As Integer, ByVal dress As Integer, ByVal toilet As Integer, ByVal transfer As Integer, ByVal continence As Integer, ByVal _ | bath As Integer, ByVal dress As Integer, ByVal toilet As Integer, ByVal transfer As Integer, ByVal continence As Integer, ByVal _ | ||
Dementia_AdCo As Integer, ByVal eye As Integer, ByVal verb As Integer, ByVal adlmean_nh As Integer, ByVal Adlmean_age As Integer, ByVal Charlson_nh As Integer) As Double | Dementia_AdCo As Integer, ByVal eye As Integer, ByVal verb As Integer, ByVal adlmean_nh As Integer, ByVal Adlmean_age As Integer, ByVal Charlson_nh As Integer) As Double | ||
On Error GoTo Err_goto | On Error GoTo Err_goto | ||
| Line 257: | Line 276: | ||
L_c_adlmean_age * Adlmean_age + _ | L_c_adlmean_age * Adlmean_age + _ | ||
L_c_charlson_nh * Charlson_nh | L_c_charlson_nh * Charlson_nh | ||
probability = Exp(sum) / (1 + Exp(sum)) | probability = Exp(sum) / (1 + Exp(sum)) | ||
Log_reg_shafer = probability | Log_reg_shafer = probability | ||
Exit_sub: | Exit_sub: | ||
Exit Function | Exit Function | ||
Err_goto: | Err_goto: | ||
MsgBox | MsgBox err.description | ||
Resume Exit_sub | Resume Exit_sub | ||
End Function | End Function | ||
Public Function NurseFormEval(ByVal Pat_ID As Long) As String | ' Commented out 2017-07-29 as part of Overstay changes abandoning DPST component. | ||
On Error GoTo Err_goto | ' | ||
'Public Function NurseFormEval(ByVal Pat_ID As Long) As String | |||
'On Error GoTo Err_goto | |||
' | |||
' Dim r As Recordset | |||
' Dim has_positive As Boolean | |||
' Dim q(6) As Integer | |||
' Dim i As Integer | |||
' | |||
' has_positive = False | |||
' | |||
' ' if exists "form data missing" consider as if there was at least one "no" | |||
' If Not IsNull(DLookup("Pat_ID", "L_TmpV2", "Pat_ID = " & Form_View.Pat_ID & " and Project = ""Overstay"" and Item = ""DPST data missing""")) Then | |||
' NurseFormEval = "red" | |||
' MsgBox """DPST data missing"" variable set, form will be evaluated as requiring assistance. " | |||
' GoTo Exit_sub | |||
' End If | |||
' | |||
' Set r = CurrentDb.OpenRecordset("Select * from s_tmp_overstay_nurseForm where Pat_ID = " & Pat_ID, , dbReadOnly) | |||
' | |||
' If r.RecordCount <> 6 Then | |||
' NurseFormEval = "undefined" | |||
' MsgBox "For each of the 6 questions you must either enter a specific answer, or a ""Form Data Missing"" entry. You don't have the correct number of entries. " | |||
' GoTo Exit_sub | |||
' End If | |||
' | |||
' r.MoveFirst | |||
' | |||
' For i = 1 To 6 | |||
' q(i) = 1 ' non-boolean to express not-set, i.e. default | |||
' Next | |||
' | |||
' 'get data into variable "q" | |||
' While Not r.EOF | |||
' If IsNumeric(Mid(r(1), 1, 1)) Then | |||
' q(Mid(r(1), 1, 1)) = r(2) | |||
' End If | |||
' r.MoveNext | |||
' Wend | |||
' | |||
' ' iterate through q and validate colour | |||
' ' check that there are entries for each and that none are positive | |||
' For i = 1 To 6 | |||
' Select Case q(i) | |||
' Case 1 ' no answer | |||
' MsgBox "Overstay question " & i & " was not filled in and ""Form Data Missing"" wasn't either; fill in one or the other to be able to evaluate colour." | |||
' NurseFormEval = "undefined" | |||
' GoTo Exit_sub | |||
' Case 0 ' answer is unchecked-"patient not OK", calling function will use Rodrigo's algorithm to get colour | |||
' NurseFormEval = "red" | |||
' GoTo Exit_sub | |||
' Case -1 ' answer is checked-"patient OK" | |||
' NurseFormEval = "green" | |||
' ' keep cycling through q, see if next has non-green | |||
' Case Else ' should never happen | |||
' MsgBox "Error in Function NurseFormEval, talk to Tina." | |||
' NurseFormEval = "undefined" | |||
' GoTo Exit_sub | |||
' End Select | |||
' Next | |||
' | |||
Exit_sub: | ' Set r = Nothing | ||
' | |||
'Exit_sub: | |||
Err_goto: | ' Exit Function | ||
' | |||
'Err_goto: | |||
End Function | ' MsgBox Err.Description | ||
' Resume Exit_sub | |||
'End Function | |||
Public Function pt_is_from_PCH(Pat_ID) As String 'returns "yes", "no" or "undefined - <explanation>" | Public Function pt_is_from_PCH(Pat_ID) As String 'returns "yes", "no" or "undefined - <explanation>" | ||
On Error GoTo Err_goto | On Error GoTo Err_goto | ||
' ensure necessary data entered to evaluate "from Nursing home" | ' ensure necessary data entered to evaluate "from Nursing home" | ||
Dim nr_of_froms As Integer | Dim nr_of_froms As Integer | ||
Dim Pre_Acute_Living_Situation As Variant 'to allow null | Dim Pre_Acute_Living_Situation As Variant 'to allow null | ||
Pre_Acute_Living_Situation = DLookup("pre_acute_living_situation", "check_pt_from_pch", "Pat_ID = " & Pat_ID) | Pre_Acute_Living_Situation = DLookup("pre_acute_living_situation", "check_pt_from_pch", "Pat_ID = " & Pat_ID) | ||
If IsNull(Pre_Acute_Living_Situation) Then | If IsNull(Pre_Acute_Living_Situation) Then | ||
MsgBox "Overstay Pre-acute Living Situation: The field is empty, needs to be entered before Overstay Colour can be generated. (see http://ccmdb.kuality.ca/index.php/Overstay_Predictor_Project_Collection_Instructions#admitted_from)" | MsgBox "Overstay Pre-acute Living Situation: The field is empty, needs to be entered before Overstay Colour can be generated. (see http://ccmdb.kuality.ca/index.php/Overstay_Predictor_Project_Collection_Instructions#admitted_from)" | ||
| Line 356: | Line 377: | ||
GoTo Exit_sub | GoTo Exit_sub | ||
End If | End If | ||
If Pre_Acute_Living_Situation = "location missing/unknown" Then | If Pre_Acute_Living_Situation = "location missing/unknown" Then | ||
MsgBox "Overstay Pre-acute Living Situation: The field is ""location missing/unknown""if info is available please enter and re-evaluate colour. (see http://ccmdb.kuality.ca/index.php/Overstay_Predictor_Project_Collection_Instructions#admitted_from)" | MsgBox "Overstay Pre-acute Living Situation: The field is ""location missing/unknown""if info is available please enter and re-evaluate colour. (see http://ccmdb.kuality.ca/index.php/Overstay_Predictor_Project_Collection_Instructions#admitted_from)" | ||
| Line 362: | Line 383: | ||
GoTo Exit_sub | GoTo Exit_sub | ||
End If | End If | ||
If (Pre_Acute_Living_Situation = "Personal Care Home") Or (Pre_Acute_Living_Situation = "Chronic Health Facility") Then | If (Pre_Acute_Living_Situation = "Personal Care Home") Or (Pre_Acute_Living_Situation = "Chronic Health Facility") Then | ||
pt_is_from_PCH = "Yes" | pt_is_from_PCH = "Yes" | ||
| Line 368: | Line 389: | ||
pt_is_from_PCH = "No" | pt_is_from_PCH = "No" | ||
End If | End If | ||
Exit_sub: | Exit_sub: | ||
Exit Function | Exit Function | ||
Err_goto: | Err_goto: | ||
MsgBox | MsgBox err.description | ||
Resume Exit_sub | Resume Exit_sub | ||
End Function | End Function | ||
Public Function adlmean_nh_function(adlscore As Integer, from_PCH As Boolean) As Integer | Public Function adlmean_nh_function(adlscore As Integer, from_PCH As Boolean) As Integer | ||
On Error GoTo Err_goto | On Error GoTo Err_goto | ||
| Line 387: | Line 408: | ||
Exit Function | Exit Function | ||
Err_goto: | Err_goto: | ||
MsgBox | MsgBox err.description | ||
Resume Exit_sub | Resume Exit_sub | ||
End Function | End Function | ||
Public Function adlmean_age_function(adlscore As Integer, age As Double) As Integer | Public Function adlmean_age_function(adlscore As Integer, age As Double) As Integer | ||
On Error GoTo Err_goto | On Error GoTo Err_goto | ||
| Line 400: | Line 421: | ||
Exit Function | Exit Function | ||
Err_goto: | Err_goto: | ||
MsgBox | MsgBox err.description | ||
Resume Exit_sub | Resume Exit_sub | ||
End Function | End Function | ||
Public Function Charlson_nh_function(Pat_ID As Long, charlsonscore As Integer, from_PCH As Boolean) As Integer | Public Function Charlson_nh_function(Pat_ID As Long, charlsonscore As Integer, from_PCH As Boolean) As Integer | ||
| Line 414: | Line 435: | ||
Exit Function | Exit Function | ||
Err_goto: | Err_goto: | ||
MsgBox | MsgBox err.description | ||
Resume Exit_sub | Resume Exit_sub | ||
End Function | End Function | ||
</pre> | </pre> | ||
| Line 424: | Line 445: | ||
The fact that a patient is from a nursing home is a factor in some of the parameters above (adlmean_nh = -0.0875967 and charlson_nh = -0.106952) but both are relatively minor factors. | The fact that a patient is from a nursing home is a factor in some of the parameters above (adlmean_nh = -0.0875967 and charlson_nh = -0.106952) but both are relatively minor factors. | ||
=== | === [[Palliative patients]] can be red === | ||
None of these are factors in the equation. [[DC Treatment]] isn't related at all because it's only collected in critical care. | None of these are factors in the equation. [[DC Treatment]] isn't related at all because it's only collected in critical care. | ||
}} | |||
[[Category: OverstayProject]] | [[Category:OverstayProject]] | ||