maintenance: title: FORM_SET_VANCOMYCIN_TROUGH_ORDERS;; mlmname: FORM_SET_VANCOMYCIN_TROUGH_ORDERS;; arden: version 2.5;; version: 6.10;; institution: St Clair Hospital;; author: Juliet M. Law, Allscripts ;; specialist: Bryan Berkeybile, Allscripts;; date: 2014-04-28;; validation: testing;; library: purpose: ;; explanation: This MLM is called from Vancomycin Orders - Trough order set. Change history 2014.04.28 JML CSR 32241: Created 2015.03.23 JML Moved to Production. 2015.03.24 JML Issue found where STAT and NOW orders being pulled to calculate trough times, causing errors in calculation. ;; keywords: Called MLMs ;; knowledge: type: data-driven;; data: standard_libs := mlm {{{SINGLE-QUOTE}}}std_include_libs{{{SINGLE-QUOTE}}}; include standard_libs; //using "ObjectsPlusXA.SCM.Forms"; //using namespace "ObjectsPlusXA.SunriseClinicalManager.Forms"; //Local session object local_session := cds_session.local; // This MLM is passed three arguments, of types // communication_type, form_type and client info object respectively. (this_communication, // Communication object this_form, // Form object client_info_obj //Arden ClientInfo object ) := argument; /*******************Make Changes To Spelling And Flags In This Section*******************/ /* Set to true if a decision.log is needed.*/ log_execution_info := FALSE; //Boolean to determine if first administration needs calculated calc_first_admin := false; //Boolean to determine if Trough order is selected is_trough_selected := false; /***************************************************************************************/ // Initialize error message error_message:=""; // Assigns fields passed in the Form object to the Field object field_list:= this_form.fields; CallingEvent := this_communication.CallingEvent; CallingField := this_communication.CallingFieldName; ClientGuid := this_communication.ClientGUID; ClientVisitGuid := this_communication.ClientVisitGUID; ChartGuid := this_communication.ChartGUID; FormName := this_form.Name; PrimaryObjDetail := this_communication.PrimaryObj; OrderSetName := PrimaryObjDetail.OrderSetName; //Retrieve Fields Last_Admin_Date := last of (field_list WHERE field_list.DataItemName = "LAB_Chem_Date_TDM" and field_list.Control_MultiFieldOccNum = 1); Last_Admin_Time := last of ( field_list WHERE field_list.DataItemName = "LAB_Chem_Time_TDM" and field_list.Control_MultiFieldOccNum = 1); First_Admin_Ckbx := last of ( field_list WHERE field_list.DataItemName = "PRX_Checkbox1" and field_list.Control_MultiFieldOccNum = 1); First_Admin_Date := last of ( field_list WHERE field_List.DataItemName = "LAB_Chem_Date_TDM" and field_list.Control_MultiFieldOccNum = 2); First_Admin_Time := last of ( field_list WHERE field_list.DataItemName = "LAB_Chem_Time_TDM" and field_list.Control_MultiFieldOccNum = 2); Second_Admin_Ckbx := last of ( field_list WHERE field_list.DataItemName = "PRX_Checkbox1" and field_list.Control_MultiFieldOccNum = 2); Second_Admin_Date := last of ( field_list WHERE field_list.DataItemName = "LAB_Chem_Date_TDM" and field_list.Control_MultiFieldOccNum = 3); Second_Admin_Time := last of ( field_list WHERE field_list.DataItemName = "LAB_Chem_Time_TDM" and field_list.Control_MultiFieldOccNum = 3); Third_Admin_Ckbx := last of ( field_list WHERE field_list.DataItemName = "PRX_Checkbox1" and field_list.Control_MultiFieldOccNum = 3); Third_Admin_Date := last of ( field_list WHERE field_list.DataItemName = "LAB_Chem_Date_TDM" and field_list.Control_MultiFieldOccNum = 4); Third_Admin_Time := last of ( field_list WHERE field_list.DataItemName = "LAB_Chem_Time_TDM" and field_list.Control_MultiFieldOccNum = 4); Fourth_Admin_Ckbx := last of ( field_list WHERE field_list.DataItemName = "PRX_Checkbox1" and field_list.Control_MultiFieldOccNum = 4); Fourth_Admin_Date := last of ( field_list WHERE field_list.DataItemName = "LAB_Chem_Date_TDM" and field_list.Control_MultiFieldOccNum = 5); Fourth_Admin_Time := last of ( field_list WHERE field_list.DataItemName = "LAB_Chem_Time_TDM" and field_list.Control_MultiFieldOccNum = 5); Vanco_orders := last of ( field_list WHERE field_list.DataItemname = "MultiOrderGrid" and field_list.Control_MultiFieldOccNum = 2); Vanco_orders_List := Vanco_orders.Value; Vanco_trough := last of ( field_list WHERE field_list.DataItemName = "MultiOrderGrid" and field_list.Control_MultiFieldOccNum = 3); Vanco_trough_Val := Vanco_trough.Value; Vanco_trough_ReqDate := last of ( field_list WHERE field_list.DataItemName = "RequestedDate" and field_list.Control_MultiFieldOccNum = 1); Vanco_trough_ReqTime := last of ( field_list WHERE field_list.DataItemName = "RequestedTime" and field_list.Control_MultiFieldOccNum = 1); //Retrieve last administration time ( OrderGUID, adminDtm, adminTime, adminSchTime, lastFreq, orderCreated ) := read last {"SELECT TOP 1 o.GUID, CONVERT( varchar(10), ot.PerformedFromDtm, 110)," || " CONVERT( varchar(5), ot.PerformedFromDtm, 14), CONVERT( varchar(5), ot.ScheduledDtm, 14), o.FrequencyCode," || " o.CreatedWhen" || " FROM CV3ClientVisit cv WITH (NOLOCK) JOIN CV3Order o WITH (NOLOCK)" || " ON cv.ClientGUID = o.ClientGUID" || " AND cv.GUID = o.ClientVisitGUID" || " AND cv.ChartGUID = o.ChartGUID" || " JOIN CV3OrderTaskOccurrence ot WITH (NOLOCK)" || " ON ot.ClientGUID = o.ClientGUID" || " AND ot.OrderGUID = o.GUID" || " WHERE o.NAME LIKE {{{SINGLE-QUOTE}}}VANCOMYCIN%{{{SINGLE-QUOTE}}}" || " AND ot.TaskStatusCode = {{{SINGLE-QUOTE}}}Performed{{{SINGLE-QUOTE}}}" || " AND cv.ClientGUID = " || Sql(ClientGUID) || " AND cv.GUID = " || Sql(ClientVisitGUID) || " AND cv.ChartGUID = " || Sql(ChartGUID) || " order by ot.ScheduledDtm desc"}; if ( CallingEvent = "FormOpen" ) then //Update Fields if ( exists orderGUID ) then Last_Admin_Date.Value := adminDtm; Last_Admin_Time.Value := adminTime; endif; Vanco_trough_ReqDate.Value := "T"; elseif ( CallingEvent = "FieldChange" ) then if ( CallingField = "MultiOrderGrid|3" ) then //Determine if the Vancomycin Trough lab was selected - if not, then no calculation is needed is_trough_selected := first of ( vanco_trough_val.IsSelected WHERE vanco_trough_val.Name = "Vancomycin Trough Plasma/Serum"); if ( is_trough_selected = true ) then //Determine if any vancomycin order was selected if ( NOT ( true IN Vanco_Orders_List.IsSelected ) ) then //Check for unsubmitted vancomycin orders captured in event triggered MLM and set in session var. if ( local_session.SessionUnsubVancoExists = true ) then First_Admin_Date.Value := local_session.SessionVancoTroughScheduledDate; //Need to format the time temp_time := local_session.SessionVancoTroughScheduledTime as Time; temp_time_hour := EXTRACT HOUR temp_time; if ( length ( temp_time_hour as string ) = 1 ) then temp_time_hour := "0" || temp_time_hour; endif; temp_time_min := EXTRACT MINUTE temp_time; if ( length ( temp_time_min as string ) = 1 ) then temp_time_min := "0" || temp_time_min; endif; First_Admin_Time.Value := temp_time_hour || ":" || temp_time_min; VancoScheduledFrequency := local_session.SessionVancoTroughFrequency; else //No unsubmitted orders //Check for existing vancomycin order that has NOT been administered - this //would be different than the performed vancomycin order checked for at the beginning of this MLM (newer_vanco_order, newer_vanco_reqDate, newer_vanco_reqTime, newer_vanco_freq) := READ LAST {"SELECT o.NAME, o.RequestedDate, CONVERT(varchar(5), o.RequestedDtm, 14), o.FrequencyCode" || " FROM CV3ClientVisit cv WITH (NOLOCK) JOIN CV3Order o WITH (NOLOCK)" || " ON cv.GUID = o.ClientVisitGUID" || " AND cv.ClientGUID = o.ClientGUID" || " AND cv.ChartGUID = o.ChartGUID" || " WHERE cv.ClientGUID = " || Sql(ClientGUID) || " AND cv.GUID = " || Sql(ClientVisitGUID) || " AND cv.ChartGUID = " || Sql(ChartGUID) || " AND o.Name = {{{SINGLE-QUOTE}}}Vancomycin:{{{SINGLE-QUOTE}}}" || " AND o.GUID <> " || Sql(OrderGUID) || " AND o.CreatedWhen > " || Sql(orderCreated) || " AND o.FrequencyCode LIKE {{{SINGLE-QUOTE}}}Q%{{{SINGLE-QUOTE}}}" || " AND ((o.OrderStatusLevelNum > 15" || " AND o.OrderStatusLevelNum NOT IN ({{{SINGLE-QUOTE}}}69{{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}70{{{SINGLE-QUOTE}}}))" || " OR o.OrderStatusCode = {{{SINGLE-QUOTE}}}HOLD{{{SINGLE-QUOTE}}})"}; if ( exists ( newer_vanco_order ) ) then First_Admin_Date.Value := newer_vanco_reqDate; First_Admin_Time.Value := newer_vanco_reqTime; VancoScheduledFrequency := newer_vanco_freq; else //No unsubmitted vanco orders exist and no newer vanco orders exist //base the future admin calculations on the next scheduled dose not administered from last administered calc_first_admin := true; VancoScheduledFrequency := lastFreq; endif; endif; else //If vancomycin was selected, then the first future admin calculation is the first scheduled //admin based on the antibiotic scheduling First_Admin_Date.Value := local_session.SessionVancoTroughScheduledDate; //Need to format the time temp_time := local_session.SessionVancoTroughScheduledTime as Time; temp_time_hour := EXTRACT HOUR temp_time; if ( length ( temp_time_hour as string ) = 1 ) then temp_time_hour := "0" || temp_time_hour; endif; temp_time_min := EXTRACT MINUTE temp_time; if ( length ( temp_time_min as string ) = 1 ) then temp_time_min := "0" || temp_time_min; endif; First_Admin_Time.Value := temp_time_hour || ":" || temp_time_min; //Set the frequency to the selected vancomycin order for grid above VancoScheduledFrequency := local_session.SessionVancoTroughFrequency; endif; //This MLM will only support Qx frequencies if ( VancoScheduledFrequency matches pattern "Q%" ) then ( frequencyNum, frequencyUOM ) := read last {"SELECT f.TimeFromValue, f.TimeUOM" || " FROM CV3Frequency f WITH (NOLOCK)" || " WHERE f.Code = " || Sql(VancoScheduledFrequency) }; endif; //************ Calculate First Admin Date and Time **************************************** //Only calculate first admin IF no vancomycin order was selected from above grid if ( calc_first_admin = true ) then admin_Hour := (extract hour ( adminSchTime as Time ) ) as number; admin_Min := ( extract minute ( adminSchTime as Time ) ) as number; if ( admin_Min = 0 ) then admin_Min := "00"; endif; newFirstAdmin_Hour := admin_Hour + (frequencyNum as number); new_admin_month := SUBSTRING 2 CHARACTERS From ( Last_Admin_Date.Value as string ); new_admin_day := Substring 2 Characters starting at 4 from ( Last_Admin_Date.Value as string ); new_admin_year := substring 4 characters starting at 7 from ( Last_Admin_Date.Value as string ); new_admin_dtm := new_admin_year || "-" || new_admin_month || "-" || new_admin_day || "T00:01:00"; new_admin := new_admin_dtm as Time; if ( newFirstAdmin_Hour < 24 ) then First_Admin_Date.Value := new_admin; if ( newFirstAdmin_Hour >= 1 AND newFirstAdmin_Hour <= 9 ) then First_Admin_Time.Value := "0" || newFirstAdmin_Hour || ":" || admin_Min; else First_Admin_Time.Value := newFirstAdmin_Hour || ":" || admin_Min; endif; elseif ( newFirstAdmin_Hour > 24 ) then if ( frequencyNum > 24 ) then newFirstAdmin_Hour := ( newFirstAdmin_Hour - ( frequencyNum as number ) ) as number; First_Admin_Date.Value := new_admin + 2 days; else newFirstAdmin_Hour := ( newFirstAdmin_Hour - 24 ) as number; First_Admin_Date.Value := new_admin + 1 day; endif; if ( newFirstAdmin_Hour >= 1 AND newFirstAdmin_Hour <= 9 ) then First_Admin_Time.Value := "0" || newFirstAdmin_Hour || ":" || admin_Min; else First_Admin_Time.Value := newFirstAdmin_Hour || ":" || admin_Min; endif; elseif ( newFirstAdmin_Hour = 24 ) then First_Admin_Date.Value := new_admin + 1 day; First_Admin_Time.Value := "00:" || admin_Min; endif; endif; //************ Calculate Second Admin Date and Time **************************************** firstAdmin_Hour := (extract hour ( First_Admin_Time.Value as Time ) ) as number; secondAdmin_Min := ( extract minute ( First_Admin_Time.Value as Time ) ) as number; if ( secondAdmin_Min = 0 ) then secondAdmin_Min := "00"; endif; secondAdmin_Hour := firstAdmin_Hour + (frequencyNum as number); sec_admin_month := SUBSTRING 2 CHARACTERS From ( First_Admin_Date.Value as string ); sec_admin_day := Substring 2 Characters starting at 4 from ( First_Admin_Date.Value as string ); sec_admin_year := substring 4 characters starting at 7 from ( First_Admin_Date.Value as string ); sec_admin_dtm := sec_admin_year || "-" || sec_admin_month || "-" || sec_admin_day || "T00:01:00"; sec_admin := sec_admin_dtm as Time; if ( secondAdmin_Hour < 24 ) then Second_Admin_Date.Value := sec_admin; if ( secondAdmin_Hour >= 1 AND secondAdmin_Hour <= 9 ) then Second_Admin_Time.Value := "0" || secondAdmin_Hour || ":" || secondAdmin_Min; else Second_Admin_Time.Value := secondAdmin_Hour || ":" || secondAdmin_Min; endif; elseif ( secondAdmin_Hour > 24 ) then if ( frequencyNum > 24 ) then secondAdmin_Hour := ( secondAdmin_Hour - ( frequencyNum as number ) ) as number; Second_Admin_Date.Value := sec_admin + 2 days; else secondAdmin_Hour := ( secondAdmin_Hour - 24 ) as number; Second_Admin_Date.Value := sec_admin + 1 day; endif; if ( secondAdmin_Hour >= 1 AND secondAdmin_Hour <= 9 ) then Second_Admin_Time.Value := "0" || secondAdmin_Hour || ":" || secondAdmin_Min; else Second_Admin_Time.Value := secondAdmin_Hour || ":" || secondAdmin_Min; endif; elseif ( secondAdmin_Hour = 24 ) then Second_Admin_Date.Value := sec_admin + 1 day; Second_Admin_Time.Value := "00:" || secondAdmin_Min; endif; //********************* Calculate Third Admin Date and Time ********************************** //thirdAdmin_Hour := secondAdmin_Hour + (frequencyNum as number); if ( secondAdmin_Hour = 24 ) then hour_value := 0; else hour_value := secondAdmin_Hour; endif; thirdAdmin_Hour := hour_value + ( frequencyNum as number ); thirdAdmin_Min := secondAdmin_Min; third_admin_month := Substring 2 Characters From ( Second_Admin_Date.Value as string ); third_admin_day := Substring 2 Characters Starting at 4 From ( Second_Admin_Date.Value as string ); third_admin_year := Substring 4 Characters Starting at 7 From ( Second_Admin_Date.Value as string ); third_admin_dtm := third_admin_year || "-" || third_admin_month || "-" || third_admin_day || "T00:01:00"; third_admin := third_admin_dtm as Time; if ( thirdAdmin_Hour < 24 ) then Third_Admin_Date.Value := Second_Admin_Date.Value; if ( thirdAdmin_Hour >= 1 AND thirdAdmin_Hour <= 9 ) then Third_Admin_Time.Value := "0" || thirdAdmin_Hour || ":" || thirdAdmin_Min; else Third_Admin_Time.Value := thirdAdmin_Hour || ":" || thirdAdmin_Min; endif; elseif ( thirdAdmin_Hour > 24 ) then if ( frequencyNum > 24 ) then thirdAdmin_Hour := ( thirdAdmin_Hour - ( frequencyNum as number ) ) as number; Third_Admin_Date.Value := third_admin + 2 days; else thirdAdmin_Hour := ( thirdAdmin_Hour - 24 ) as number; Third_Admin_Date.Value := third_admin + 1 day; endif; if ( thirdAdmin_Hour >= 1 AND thirdAdmin_Hour <= 9 ) then Third_Admin_Time.Value := "0" || thirdAdmin_Hour || ":" || thirdAdmin_Min; else Third_Admin_Time.Value := thirdAdmin_Hour || ":" || thirdAdmin_Min; endif; elseif ( thirdAdmin_Hour = 24 ) then Third_Admin_Date.Value := third_admin + 1 day; Third_Admin_Time.Value := "00:" || thirdAdmin_Min; endif; //*********** Calculate Fourth Admin Date and Time **************************** if ( thirdAdmin_Hour = 24 ) then hour_value := 0; else hour_value := thirdAdmin_Hour; endif; fourthAdmin_Hour := hour_value + ( frequencyNum as number ); fourthAdmin_Min := secondAdmin_Min; fourth_admin_month := Substring 2 Characters From ( Third_Admin_Date.Value as string ); fourth_admin_day := Substring 2 Characters Starting at 4 From ( Third_Admin_Date.Value as string ); fourth_admin_year := Substring 4 Characters Starting at 7 From ( Third_Admin_Date.Value as string ); fourth_admin_dtm := fourth_admin_year || "-" || fourth_admin_month || "-" || fourth_admin_day || "T00:01:00"; fourth_admin := fourth_admin_dtm as Time; if ( fourthAdmin_Hour < 24 ) then Fourth_Admin_Date.Value := fourth_admin; if ( fourthAdmin_Hour >= 1 AND fourthAdmin_Hour <= 9 ) then Fourth_Admin_Time.Value := "0" || fourthAdmin_Hour || ":" || fourthAdmin_Min; else Fourth_Admin_Time.Value := fourthAdmin_Hour || ":" || fourthAdmin_Min; endif; elseif ( fourthAdmin_Hour > 24 ) then if ( frequencyNum > 24 ) then fourthAdmin_Hour := ( fourthAdmin_Hour - ( frequencyNum as number ) ) as number; Fourth_Admin_Date.Value := fourth_admin + 2 days; else fourthAdmin_Hour := ( fourthAdmin_Hour - 24 ) as number; Fourth_Admin_Date.Value := fourth_admin + 1 day; endif; if ( fourthAdmin_Hour >= 1 AND fourthAdmin_Hour <= 9 ) then Fourth_Admin_Time.Value := "0" || fourthAdmin_Hour || ":" || fourthAdmin_Min; else Fourth_Admin_Time.Value := fourthAdmin_Hour || ":" || fourthAdmin_Min; endif; elseif ( fourthAdmin_Hour = 24 ) then Fourth_Admin_Date.Value := fourth_admin + 1 day; Fourth_Admin_Time.Value := "00:" || fourthAdmin_Min; endif; endif; elseif ( CallingField = "MultiOrderGrid|2" ) then Vanco_trough_Val.IsSelected := false; First_Admin_Date.Value := null; First_Admin_Time.Value := ""; First_Admin_Ckbx.Value := false; Second_Admin_Date.Value := null; Second_Admin_Time.Value := ""; Second_Admin_Ckbx.Value := false; Third_Admin_Date.Value := null; Third_Admin_Time.Value := ""; Third_Admin_Ckbx.Value := false; Fourth_Admin_Date.Value := null; Fourth_Admin_Time.Value := ""; Fourth_Admin_Ckbx.Value := false; elseif ( CallingField = "PRX_Checkbox1|1" ) then if ( First_Admin_ckbx.Value = true ) then //Toggle checkboxes Second_Admin_ckbx.Value := false; Third_Admin_ckbx.Value := false; Fourth_Admin_ckbx.Value := false; if ( First_Admin_Date.Value is not null ) then Vanco_trough_ReqDate.Value := First_Admin_Date.Value; a := ( First_Admin_Time.Value as Time ) - 30 minutes; b := extract hour a; if ( b >= 1 AND b <= 9 ) then b := "0" || b; endif; c := b || ":" || extract minute a; //Set the Requested Time Priority Vanco_trough_ReqTime_Val := Vanco_trough_ReqTime.Value; Vanco_trough_ReqTime_Val.ReqTimeCode := "Scheduled Time"; Vanco_trough_ReqTime_Val.ReqTimeValue := c; else First_Admin_ckbx.Value := false; endif; endif; elseif ( CallingField = "PRX_Checkbox1|2" ) then if ( Second_Admin_Ckbx.Value = true ) then //Toggle Checkboxes First_Admin_ckbx.Value := false; Third_Admin_ckbx.Value := false; Fourth_Admin_ckbx.Value := false; if ( Second_Admin_Date.Value is not null ) then Vanco_trough_ReqDate.Value := Second_Admin_Date.Value; a := ( Second_Admin_Time.Value as Time ) - 30 minutes; b := extract hour a; if ( b >= 1 AND b <= 9 ) then b := "0" || b; endif; c := b || ":" || extract minute a; //Set the Requested Time Priority Vanco_trough_ReqTime_Val := Vanco_trough_ReqTime.Value; Vanco_trough_ReqTime_Val.ReqTimeCode := "Scheduled Time"; Vanco_trough_ReqTime_Val.ReqTimeValue := c; else Second_Admin_Ckbx.Value := false; endif; endif; elseif ( CallingField = "PRX_Checkbox1|3" ) then if ( Third_Admin_Ckbx.Value = true ) then //Toggle checkboxes First_Admin_Ckbx.Value := false; Second_Admin_Ckbx.Value := false; Fourth_Admin_Ckbx.Value := false; if ( Third_Admin_Date.Value is not null ) then Vanco_trough_ReqDate.Value := Third_Admin_Date.Value; a := ( Third_Admin_Time.Value as Time ) - 30 minutes; b := extract hour a; if ( b >= 1 AND b <= 9 ) then b := "0" || b; endif; c := b || ":" || extract minute a; //Set the Requested Time Priority Vanco_trough_ReqTime_Val := Vanco_trough_ReqTime.Value; Vanco_trough_ReqTime_Val.ReqTimeCode := "Scheduled Time"; Vanco_trough_ReqTime_Val.ReqTimeValue := c; else Third_Admin_Ckbx.Value := false; endif; endif; elseif ( CallingField = "PRX_Checkbox1|4" ) then if ( Fourth_Admin_Ckbx.Value = true ) then //Toggle Checkboxes First_Admin_Ckbx.Value := false; Second_Admin_Ckbx.Value := false; Third_Admin_Ckbx.Value := false; if ( Fourth_Admin_Date.Value is not null ) then Vanco_trough_ReqDate.Value := Fourth_Admin_Date.Value; a := ( Fourth_Admin_Time.Value as Time ) - 30 minutes; b := extract hour a; if ( b >= 1 AND b <= 9 ) then b := "0" || b; endif; c := b || ":" || extract minute a; //Set the Requested Time Priority Vanco_trough_ReqTime_Val := Vanco_trough_ReqTime.Value; Vanco_trough_ReqTime_Val.ReqTimeCode := "Scheduled Time"; Vanco_trough_ReqTime_Val.ReqTimeValue := c; else Fourth_Admin_Ckbx.Value := false; endif; endif; endif; //End MultiOrderGrid|3 Calling Field endif; //End Calling Event ;; evoke: // No evoke statement ;; logic: conclude true; ;; action: // This MLM returns two parameters, of types communication_type and form_type respectively. return this_communication, this_form; ;; end: