maintenance: title: Observation Admit/Discharge;; mlmname: FORM_Observation_ADT;; arden: version 2;; version: 4.50;; institution: St Clair;; author: Don Warnick, Eclipsys Corp;; specialist: ;; date: 2010-07-15;; validation: testing;; library: purpose: Manage Date fields ;; explanation: This MLM is called from the Observation forms and Order sets Change history 07.15.2010 DW Created 07.12.2011 DW Introduced logic to support mandatory MD HI entry found in Form_Health_Issue_Entered_From_Order_Form 08.09.2013 DW HD#159598 Altered date field from "requesteddate" to "CM_Patient_Change_Date" 11.5.2013 SH CSR#: 31898 Altered to include PA, PA-C, and CRNP for required HI and Admit date/time to auto populate. Also added 5 minutes to the start time to prevent nuisance alert from occuring. 02.25.2014 JML CSR# 31744: Modified for Discharge order ONLY; if patient is "emergency", then remove the mandatory field property on Discharge Diagnosis. 06.03.2014 DW CSR# 31688 Changes for MU2 08.07.2014 DW HD#167318 - Exclude all Infusion Department users from the Discharge Dx requirement. ;; keywords: Called MLMs, Form fields, Observation ADT Date fields ;; knowledge: type: data-driven;; data: standard_libs := MLM {{{SINGLE-QUOTE}}}std_include_libs{{{SINGLE-QUOTE}}}; include standard_libs; (this_communication, this_form, client_info_obj) := argument; visit_guid := this_communication.ClientVisitGUID; client_guid := this_communication.ClientGUID; chart_guid := this_communication.ChartGUID; orderroletype:= this_communication.primaryobj.enterrole; orderForm := this_communication.PrimaryObj.Name; userguid := this_communication.userguid; if (orderroletype matches pattern "%Physician%") or orderroletype in ("PA","PA-C","CRNP","Nurse (RN)") then orderrole := true; else orderrole := false; endif; orgunit := read last {" select ou.Name " || " from cv3user u with (nolock) " || " join CV3OrganizationalUnit ou with (nolock) on ou.guid = u.OrgUnitGUID " || " where u.guid = " || SQL(userguid) }; log_execution_info := FALSE; error_message:=""; field_list:= this_form.fields; CallingField :=this_communication.CallingFieldName; CallingEvent := this_communication.CallingEvent; // On some of the forms the "system" date field is not used. This permits either to work. requesteddate:= last of (field_list where field_list.DataItemName = "RequestedDate" ); if not exist requesteddate then requesteddate:= last of (field_list where field_list.DataItemName = "CM_Patient_Change_Date" ); endif; requestedtime:= last of (field_list where field_list.DataItemName = "RequestedTime" ); Obs_field := last of (field_list where field_list.DataItemName = "NUR_ADTObsvStatusCBx"); SSop_field := last of (field_list where field_list.DataItemName = "NUR_ADTSsopStatusCBx"); Inp_field := last of (field_list where field_list.DataItemName = "NUR_ADTInptStatusCBx"); Surgery_field := last of (field_list where field_list.DataItemName= "NUR_ADTsdcstatusCBx"); Denied_field := last of (field_list where field_list.DataItemName = "NUR_ADTAdmDeniedCBx"); Dis_Time_Testing_field := last of (field_list where field_list.DataItemName= "NUR_CB Testing" ); Dis_Time_AM_field := last of (field_list where field_list.DataItemName = "NUR_CB AM"); Dis_Time_PM_field := last of (field_list where field_list.DataItemName = "NUR_CB PM"); Dis_Time_Today_field:= last of (field_list where field_list.DataItemName = "NUR_CB Today"); Dis_Time_Tomorrow_field:= last of (field_list where field_list.DataItemName= "NUR_CB Tomorrow"); Dis_Time_Now_field:= last of (field_list where field_list.DataItemName = "NUR_CB Now"); AttendingPhysician:= last of (field_list where field_list.DataItemName = "Obj_Plus_Consult"); Two_Midnight_field:= last of (field_list where field_list.DataItemName = "CPOE_Adm_TwoMidnight"); Dis_Diagnosis_field:= last of (field_list where field_list.DataItemName = "Obj_Plus_Problem List Builder DISC"); Dis_Current_Diagnosis_field:= last of (field_list where field_list.DataItemName = "NUR_ADT Discharge Dx"); Dis_Goals_field:= last of (field_list where field_list.DataItemName = "NUR_DC_Goals"); //**** CSR 31744 Change **** Dis_ED_Diagnosis_field := last of (field_list WHERE field_list.DataItemName = "DISC_Discharge Diagnosis"); MD_Box := last of (field_list where field_list.DataItemName = "MLM_Physician_Mandatory_HI"); // extract components of current time and create fields which can be compared with requested time hr := extract hour now; if hr < 10 then hr := "0" || hr; endif; mi := extract minute now; if mi < 10 then mi := "0" || mi; endif; yr := extract year now; mn := extract month now; if mn < 10 then mn := "0" || mn; endif; dd := extract day now; if dd < 10 then dd := "0" || dd; endif; calc_currtime := ((hr ||":"|| mi) as time) + 300 seconds; //changed to add 5 minutes to time to prevent nuisance alerts currdate := yr || "-" || mn || "-" || dd ; currtime := extract hour calc_currtime || ":" || extract minute calc_currtime; // Populate the Requested Time Code with "start time" requestedtime.value.ReqTimeCode := "Start Time"; // Only called upon open from the Admit, Observation, Discharge forms //**** CSR 31744 Change Begin **** visitType := read last {"SELECT cv.TypeCode" || " FROM CV3Client c WITH (NOLOCK) JOIN CV3ClientVisit cv WITH (NOLOCK)" || " ON c.GUID = cv.ClientGUID" || " WHERE c.GUID = " || Sql(client_guid) || " AND cv.GUID = " || Sql(visit_guid)}; if ( ( visitType <> "Emergency" ) and ( visitType <> "Clinic" ) ) then Dis_ED_Diagnosis_field.control_read_only := true; endif; //**** CSR 31744 Change End **** (DischargeDiagnosisHIOnFile) := read { " select distinct hi.shortname " || " from cv3healthissuedeclaration hi with (nolock) " || " join CV3CodedHealthIssue chi with (nolock) on chi.GUID = hi.CodedHealthIssueGUID " || " where hi.clientguid = " || client_guid || " and hi.chartguid = " || chart_guid || " and hi.clientvisitguid = " || visit_guid || " " || " and hi.active = 1 and hi.status = {{{SINGLE-QUOTE}}}Active{{{SINGLE-QUOTE}}} " || " and hi.typecode = {{{SINGLE-QUOTE}}}Discharge Diag{{{SINGLE-QUOTE}}} " }; (NursingOrdersList) := read last { " SET CONCAT_NULL_YIELDS_NULL off select {{{SINGLE-QUOTE}}}\n{{{SINGLE-QUOTE}}} + o.name + {{{SINGLE-QUOTE}}} {{{SINGLE-QUOTE}}} + REPLACE(REPLACE(REPLACE(o.SummaryLine, CHAR(10), {{{SINGLE-QUOTE}}} {{{SINGLE-QUOTE}}}), CHAR(13), {{{SINGLE-QUOTE}}} {{{SINGLE-QUOTE}}}), CHAR(9), {{{SINGLE-QUOTE}}} {{{SINGLE-QUOTE}}}) " || " from cv3ordercatalogmasteritem as ocmi with (nolock) " || " join cv3order as o with (nolock)on o.ordercatalogmasteritemguid = ocmi.guid " || " and o.ClientGUID = " || client_guid || " and o.ChartGUID = " || chart_guid || " and o.ClientVisitGUID= " || visit_guid || " " || " and o.InitialSessionTypeCode = {{{SINGLE-QUOTE}}}Discharge{{{SINGLE-QUOTE}}} and o.name <> {{{SINGLE-QUOTE}}}Discharge{{{SINGLE-QUOTE}}} " || " and o.name not like {{{SINGLE-QUOTE}}}Lab Test%{{{SINGLE-QUOTE}}} and o.name not like {{{SINGLE-QUOTE}}}Medical Imaging%{{{SINGLE-QUOTE}}} " || " and o.OrderStatusLevelNum > 15 and o.OrderStatusLevelNum not in (69, 70) " }; // FORM CLOSE If CallingEvent = "FormClose" Then AttendingPhysicianNameEdstan := AttendingPhysician.value; AttendingPhysicianName:= Substring (Find "(" in string AttendingPhysicianNameEdstan) -1 characters from AttendingPhysicianNameEdstan; EdstanStart := (Find "(" in string AttendingPhysicianNameEdstan) +1; Edstanlength := ((Find ")" in string AttendingPhysicianNameEdstan) -1) - (Find "(" in string AttendingPhysicianNameEdstan); Edstan := Substring Edstanlength characters starting at EdstanStart from AttendingPhysicianNameEdstan ; RequestingUserGUID := read first { " select cp.guid " || " from cv3careproviderid cpid with (nolock) " || " join cv3careprovider cp on cp.guid = cpid.providerguid " || " where cpid.ProviderIDTypeCode = {{{SINGLE-QUOTE}}}Edstan Number (physician){{{SINGLE-QUOTE}}} " || " and cpid.idcode = " || Sql(Edstan) }; (CurrentOrder) := read last { " select o.name " || " from cv3order o with (nolock) " || " where o.name = {{{SINGLE-QUOTE}}}Two Midnight Rule (Admit to Inpatient){{{SINGLE-QUOTE}}} " || " and o.ClientGUID = " || client_guid || " and o.ChartGUID = " || chart_guid || " and o.ClientVisitGUID= " || visit_guid || " " || " and o.OrderStatusLevelNum > 15 and o.OrderStatusLevelNum not in (69, 70) " }; If exists RequestingUserGUID and not exists CurrentOrder and Two_Midnight_field.value = true then try orderItemName := "Two Midnight Rule (Admit to Inpatient)"; SessionType := "Standard"; SessionReason := ""; RequestingSource := "Verbal Order"; user_IDType := "Edstan Number (physician)"; order_Creation_Reason := "From Test MLM"; client_visit_obj := call {{{SINGLE-QUOTE}}}ClientVisit{{{SINGLE-QUOTE}}}.FindByPrimaryKey with ((visit_guid as number) as {{{SINGLE-QUOTE}}}Int64{{{SINGLE-QUOTE}}}) ; user_IDCode := read last {"SELECT IDCode FROM CV3CareProviderID " || " where ProviderGUID = {{{SINGLE-QUOTE}}}" || RequestingUserGUID || "{{{SINGLE-QUOTE}}} and ProviderIDTypeCode = {{{SINGLE-QUOTE}}}" || user_IDType || "{{{SINGLE-QUOTE}}}"}; RequestingCareProvider_obj:= call {{{SINGLE-QUOTE}}}CareProvider{{{SINGLE-QUOTE}}}.FindById with ( user_IDType, (user_IDCode as STRING) ); location_guid := read last {"SELECT CurrentLocationGUID FROM CV3ClientVisit with (nolock) where ClientGUID = " || client_guid}; location_obj := call {{{SINGLE-QUOTE}}}Location{{{SINGLE-QUOTE}}}.FindByPrimaryKey with ((location_guid as number) as {{{SINGLE-QUOTE}}}Int64{{{SINGLE-QUOTE}}}); general_catalog_item := call {{{SINGLE-QUOTE}}}OrderCatalogMasterItem{{{SINGLE-QUOTE}}}.FindByName with orderItemName; GeneralOrder_obj := call {{{SINGLE-QUOTE}}}GeneralOrder{{{SINGLE-QUOTE}}}.CreateGeneralOrder with client_visit_obj, // ClientVisit ObjectsPlus object general_catalog_item, // CatalogMasterItem ObjectsPlus object order_Creation_Reason, // CreateReason RequestingCareProvider_obj, // RequestingProvider ObjectsPlus object RequestingSource, // string requestingSource (must be in dictionary) SessionType, // string SessionType SessionReason, // string SessionReason location_obj, // Location ReleaseLocGrpID "Never" as {{{SINGLE-QUOTE}}}AvailabilityOverride{{{SINGLE-QUOTE}}}; // AvailabilityOverride GeneralOrder_obj.RequestedDate := "T"; void := call GeneralOrder_obj.Save; endtry; catch Exception ex error_occurred:= true; debugFlag := TRUE; messageText := messageText || "New general order:\n" || ex.Message || "\n\n"; if ( general_catalog_item is NOT NULL ) then void:= call general_catalog_item.Dispose; general_catalog_item:= null; endif; if ( GeneralOrder_obj is NOT NULL ) then void:= call GeneralOrder_obj.Dispose; GeneralOrder_obj:= null; endif; endcatch; if ( client_visit_obj is NOT NULL ) then void:= call client_visit_obj.Dispose; client_visit_obj:= null; endif; if ( RequestingCareProvider_obj is NOT NULL ) then void:= call RequestingCareProvider_obj.Dispose; RequestingCareProvider_obj:= null; endif; if ( location_obj is NOT NULL ) then void:= call location_obj.Dispose; location_obj:= null; endif; endif; // Place Order Decision endif; // Close // FORM OPEN If CallingEvent= "FormOpen" then If orderrole = true then MD_Box.control_mandatory := true; requesteddate.value:= currdate; requestedtime.value.reqtimevalue:= currtime; endif; If exists DischargeDiagnosisHIOnFile then for i in 1 seqto count DischargeDiagnosisHIOnFile do if i = 1 then DischargeDiagnosisHIOnFile_Out := DischargeDiagnosisHIOnFile [i]; else DischargeDiagnosisHIOnFile_Out := DischargeDiagnosisHIOnFile_Out || " , " || DischargeDiagnosisHIOnFile [i]; endif; enddo; Dis_Diagnosis_field.Control_Mandatory := false; else DischargeDiagnosisHIOnFile_Out := " "; If orderrole = true and orgunit not in ("Emergency Department","Infusion Center") then Dis_Diagnosis_field.Control_Mandatory := true; else Dis_Diagnosis_field.Control_Mandatory := false; endif; endif; // exists DischargeDiagnosisHIOnFile Dis_Current_Diagnosis_field.Value := DischargeDiagnosisHIOnFile_Out ; endif; // orderrole = true // FIELD CHANGE If CallingEvent = "FieldChange" then // Called from this field on the Change (in house) form If callingField = "NUR_ADTObsvStatusCBx" then If Obs_field.value = true then SSop_field.control_read_only := True; Inp_field.control_read_only := True; Surgery_field.control_read_only := True; Denied_field.control_read_only := True; else SSop_field.control_read_only := False; Inp_field.control_read_only := False; Surgery_field.control_read_only := False; Denied_field.control_read_only := False; requesteddate.value:= " "; requestedtime.value.reqtimevalue:= " "; endif; // Called from one of these fields on the Discharge - Observation form ElseIf (callingField = "NUR_CB Now") // Now is selected then If (Dis_Time_Now_field.value = true) then // NOW is True Dis_Time_Today_field.value:= false; Dis_Time_Tomorrow_field.value:= false; requesteddate.value:= currdate; requestedtime.value.reqtimevalue:= currtime; else // NOW is False requesteddate.value := " "; requestedtime.value.ReqTimeCode := " "; endif; ElseIf (callingField = "NUR_CB Testing" or callingField = "NUR_CB AM" or callingField = "NUR_CB PM" or callingField = "NUR_CB Today" or callingField = "NUR_CB Tomorrow") // Pending Results or AM or PM or Today or Tomorrow is selected then If (Dis_Time_Testing_field.value = true or Dis_Time_AM_field.value = true or Dis_Time_PM_field.value = true or Dis_Time_Today_field.value = true or Dis_Time_Tomorrow_field.value = true) then // Any are True requesteddate.Control_Mandatory:= false; requestedtime.Control_Mandatory:= false; else // All are False requesteddate.Control_Mandatory:= true; requestedtime.Control_Mandatory:= true; endif; ElseIf (CallingField = "CPOE_ADM Dx Override") then HardCodedProblem:= last of (field_list where field_list.DataItemName = "HI List 1"); ProblemListADM := last of (field_list where field_list.DataItemName = "Obj_Plus_Problem List Builder ADM"); Override := last of (field_list where field_list.DataItemName = "CPOE_ADM Dx Override"); If Override.Value = true then HardCodedProblem.Value := ""; HardCodedProblem.Control_Mandatory:= false; ProblemListADM.Control_Mandatory := true; endif; endif; If callingField = "NUR_CB Tomorrow" then If Dis_Time_Tomorrow_field.value = true then Dis_Time_Now_field.value:= false; Dis_Time_Today_field.value:= false; requesteddate.value:= Now + 1 day; else requesteddate.value:= " "; endif; endif; If callingField = "NUR_CB Today" then If Dis_Time_Today_field.value = true then Dis_Time_Now_field.value:= false; Dis_Time_Tomorrow_field.value:= false; requesteddate.value:= Now; else requesteddate.value:= " "; endif; endif; If callingField = "NUR_CB AM" then If Dis_Time_AM_field.value = true then Dis_Time_PM_field.value:= false; endif; endif; If callingField = "NUR_CB PM" then If Dis_Time_PM_field.value = true then Dis_Time_AM_field.value:= false; endif; endif; If callingField = "Obj_Plus_Problem List Builder DISC" then If Dis_Diagnosis_field.value matches pattern "%...%" or Dis_Diagnosis_field.Value is null then xxx:= "xxx"; else dlg_result := call {{{SINGLE-QUOTE}}}MessageBox{{{SINGLE-QUOTE}}}.Show with "\n\nType-in{{{SINGLE-QUOTE}}}s are not permitted. Click the search button (on the right) to enter the Health Issue " || "\n\n\n","Type-in Information Not Permitted", "OK" as {{{SINGLE-QUOTE}}}MessageBoxButtons{{{SINGLE-QUOTE}}},"Error" as {{{SINGLE-QUOTE}}}MessageBoxIcon{{{SINGLE-QUOTE}}}; Dis_Diagnosis_field.Value := " "; endif; endif; endif; // Calling Event Field Change ;; 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: