maintenance: maintenance: title: SC Visit Transfer ;; filename: SC_Visit_Transfer;; arden: version 2;; version: 4.50;; institution: St Clair;; author: Robert Spence;; specialist: Robert Spence;; date: 2007-03-22;; validation: testing;; library: purpose: Do not allow a patient to be transfered via the SCM application if the starting location is not valid ;; explanation: When a user selects {{{SINGLE-QUOTE}}}OK{{{SINGLE-QUOTE}}} in change location (Confirm Transfer) in the SCM application and the patient is not already in house, a hard stop alert will display Change History Robert 03.29.2007 - Added logic to allow ER to Psych or ER to IRU 03.29.2007 - Also logic for Psych to ER and IRU to ER 03.02.2010 - Addded logic to trap for release of temp and change to new bed DW 12.16.2010 - Added logic for MRSA ordering JML 05.24.2013 - WO #158012 - Restrict transfer from Infusion, OR, and FBC. STH 04.14.2016 - CSR#: 31256 - Update to allow SDC patients to be transfered to/from all units except IRU and PSYE (there is already logic to handle IRU and PSYE locations). I just commented out the SDC visittype from checking the "bad patient" logic to prevent transfering to/from most locations. {Go-Live 4/25/2016}. JML 02.01.2017 - WO #2545984 - Cancel Discharge events now evoke ClientVisitModify event. Added logic to not process this MLM if previous VisitStatus = DSC. DW 08.29.2017 - CSR# 36214 - SCM AM Registration - Commented out IRU sections - Changed the logic to only fire the "from / to bedded unit" logic on non (clinic or preclinic) patients. - Cleaned up formatting for readability (Ultra edit compare will show many diffreneced even though the differences are harmless formatting changes) - Some routines will not be processed for users other than in the Registration, HIS, and Laboratory departments JML 01.29.2018 - CSR# 26413 - Modified code based on process changes for REG / SCHED activation: - Allow nurses to Check In / Arrive Infusion patients based on a pre-admit location of {{{SINGLE-QUOTE}}}Infusion{{{SINGLE-QUOTE}}}. - Move OR code logic to allow nurses to Check in / Arrive SSOP & Outpatient Surgical patients, using pre-admit location = "OR" and "St. Clair Hospital Anc" JML 02.19.2018 - CSR# 26413 - Modified code to accommodate SDC patient types now registered as OBS patients. Conditionally checking for service type = SSOP to allow nursing to arrive patients into an OR bed. ;; keywords: Transfer ;; knowledge: type: data-driven;; data: log_execution_info:= false; send_alert := "DoNotSend"; stop_Message := "Test"; Hard_Stop:=False; visit_alert := destination { Alert: warning, "Visit Transfer", high, chart,"Visit Transfer", 4005, send_alert, "No Override Allowed" }; visit_transfer:= event{ClientVisitModify User ClientVisit}; // where LocationStatusChange = "Confirm Transfer"}; standard_libs := mlm {{{SINGLE-QUOTE}}}std_include_libs{{{SINGLE-QUOTE}}}; include standard_libs; using "ObjectsPlusXA.SCM.Forms"; using namespace "ObjectsPlusXA.SunriseClinicalManager.Forms"; /* This block executes only when this MLM is called by the editor */ if called_by_editor then visit_obj := read last { ClientVisit: THIS }; EvokingObject := visit_obj; Bk_Loc_Name := "ER-2401"; Bk_Loc_GUid := "4000001081061001"; Bk_VisitStatus := "ADM"; Bk_TypeCode := "Inpatient"; else /* Get the backup Object */ (backup_obj) := read last {ClientVisit: Backup REFERENCING EvokingObject}; (Bk_Loc_Name, Bk_Loc_GUID, Bk_VisitStatus,Bk_TypeCode,Bk_TemporaryLocation, Bk_ServiceGuid) := read last {ClientVisit: CurrentLocation,CurrentLocationGUID,VisitStatus,TypeCode, TemporaryLocation, ServiceGUID REFERENCING backup_obj}; endif; /* Get the ended with data */ (To_Loc_Name,To_Loc_GUID,To_VisitStatus,To_TypeCode,To_TemporaryLocation,VisitGuid) := read last {ClientVisit: CurrentLocation,CurrentLocationGUID,VisitStatus,TypeCode,TemporaryLocation,guid REFERENCING EvokingObject}; Temp_Loc_Prob:=False; badPatient := False; (UserGUID ) := read last { UserInfo: GUID }; // Determine if the user is from Registration, HIS, or Laboratory. These users will not recieve the hard stop related to some sections of the MLM. (UserDepartment) := read last {" select ou.name from CV3User u with (nolock) join cv3organizationalunit ou on ou.guid = u.orgunitguid where " || UserGuid || " = u.guid " }; (PatientRegistration_Service) := read last { "SELECT s.Description FROM CV3Service s WITH (NOLOCK) where s.GUID = " || SQL(Bk_ServiceGuid) }; if (UserDepartment = "Registration Department" or UserDepartment = "Laboratory" or UserDepartment = "Eclipsys Corporation") then UserDepartmentAlertOverride := true; else UserDepartmentAlertOverride := false; endif; //If ((Bk_Loc_Name = To_Loc_Name) OR (Bk_VisitStatus = "DSC"))// or (To_Loc_Name matches pattern "Room%")) If ( ( Bk_Loc_Name = To_Loc_Name ) OR ( Bk_VisitStatus = "DSC" ) ) then Hard_Stop := False; // This insures that the location is the only change here. else // Gather Room Lists // IRU_Room_List := read {"select name from Cv3Location where name like {{{SINGLE-QUOTE}}}IRU%{{{SINGLE-QUOTE}}} and IsClientLocation = 1 and TypeCode = {{{SINGLE-QUOTE}}}Bed{{{SINGLE-QUOTE}}} order by name "}; Psych_Room_List := read {"select name from Cv3Location where name like {{{SINGLE-QUOTE}}}Psy%{{{SINGLE-QUOTE}}} and IsClientLocation = 1 and TypeCode = {{{SINGLE-QUOTE}}}Bed{{{SINGLE-QUOTE}}} order by name "}; ER_Room_List := read {"select name from Cv3Location where name like {{{SINGLE-QUOTE}}}ER-%{{{SINGLE-QUOTE}}} and IsClientLocation = 1 and TypeCode = {{{SINGLE-QUOTE}}}Bed{{{SINGLE-QUOTE}}} order by name "}; FBC_Room_List := read {"SELECT Name FROM CV3Location WHERE Name LIKE {{{SINGLE-QUOTE}}}FBC-%{{{SINGLE-QUOTE}}} AND IsClientLocation = 1 AND TypeCode = {{{SINGLE-QUOTE}}}Bed{{{SINGLE-QUOTE}}} ORDER BY Name"}; INFUSION_Room_List := read {"SELECT Name FROM CV3Location WHERE Name LIKE {{{SINGLE-QUOTE}}}INFUS-%{{{SINGLE-QUOTE}}}AND IsClientLocation = 1 AND TypeCode = {{{SINGLE-QUOTE}}}Bed{{{SINGLE-QUOTE}}} ORDER BY Name "}; OR_Room_List := read {"SELECT Name FROM CV3Location WHERE Name LIKE {{{SINGLE-QUOTE}}}OR-%{{{SINGLE-QUOTE}}} AND IsClientLocation = 1 AND TypeCode = {{{SINGLE-QUOTE}}}Bed{{{SINGLE-QUOTE}}} ORDER BY Name "}; // Determine backup (prior) visit status If Bk_VisitStatus = "PRE" then Bk_VisitStatus := "Pre-Admit"; elseif Bk_VisitStatus = "DSC" then Bk_VisitStatus := "Discharged"; elseif Bk_VisitStatus = "CLS" then Bk_VisitStatus := "Closed"; elseif Bk_VisitStatus = "ADM" then Bk_VisitStatus := "Admitted"; endif; /* // Keep IRU In IRU (Except ED) If (Bk_Loc_Name in IRU_Room_List) and (To_Loc_Name not in IRU_Room_List) and (To_Loc_Name Not in ER_Room_List) then Hard_Stop := True; Stop_Message := "directly from an IRU bed to another unit" || "\n" || "You must discharge and readmit the patient " || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\n" || "You are attempting to transfer to:- " || To_Loc_Name; endif; If (Bk_Loc_Name Not in IRU_Room_List) and (To_Loc_Name in IRU_Room_List) and (Bk_Loc_Name Not in ER_Room_List) then Hard_Stop := True; Stop_Message := "directly from this unit to an IRU bed" || "\n" || "You must discharge and readmit the patient " || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\n" || "You are attempting to transfer to:- " || To_Loc_Name; endif; */ // Keep Psych In Psych (Except ED) // From Psych If (Bk_Loc_Name in Psych_Room_List) and (To_Loc_Name not in Psych_Room_List) and (To_Loc_Name Not in ER_Room_List) then Hard_Stop := True; Stop_Message := "directly from a Behavioral Health bed to another unit" || "\n" || "You must discharge and readmit the patient " || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\n" || "You are attempting to transfer to:- " || To_Loc_Name; endif; // To Psych If (Bk_Loc_Name Not in Psych_Room_List) and (To_Loc_Name in Psych_Room_List) and (Bk_Loc_Name Not in ER_Room_List) then Hard_Stop := True; Stop_Message := "directly from this unit to a Behavioral Health bed" || "\n" || "You must discharge and readmit the patient " || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\n" || "You are attempting to transfer to:- " || To_Loc_Name; endif; If (Bk_TypeCode = "Clinic" OR To_Typecode = "Clinic") then badPatient := True; endif; If (Bk_TypeCode = "Pre Clinic" or To_Typecode = "Pre Clinic") then badPatient := True; endif; // Clinic or Pre Clinic patients If (badPatient = True) then // Keep FBC In FBC (Except ED) // From FBC If (Bk_Loc_Name IN FBC_Room_List) AND (To_Loc_Name NOT IN FBC_Room_List) and (To_Loc_Name NOT IN ER_Room_List) then Hard_Stop := True; Stop_Message := "as a " || Bk_Typecode || " patient directly from an FBC bed to another unit" || "\n" || "You must discharge and readmit the patient " || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\n" || "You are attempting to transfer to:- " || To_Loc_Name; endif; // To FBC If (Bk_Loc_Name NOT IN FBC_Room_List) AND (To_Loc_Name IN FBC_Room_List) AND (Bk_Loc_Name NOT IN ER_Room_List) then Hard_Stop := True; Stop_Message := "as a " || To_Typecode || " patient directly from this unit to an FBC bed" || "\n" || "You must discharge and readmit the patient " || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\n" || "You are attempting to transfer to:- " || To_Loc_Name; endif; // Keep Infusion In Infusion (Except ED) // From Infusion If (Bk_Loc_Name IN INFUSION_Room_List) AND (To_Loc_Name NOT IN INFUSION_Room_List) AND (To_Loc_Name NOT IN ER_Room_List) then Hard_Stop := True; Stop_Message := "as a " || Bk_Typecode || " patient directly from an Infusion bed to another unit" || "\n" || "You must discharge and readmit the patient " || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\n" || "You are attempting to transfer to:- " || To_Loc_Name; Endif; // To Infusion If (Bk_Loc_Name NOT IN INFUSION_Room_List) AND (Bk_Loc_Name <> "Infusion") AND (To_Loc_Name IN INFUSION_Room_List) AND (Bk_Loc_Name NOT IN ER_Room_List) then Hard_Stop := True; Stop_Message := "as a " || Bk_Typecode || " patient directly from this unit to an Infusion bed" || "\n" || "You must discharge and readmit the patient " || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\n" || "You are attempting to transfer to:- " || To_Loc_Name; Endif; // Do not allow Clinic or Pre Clinic patients transferred out of ED to any bed If (Bk_Loc_Name IN ER_Room_List) AND (To_Loc_Name NOT IN ER_Room_List) then Hard_Stop := True; Stop_Message := "as a " || Bk_Typecode || " patient directly from an ER inpatient bed to another unit" || "\n" || "Please contact Registration." || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\nYou are attempting to transfer to:- " || To_Loc_Name; Endif; //Do not allow Clinic or Pre Clinic patients transferred in and out of OR If (Bk_Loc_Name IN OR_Room_List) AND (To_Loc_Name NOT IN OR_Room_List) AND (To_Loc_Name NOT IN ER_Room_List) then Hard_Stop := True; Stop_Message := "as a " || Bk_Typecode || " patient directly from an OR bed to another unit" || "\n" || "You must discharge and readmit the patient " || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\n" || "You are attempting to transfer to:- " || To_Loc_Name; Endif; If (Bk_Loc_Name NOT IN OR_Room_List) AND ( Bk_Loc_Name <> "OR" AND Bk_Loc_Name <> "St. Clair Hospital Anc" ) AND (To_Loc_Name IN OR_Room_List) AND (Bk_Loc_Name NOT IN ER_Room_List) then Hard_Stop := True; Stop_Message := "as a " || Bk_Typecode || " patient directly from this unit to an OR bed" || "\n" || "You must discharge and readmit the patient " || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\n" || "You are attempting to transfer to:- " || To_Loc_Name; Endif; else // Not a clinic or pre clinic //CSR 26413: Build in exception case for SDC and outpatient surgical //TypeCode = SDC, VisitStatus = PRE, Bk_Loc_Name = OR //TypeCode = SDC, VisitStatus = PRE, Bk_Loc_Name = St. Clair Hospital Anc if ( Bk_TypeCode = "SDC" OR PatientRegistration_Service = "SSOP" OR ( Bk_TypeCode = "Inpatient" AND Bk_Loc_Name = "OR" ) ) then // Keep OR In OR (Except ED) // To OR If (Bk_Loc_Name NOT IN OR_Room_List) AND ( Bk_Loc_Name <> "OR" AND Bk_Loc_Name <> "St. Clair Hospital Anc" ) AND (To_Loc_Name IN OR_Room_List) AND (Bk_Loc_Name NOT IN ER_Room_List) then Hard_Stop := True; Stop_Message := "as a " || Bk_Typecode || " patient directly from this unit to an OR bed" || "\n" || "You must discharge and readmit the patient " || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name|| "\n" || "You are attempting to transfer to:- " || To_Loc_Name; Endif; //All other cases where TypeCode <> Clinic or Pre-Clinic else // Is the FROM location a bed? exist_bedded := read last {"select name from Cv3Location where LocnGrpGUID= " || SQL(Bk_Loc_GUID) || " and TypeCode = {{{SINGLE-QUOTE}}}Bed{{{SINGLE-QUOTE}}} and IsClientLocation = 1 and Name= " || SQL(Bk_Loc_Name) }; If exist exist_bedded then test:=True; else Hard_Stop := True; Stop_Message := "because this patient is not currently assigned to a bed" || "\n" || "Please verify you have selected the correct visit" || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name || "\n" || "Current patient type is:- " || Bk_TypeCode; endif; // Is the TO location a bed? To_exist_bedded := read last {"select name from Cv3Location where LocnGrpGUID= " || SQL(To_Loc_GUID) || " and TypeCode = {{{SINGLE-QUOTE}}}Bed{{{SINGLE-QUOTE}}} and IsClientLocation = 1 and Name= " || SQL(To_Loc_Name) }; If exist To_exist_bedded then test:=True; else Hard_Stop := True; Stop_Message := "to an invalid location" || "\n\n" || "You are attempting to transfer to:- " || To_Loc_Name ; endif; endif; //Exception case for Surgical Patients (OPSU) Endif; // Is this a clinic or preclinic ? // Is the Patient Admitted? /* If BK_VisitStatus <> "Admitted" then Hard_Stop :=True; Stop_Message := "because this patient is not currently admitted to the hospital" || "\n" || "Please verify you have selected the correct visit" || "\n\n" || "Current Patient Location is:- " || Bk_Loc_Name || "\n" || "Current Visit Status is:- " || Bk_VisitStatus ; endif; */ // Now add the extra for temporary location issue with 5.0 SP3 03/02/2010 if Hard_Stop = false then if Bk_TemporaryLocation is null then Hard_Stop := false; else Hard_Stop := true; Stop_Message := "{{+R}}You may not clear the Temporary Location {{+B}}" || "AND{{-B}} transfer to a New Location Bed Assignment in one step" || "\n\n" || "Please remove the New Location Bed Assignment and Click OK. Then " || "come back and transfer to the New Location Bed Assignment" ; Temp_Loc_Prob:=True; endif; endif; endif; // If ((Bk_Loc_Name = To_Loc_Name) OR (Bk_VisitStatus = "DSC")) if Temp_Loc_Prob = False then Stop_Message:= "You may not transfer this patient " || Stop_Message ; endif; // Added for MRSA Project (ClientVisitGuid, ChartGuid, ClientGuid, CurrentLocation, VisitStatus) := read last {ClientVisit: GUID, ChartGUID, ClientGUID, CurrentLocation, VisitStatus }; (UserGUID ) := read last { UserInfo: GUID }; MRSA_Rules_MLM := mlm {{{SINGLE-QUOTE}}}SCH_Func_MRSA_Order{{{SINGLE-QUOTE}}}; (ScreeningUnit, OrderedToday, OrderedWithin3, Positivescreen, SignificantDTM, StatusCode, ResultValue, MRSAHistory, NursingHomeResidency, AntiInfectivewithin7) := call MRSA_Rules_MLM with (ClientVisitGuid, ChartGuid, ClientGuid, CurrentLocation); If AntiInfectivewithin7 = "Yes" then ModifierVariable := "Ordered Per Protocol"; else ModifierVariable := "MRSA Screen Antibiotics"; endif; FromUnit:= Substring (find "-" in string Bk_Loc_Name)-1 CHARACTERS From Bk_Loc_Name; ToUnit := Substring (find "-" in string To_Loc_Name)-1 CHARACTERS From To_Loc_Name; If FromUnit in ("ICU","CVSU","IRU","5A","5E","6E","5G") then FromScreeningUnit := "Yes"; else FromScreeningUnit := "No"; endif; // Override the ScreeningUnit value attained from the called MLM which is not the "to unit" but is the "from unit" If ToUnit in ("ICU","CVSU","IRU","5A","5E","6E","5G") then ScreeningUnit := "Yes"; else ScreeningUnit := "No"; endif; If VisitStatus = "Adm" and (ScreeningUnit = "Yes" or FromScreeningUnit = "Yes") and FromUnit <> ToUnit and orderedtoday = "No" and Positivescreen = "No" and orderedwithin3 = "No" then Proceed := "Yes"; else Proceed := "No"; endif; SessionType := "Standard"; SessionReason := ""; RequestingSource := ""; user_IDType := "Edstan Number (physician)"; order_Creation_Reason := "From Protocol"; client_visit_obj := call {{{SINGLE-QUOTE}}}ClientVisit{{{SINGLE-QUOTE}}}.FindByPrimaryKey with ((ClientVisitGuid as number) as {{{SINGLE-QUOTE}}}Int64{{{SINGLE-QUOTE}}}) ; // user_IDCode := read last {"SELECT IDCode FROM CV3User " || " where GUID = " || UserGUID}; user_IDCode := "infectioncontrol"; RequestingCareProvider_obj := call {{{SINGLE-QUOTE}}}CareProvider{{{SINGLE-QUOTE}}}.FindById with ( user_IDType, (user_IDCode as STRING) ); location_guid := read last {"SELECT CurrentLocationGUID FROM CV3ClientVisit where ClientGUID = " || ClientGUID}; location_obj := call {{{SINGLE-QUOTE}}}Location{{{SINGLE-QUOTE}}}.FindByPrimaryKey with ((location_guid as number) as {{{SINGLE-QUOTE}}}Int64{{{SINGLE-QUOTE}}}); ;; evoke: visit_transfer ; ;; logic: // conclude Hard_Stop; conclude true; ;; action: // MRSA Ordering Change if Hard_Stop = true and UserDepartmentAlertOverride = false then write Stop_Message at visit_alert; else if Proceed = "Yes" then try Catalog_Item_Name := "Nasal Screen for MRSA (Infection Control)"; Catalog_Item_Modifier := ModifierVariable; Catalog_Item_Version := ""; Laboratory_catalog_item := call {{{SINGLE-QUOTE}}}OrderCatalogMasterItem{{{SINGLE-QUOTE}}}.FindByName with Catalog_Item_Name; Parent_DiagnosticOrder_obj := call {{{SINGLE-QUOTE}}}DiagnosticOrder{{{SINGLE-QUOTE}}}.CreateDiagnosticOrder with client_visit_obj, // ClientVisit ObjectsPlus object Laboratory_catalog_item, // OrderCatalogMasterItem ObjectsPlus object Catalog_Item_Modifier, // string ItemNameModifier Catalog_Item_Version, // string ItemNameModifierVersion order_Creation_Reason, // string CreateReason RequestingCareProvider_obj , // RequestedBy ObjectsPlus object RequestingSource, // string RequestedBySource (must be in dictionary) SessionType, // string SessionType SessionReason, // string SessionReason location_obj, // Location ReleaseLocGrpID "Always" as {{{SINGLE-QUOTE}}}AvailabilityOverride{{{SINGLE-QUOTE}}}; // AvailabilityOverride eAvailabilityOverride if ( Laboratory_catalog_item is NOT NULL ) then void := call Parent_DiagnosticOrder_obj.Save; void := call Parent_DiagnosticOrder_obj.Dispose; void:= call Laboratory_catalog_item.Dispose; Laboratory_catalog_item:= null; endif; endtry; catch Exception ex error_occurred := true; error_message := "{{+R}}New Parent Diagnostic order:{{-R}}\n" || ex.Message || "\n\n"; if ( Laboratory_catalog_item is NOT NULL ) then void:= call Laboratory_catalog_item.Dispose; Laboratory_catalog_item:= null; endif; if ( Parent_DiagnosticOrder_obj is NOT NULL ) then void:= call Parent_DiagnosticOrder_obj.Dispose; Parent_DiagnosticOrder_obj:= null; endif; Parent_DiagnosticOrder_dest := null; endcatch; endif; endif; ;; end: