maintenance: title: SCH_BASAL_INSULIN_CHECK;; mlmname: SCH_BASAL_INSULIN_CHECK;; arden: version 2;; version: 5.00;; institution: St Clair Hospital;; author: Shawn Head;; specialist: Janet Nordin;; date: 2016-06-27;; validation: testing;; library: purpose: Check to see if Basal Insulin alert needs to present to physicians ;; explanation: 06.21.2016 - STH - CSR#: 34335 - created {Go-Live Scheduled 9/13/2016} 10.20.2016 - STH - CSR#: 34335 - Needed to make a few more modifications so the MLM was backed out and re-loaded on 10/20/2016 11.10.2016 - STH - CSR#: 34335 - Need to supress the alert for the ER Major patients also per PRISM. loaded on 11/10/2016 03.06.2017 - DW - CSR#: 34335 - Remove from production status per requrest of the physicians 06.13.2018 - STH - CSR#: 35114 - Update to include new BGM result/item Glucose, BGM confirmation {Go-Live 6/20/2018} 10.05.2018 - STH - CSR#: 37415 - Additional updates requested by Dr. Lou. Change the wording, Add new selection options , remove selection option, add last dose administered, moved active orders to right of result values. {Go-Live 10-17-2018} ;; keywords: Objects+, Care Provider Visit Role, Auto create care provider, auto DC care provider ;; knowledge: type: data-driven;; data: /* Set to true if logging is needed.*/ log_execution_info:= FALSE; standard_libs := mlm {{{SINGLE-QUOTE}}}std_include_libs{{{SINGLE-QUOTE}}}; include standard_libs; using "ObjectsPlusXA.SCM.Forms"; using namespace "ObjectsPlusXA.SunriseClinicalManager.Forms"; on_order_enter := event {OrderWorksheetSubmit User } ; suggest_ordering := false; (ClientVisitGuid, ChartGuid, ClientGuid, VisitType, CurrentLoc):=read last {ClientVisit: GUID, ChartGUID, ClientGUID, TypeCode, CurrentLocation}; BasalInsulin_alert:= destination { Alert } WITH [alert_type := "Warning", short_message :="Basal Insulin Suggested", Priority :="HIGH", Scope := "chart", Rule_group :="BASALINSULIN", rule_number := 1005, send_with_order := "", display_alert := TRUE, alert_abstract:= "", alert_dialog_settings := "Must Comment", async_alert_dialog_settings := "", document_name := "", document_conditional_text := (), ack_comment_UDDD := "BasalAckComment", ack_comment_UDDD_is_restricted := true ]; userguid,user_id :=read last {UserInfo: guid,idcode}; if(((substring 3 characters from CurrentLoc) = "ICU") or ((substring 4 characters from CurrentLoc) = "CVSU") or (CurrentLoc = "ER Major")) then SupressAlert := true; else SupressAlert := false; endif; //SupressAlert := false; occcode := read last {" select OccupationCode from CV3USER U with (nolock)" || " where guid = " || sql(userguid) }; if ((SupressAlert = false) and (occcode in ("MD","DO","DMD","DPM","CRNP","PA","PA-C","IT"))) then (Basal_OCMI_GUIDs, Basal_OCMI_Names) := read { " select distinct OCMI.guid, ocmi.Name as {{{SINGLE-QUOTE}}}OrderName{{{SINGLE-QUOTE}}} from CV3OrderCatalogMasterItem OCMI join cv3drugmapping dm on ocmi.guid = dm.catalogitemguid join SXAMultumLevelsForDupMedTherapy dup on dup.DrugId = dm.DrugKey where dup.LevelOne_Name = {{{SINGLE-QUOTE}}}intermediate- and long-acting insulins{{{SINGLE-QUOTE}}} and ExpiryDate is null " }; (existing_Basal_orders) := Read {UnsubmittedOrders : Name WHERE Name in (sql(Basal_OCMI_Names)) }; if(count(existing_Basal_orders)=0) then (glucose_results,Result_Entered, Result_value) := read { " select guid into #tmp_Glucoseitems from CV3ResultCatalogItem with(nolock) where itemname in ({{{SINGLE-QUOTE}}}Glucose, BGM confirmation{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Glucose Non-Fasting{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Glucose Bedside{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Glucose Bedside.{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Glucose Fasting{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Glucose Fasting from Blood Gas{{{SINGLE-QUOTE}}}" || ",{{{SINGLE-QUOTE}}}Glucose from Blood Gas{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Glucose, ABG, POC{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Glucose, VBG, POC{{{SINGLE-QUOTE}}}) select bo.value , BO.ENTERED into #tmp_GlucoseResults from #tmp_Glucoseitems tg inner join CV3BasicObservation bo with (nolock) on tg.GUID = bo.ResultItemGUID and bo.ClientGUID = " || sql(ClientGuid) || " and bo.ChartGUID = " || sql(ChartGuid) || " and bo.ClientVisitGUID = " || sql(ClientVisitGuid) || " select top 2 (CASE WHEN ISNULL(BO.VALUE,{{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}}) >= 200 then {{{SINGLE-QUOTE}}}yes{{{SINGLE-QUOTE}}} when isnull(bo.value,{{{SINGLE-QUOTE}}}{{{SINGLE-QUOTE}}}) like {{{SINGLE-QUOTE}}}>%{{{SINGLE-QUOTE}}} then {{{SINGLE-QUOTE}}}yes{{{SINGLE-QUOTE}}} else {{{SINGLE-QUOTE}}}no{{{SINGLE-QUOTE}}} end) as {{{SINGLE-QUOTE}}}high_result{{{SINGLE-QUOTE}}} , bo.entered , case when isnull(bo.value,{{{SINGLE-QUOTE}}}{{{SINGLE-QUOTE}}}) = {{{SINGLE-QUOTE}}}{{{SINGLE-QUOTE}}} then {{{SINGLE-QUOTE}}}N/A{{{SINGLE-QUOTE}}} else bo.value end as {{{SINGLE-QUOTE}}}ResultValue{{{SINGLE-QUOTE}}} from #tmp_GlucoseResults bo with(nolock) where bo.Entered >= dateadd(hh,-24,getdate()) order by bo.Entered desc DROP TABLE #tmp_Glucoseresults, #tmp_Glucoseitems "}; // //this needs added into the above statement before go-live // where bo.Entered >= dateadd(hh,-24,getdate()) ResultDTTM1 := Result_Entered[1]; ResultDTTM2 := Result_Entered[2]; ctgl := count(glucose_results); if((count(glucose_results)>=2) and ("no" not in glucose_results)) then //GlucoseResultsMessage := "{{+B}}Last 2 Glucose Results:{{-B}}\n " || ResultDTTM1 || " - {{+B}}{{+R}}" || Result_value[1] || "{{-R}}{{-B}}\n " || ResultDTTM2 || " - {{+B}}{{+R}}" || Result_value[2] || "{{-R}}{{-B}}"; abc123 := "step1"; (Alert_Previous_Fired,Alert_Fired_Dttm,Suppress) := read { " select {{{SINGLE-QUOTE}}}true{{{SINGLE-QUOTE}}}, Entered, (case when alertcomments in ({{{SINGLE-QUOTE}}}Clinical Adjustments Made{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Patient not a candidate for tight glycemic control.{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}I have consulted PCP/Endocrinologist.{{{SINGLE-QUOTE}}}) then {{{SINGLE-QUOTE}}}YES{{{SINGLE-QUOTE}}} else {{{SINGLE-QUOTE}}}NO{{{SINGLE-QUOTE}}} end) as {{{SINGLE-QUOTE}}}full_suppress{{{SINGLE-QUOTE}}} from CV3AlertDeclaration WITH (NOLOCK) where ClientGUID = " || sql(ClientGuid) || " and ChartGUID = " || sql(ChartGuid) || " and ClientVisitGUID = " || sql(ClientVisitGuid) || " and description like {{{SINGLE-QUOTE}}}%BASAL INSULIN SUGGESTED%{{{SINGLE-QUOTE}}} and userguid = " || sql(userguid) || " order by entered desc "}; /*--REMOVED BECAUSE WE RESTRICTED THE ALERT COMMENT SELECTION TO BE DROP DOWN LIST ONLY, NO FREETEXT ENTRY ALLOWED. and ((alertcomments like {{{SINGLE-QUOTE}}}%Observe for another 24 hours to see if sugars improve%{{{SINGLE-QUOTE}}}) or (alertcomments like {{{SINGLE-QUOTE}}}%Fear of hypoglycemia%{{{SINGLE-QUOTE}}})) */ if((count(Alert_Previous_Fired)=0) or (("YES" not in Suppress) and ((Result_Entered[1] > Alert_Fired_Dttm[1]) and (Result_Entered[2] > Alert_Fired_Dttm[1])))) then abc123 := "step2"; active_basal_insulin_orders := (); Basal_summary_line := (); Basal_Requested_dttm := (); Basal_Administered_dttm := (); Basal_Administered_name := (); Basal_Administered_summaryline := (); (Basal_Requested_dttm, active_basal_insulin_orders, Basal_summary_line ,Basal_Administered_dttm, Basal_Administered_name, Basal_Administered_summaryline) := read { " select distinct OCMI.guid, ocmi.Name as {{{SINGLE-QUOTE}}}OrderName{{{SINGLE-QUOTE}}} into #tmp_OCMI from CV3OrderCatalogMasterItem OCMI join cv3drugmapping dm on ocmi.guid = dm.catalogitemguid join SXAMultumLevelsForDupMedTherapy dup on dup.DrugId = dm.DrugKey where dup.LevelOne_Name = {{{SINGLE-QUOTE}}}intermediate- and long-acting insulins{{{SINGLE-QUOTE}}} and ExpiryDate is null ;with orders as ( select distinct o.* from #tmp_OCMI ocmi with (nolock) inner join cv3order o with (nolock) on ocmi.GUID = o.OrderCatalogMasterItemGUID and o.ClientGUID = " || sql(ClientGuid) || " and o.ChartGUID = " || sql(ChartGuid) || " and o.ClientVisitGUID = " || sql(ClientVisitGuid) || " ), activeorders as ( select distinct o.clientguid, o.requestedDtm, o.name, replace(o.summaryline,char(13)+char(10),{{{SINGLE-QUOTE}}} {{{SINGLE-QUOTE}}}) as {{{SINGLE-QUOTE}}}summaryline{{{SINGLE-QUOTE}}} from orders o with (Nolock) where o.OrderStatusLevelNum > {{{SINGLE-QUOTE}}}15{{{SINGLE-QUOTE}}} and o.OrderStatusLevelNum not in ({{{SINGLE-QUOTE}}}69{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}70{{{SINGLE-QUOTE}}}) ), lastadmin as ( select TOP 1 o.clientguid, isnull(oto.PerformedFromDtm,{{{SINGLE-QUOTE}}}{{{SINGLE-QUOTE}}}) as {{{SINGLE-QUOTE}}}PerformedFromDtm{{{SINGLE-QUOTE}}} , isnull(o.name,{{{SINGLE-QUOTE}}}NO ADMINISTRATION{{{SINGLE-QUOTE}}}) as {{{SINGLE-QUOTE}}}name{{{SINGLE-QUOTE}}}, isnull(replace(o.summaryline,char(13)+char(10),{{{SINGLE-QUOTE}}} {{{SINGLE-QUOTE}}}),{{{SINGLE-QUOTE}}}{{{SINGLE-QUOTE}}}) as {{{SINGLE-QUOTE}}}summaryline{{{SINGLE-QUOTE}}} from orders o inner join CV3OrderTaskOccurrence oto on o.ClientGUID = oto.ClientGUID and o.GUID = oto.OrderGUID and oto.TaskStatusCode = {{{SINGLE-QUOTE}}}Performed{{{SINGLE-QUOTE}}} order by oto.PerformedFromDtm ) select ao.RequestedDtm, ao.Name, ao.summaryline, la.PerformedFromDtm,la.name, la.summaryline from activeorders ao left join lastadmin la on ao.ClientGUID = la.ClientGUID order by ao.Name drop table #tmp_OCMI "}; /* (Basal_Requested_dttm, active_basal_insulin_orders, Basal_summary_line) := read { " select distinct OCMI.guid, ocmi.Name as {{{SINGLE-QUOTE}}}OrderName{{{SINGLE-QUOTE}}} into #tmp_OCMI from CV3OrderCatalogMasterItem OCMI join cv3drugmapping dm on ocmi.guid = dm.catalogitemguid join SXAMultumLevelsForDupMedTherapy dup on dup.DrugId = dm.DrugKey where dup.LevelOne_Name = {{{SINGLE-QUOTE}}}intermediate- and long-acting insulins{{{SINGLE-QUOTE}}} and ExpiryDate is null select distinct o.requestedDtm, o.name, replace(o.summaryline,char(13)+char(10),{{{SINGLE-QUOTE}}} {{{SINGLE-QUOTE}}}) from #tmp_OCMI ocmi with (nolock) inner join cv3order o with (nolock) on ocmi.GUID = o.OrderCatalogMasterItemGUID and o.ClientGUID = " || sql(ClientGuid) || " and o.ChartGUID = " || sql(ChartGuid) || " and o.ClientVisitGUID = " || sql(ClientVisitGuid) || " where o.OrderStatusLevelNum > {{{SINGLE-QUOTE}}}15{{{SINGLE-QUOTE}}} and o.OrderStatusLevelNum not in ({{{SINGLE-QUOTE}}}69{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}70{{{SINGLE-QUOTE}}}) order by o.Name " }; */ BasalOrderNames := ""; BasalOrderMessage := ""; for x in (1 seqto count(active_basal_insulin_orders)) do if(((Basal_Requested_dttm[x] as time) < (ResultDTTM1 as time)) and ((Basal_Requested_dttm[x] as time) < (ResultDTTM2 as time))) then suggest_ordering := true; endif; if (count(BasalOrderNames) <= 0) then BasalOrderNames := Basal_Requested_dttm[x] || " - " || active_basal_insulin_orders[x] || "\n {" || Basal_summary_line[x] || "}\n"; else BasalOrderNames := BasalOrderNames || Basal_Requested_dttm[x] || " - " || active_basal_insulin_orders[x] || "\n {" || Basal_summary_line[x] || "}\n"; endif; enddo; if(count(active_basal_insulin_orders) = 0) then suggest_ordering := true; BasalOrderMessage := "{{+B}}{{+R}}THERE ARE CURRENTLY NO ACTIVE BASAL ORDERS{{-B}}{{-R}}\n " || BasalOrderNames; else BasalOrderMessage := "{{+B}}Active Basal Order Names:{{-B}}\n " || BasalOrderNames; endif; if(count(Basal_Administered_name) <= 0) then Basal_Administered_dttm := ""; Basal_Administered_name := ""; Basal_Administered_summaryline := ""; Basal_Administered_Header := "{{+R}}No Basal Insulin Administered{{-R}}"; else Basal_Administered_Header := "Most Recent Administration of Basal"; endif; //GlucoseResultsMessage := "{{+B}}Last 2 Glucose Results:{{-B}}\n " || ResultDTTM1 || " - {{+B}}{{+R}}" || Result_value[1] || "{{-R}}{{-B}}\n " || ResultDTTM2 || " - {{+B}}{{+R}}" || Result_value[2] || "{{-R}}{{-B}}"; FinalMessageDetails := "{{+B}}Last 2 Glucose Results: " || Basal_Administered_Header || "{{-B}}\n" || ResultDTTM1 || " - {{+B}}{{+R}}" || Result_value[1] || "{{-R}}{{-B}} " || Basal_Administered_dttm[1] || " " || Basal_Administered_name[1] || "\n" || ResultDTTM2 || " - {{+B}}{{+R}}" || Result_value[2] || "{{-R}}{{-B}} " || Basal_Administered_summaryline[1] || "\n " || BasalOrderMessage|| "\n"; endif; endif; endif; endif; ;; evoke: on_order_enter; ;; logic: conclude true; ;; action: if(suggest_ordering) then error_destination.short_message := "BASAL INSULIN SUGGESTED"; alert_message := "Patient has had {{+B}}2 or more Glucose Levels >200mg/dl in the last 24 hours {{-B}}Please consider initiating or adjusting Basal Insulin.\n\n " || /*"\n\nConsider ordering ""Diabetic Management Protocol"".\n\n" || */FinalMessageDetails; //GlucoseResultsMessage || "\n\n" || BasalOrderMessage; write alert_message at BasalInsulin_alert; //write error_message at error_destination; endif; ;; Urgency: 50;; end: