maintenance: title: Maintain Advanced Visit List of patients with onset of diabetes;; mlmname: SCH_AVL_DIABETES_ONSET;; arden: version 2.5;; version: 5.50;; institution: St.Clair Hospital;; author: Debbie Eiler;; specialist: Don Warnick;; date: 2013-07-01;; validation: Testing;; library: purpose: Maintains Diabetes Onset Visit List data ;; explanation: This MLM maintains the Diabetes Onset Advanced Visit List Change history 07.01.2013 DW CSR# 31622 Created from the Potential Heart Failure Advance Visit List 10.07.2013 JL 6.1 upgrade - Corrected ambibuous code field in Health Issue query ;; keywords: ObjectsPlus, Advanced Visit List Data, Diabetes Onset ;; knowledge: type: data-driven;; data: // Advanced Visit List Item Names AVL_Name := "Potential Diabetes Onset"; AVL_External_ID := "003"; AVL_Result := "ResultValue" ; // Triggers clientvisit_modify_event := Event {ClientVisitModify BATCH ClientVisit: where typecode = "Inpatient" or typecode = "Observation"}; lab_result_enter_event := EVENT {ObservationEnter ANY Observation: WHERE Itemname matches pattern "%A1C%"}; // Destinations objects_plus_destination := destination { ObjectsPlus } with [ alert_type := "Warning", short_message := "Object created by MLM", priority := "low", scope := "chart", rule_group := "Advanced Visit List Data Object", rule_number := 2010]; send_alert := "DoNotSend"; alert_dest := destination { Alert: warning, "Order Session Type", high, chart, "Order Session Type", 15042, send_alert, "No Override Allowed" }; standard_libs := MLM {{{SINGLE-QUOTE}}}std_include_libs{{{SINGLE-QUOTE}}}; include standard_libs; if called_by_editor then EvokingObject := read last {HealthIssue: THIS }; endif; // DETERMINE IF PROCESSING SHOULD CONTINUE SECTION If EvokingEventType = lab_result_enter_event.type then evokevent := "Lab Event"; (VisitGUID, ChartGUID, ClientGUID) := read last { Observation: ClientVisitGUID, ChartGUID, ClientGUID REFERENCING EvokingObject }; endif; IF EvokingEventType = clientvisit_modify_event.type then evokevent := "Change to Inpatient Event"; (VisitGUID, ChartGUID, ClientGUID) := read last {ClientVisit: GUID, ChartGUID, ClientGUID REFERENCING EvokingObject}; endif; PatientType := read last {"select typecode from CV3ClientVisit with (nolock) where typecode in ({{{SINGLE-QUOTE}}}inpatient{{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}observation{{{SINGLE-QUOTE}}}) and ClientGUID = " || ClientGUID || " and ChartGUID = " || ChartGUID || " and guid = " || VisitGUID || " "}; (Lab_Value, abnormalitycode, ArrivalDtm) := read last {"select bo.value, bo.abnormalitycode, convert(varchar(10), bo.ArrivalDtm,101) from cv3order o with (nolock) join cv3basicobservation as bo with (nolock) on bo.ClientGUID = o.ClientGUID and bo.ChartGUID = o.ChartGUID and bo.clientvisitguid = o.clientvisitguid and bo.orderguid = o.guid and bo.ishistory = 0 where o.ClientGUID = " || ClientGUID || " and o.ChartGUID = " || ChartGUID || " and o.clientvisitguid = " || VisitGUID || " and o.name = {{{SINGLE-QUOTE}}}Hemoglobin A1C{{{SINGLE-QUOTE}}} and bo.ItemName = {{{SINGLE-QUOTE}}}Hemoglobin A1C Percent{{{SINGLE-QUOTE}}} and CAST (bo.value as float) >= 6.5"}; (DiabeticHealthIssue) := read last {"select hi.description from CV3HealthIssueDeclaration hi with (nolock) join CV3CodedHealthIssue h with (nolock) on h.GUID = hi.CodedHealthIssueGUID where hi.Active = 1 and (case when h.typecode = {{{SINGLE-QUOTE}}}imo{{{SINGLE-QUOTE}}} then substring(h.code, 5, 20) when h.TypeCode = {{{SINGLE-QUOTE}}}icd9{{{SINGLE-QUOTE}}} then h.code end) > {{{SINGLE-QUOTE}}}250.0{{{SINGLE-QUOTE}}} and (case when h.typecode = {{{SINGLE-QUOTE}}}imo{{{SINGLE-QUOTE}}} then substring(h.code, 5, 20) when h.TypeCode = {{{SINGLE-QUOTE}}}icd9{{{SINGLE-QUOTE}}} then h.code end) < {{{SINGLE-QUOTE}}}250.93{{{SINGLE-QUOTE}}} and ClientGuid = " || ClientGUID || " "}; // If Criteria are met Proceed If (EvokingEventType = lab_result_enter_event.type and PatientType is not null and exists Lab_Value and not exists DiabeticHealthIssue) or (EvokingEventType = clientvisit_modify_event.type and exists Lab_Value and not exists DiabeticHealthIssue) then // Lab event section If EvokingEventType = lab_result_enter_event.type then LabValue, abnormalitycode, ArrivalDtm := read last { Observation: value, abnormalitycode, ArrivalDtm REFERENCING EvokingObject }; // Reformat the Result Date ResultMonth:= EXTRACT Month ArrivalDtm; ResultDay:= EXTRACT Day ArrivalDtm; if ResultMonth < 10 then ResultMonth:= "0" || ResultMonth; endif; if ResultDay < 10 then ResultDay:= "0" || ResultDay; endif; ResultDate := ResultMonth || "/" || ResultDay || "/" || EXTRACT YEAR ArrivalDtm; if abnormalitycode = "H" then Lab_Value := LabValue || " (H) " || ResultDate; else Lab_Value := LabValue || " " || ResultDate; endif; // Attain patient{{{SINGLE-QUOTE}}}s existing Advanced Visit List Data for re-entry (ClientVisitGUID):= read last{"select ClientVisitGUID from CV3AdvancedVisitListData with (nolock) where externalid = " || AVL_External_ID || " and ClientVisitGUID = " || VisitGUID || " "}; // Visit event section ElseIf (EvokingEventType = clientvisit_modify_event.type) then // Populate Lab data found in the patient record if exists Lab_Value then if abnormalitycode = "H" then Lab_Value := Lab_Value || " (H) " || ArrivalDtm ; else Lab_Value := Lab_Value || " " || ArrivalDtm ; endif; else Lab_Value := " "; endif; endif; // If Proceed error_occurred := false; error_message := ""; continue_processing:= true; log_execution_info := false; is_closed := false; is_active := false; // CONTINUE PROCESSING (except for Health Issue Modify event where something other than status or onset date changed) if continue_processing then try client_visit_obj := call {{{SINGLE-QUOTE}}}ClientVisit{{{SINGLE-QUOTE}}}.FindByPrimaryKey with ((VisitGUID as number) as {{{SINGLE-QUOTE}}}Int64{{{SINGLE-QUOTE}}}) ; // Create the AdvancedVisitListData object. advanced_visit_list_data_obj := call {{{SINGLE-QUOTE}}}AdvancedVisitListData{{{SINGLE-QUOTE}}}.CreateAdvancedVisitListData with (client_visit_obj, AVL_Name, AVL_External_ID) ; endtry; catch Exception ex error_occurred := true; error_message := "{{+R}}Error Message:{{-R}}\n" || ex.Message || "\n\n"; if ( advanced_visit_list_data_obj is NOT NULL ) then void:= call advanced_visit_list_data_obj.Dispose; advanced_visit_list_data_obj:= null; endif; if ( client_visit_obj is NOT NULL ) then void:= call client_visit_obj.Dispose; client_visit_obj:= null; endif; endcatch; endif; // End of INPATIENT/OBSERVATION PATIENT PROCEED SECTION else // DO NOT PROCEED SECTION continue_processing:= false; endif; // If PatientType ;; priority: 50 ;; evoke: 1 minutes after time of lab_result_enter_event; 1 minutes after time of clientvisit_modify_event; ;; logic: if( EvokingObject is null or continue_processing = false ) then conclude false; endif; try if( is_closed AND is_active ) then void := call advanced_visit_list_data_obj.Deactivate; // don{{{SINGLE-QUOTE}}}t conclude false as we still need to return true to OP destination continue_processing:= false; endif; if( continue_processing ) then void := call advanced_visit_list_data_obj.{{{SINGLE-QUOTE}}}SetValue{{{SINGLE-QUOTE}}} with AVL_Result , Lab_Value ; objects_plus_destination.ObjectsPlus := advanced_visit_list_data_obj; endif; endtry; catch Exception ex error_occurred := true; error_message := "{{+R}}Error Message:{{-R}}\n" || ex.Message || "\n\n"; if ( advanced_visit_list_data_obj is NOT NULL ) then void:= call advanced_visit_list_data_obj.Dispose; advanced_visit_list_data_obj:= null; endif; if ( client_visit_obj is NOT NULL ) then void:= call client_visit_obj.Dispose; client_visit_obj:= null; endif; endcatch; if ( client_visit_obj is NOT NULL ) then void:= call client_visit_obj.Dispose; client_visit_obj:= null; endif; conclude true; ;; action: if error_occurred then write "An error has occured in the MLM " || "{{+B}}MLM SCH_AVL_DIABETES_ONSET {{-B}} " || "Please notify your System Administrators that an error message has " || "occurred for this patient. They will review the following error " || "message: \n" at alert_dest; write error_message at alert_dest; endif; if exists objects_plus_destination then write true at objects_plus_destination; endif; write " Messages " || " Version 1.. List Name : " || AVL_Name || " Evoking Event: " || evokevent || " Lab Value: " || Lab_Value || " ClientVisitGUID: " || ClientVisitGUID || " PatientType: " || PatientType || " DiabetesHI: " || DiabeticHealthIssue || " continue_processing : " || continue_processing at alert_dest; ;; urgency: 50;; end: