Files
St.Clair/MLMStripper/bin/Debug/FORM/FORM_ANTIBIOTIC_SCHEDULING.mlm

748 lines
36 KiB
Plaintext

maintenance:
title: Antibiotic Scheduling;;
mlmname: FORM_Antibiotic_Scheduling;;
arden: version 2;;
version: 5.50;;
institution: St Clair;;
author: Teresa Spicuzza;;
specialist: Don Warnick;;
date: 2014-02-11;;
validation: testing;;
library:
purpose: Automatic Medication Scheduling
;;
explanation: The MLM will select a schedule for an medication based upon the last dose of the prior similar medication
Change history
02.11.2014 DW CSR# 32133 Automatic Medication Scheduling
05.20.2016 JML CSR# 34091 Define exception case when antibiotic scheduling should not run
07.19.2016 BB CSR# 33588 FBC Admission Order set has its own set of rules for Antibiotic scheduling, so this MLM logic
needs to be excluded from CSR#33588 (MLM: FORM_SET_FBC_ADMISSION_ORDERS).
09.22.2017 DW HD# 2763521 Corrected an issue with the top of the hour scheuling programming. Orders scheduled for the last quarter of the hours >=45 were scheduling for the following hour
The June 2016 update broke this code
03.13.2018 TMS CSR 34822 Exclusions added for Zosyn extended infusion.
;;
keywords: Automatic Medication Scheduling
;;
knowledge:
type: data-driven;;
data:
// To introduce new medication categories, update PrimaryTherapeuticCatagoriesSupported & ExcludedTherapeuticCatagories
PrimaryTherapeuticCatagoriesSupported := ("anti-infectives");
ExcludedTherapeuticCatagories := ("anti-infectives | antimalarial agents","anti-infectives | antituberculosis agents",
"anti-infectives | antiviral agents","anti-infectives | macrolide derivatives",
"anti-infectives | miscellaneous antibiotics", "anti-infectives | urinary anti-infectives");
// Define the patient sleeping hours (these hours are avioded for PO administration of some drugs)
bedtime := 00;
waketime := 06;
PORoutes := ("Chew","Chewed","Dissolve in Mouth","Gargle","Oral","PO","Swish","Swish and Spit","Swish and Swallow");
standard_libs := MLM {{{SINGLE-QUOTE}}}std_include_libs{{{SINGLE-QUOTE}}};
include standard_libs;
(this_communication,this_form,client_info_obj) := argument;
local_session := cds_session.local;
// Restrict who sees the "valdation" alerts
userguid := this_communication.userguid;
useridcode:= read last {" Select idcode from cv3user with (nolock) where guid = " || SQL(userguid)};
FireOnUser:= ("dwarnicktest","ageorgulistest","dbellissimotest");
worksheetInfo := call {{{SINGLE-QUOTE}}}OrderEntryBatch{{{SINGLE-QUOTE}}}.GetCurrent;
error_message:="";
field_list := this_form.fields;
comm_primary_obj := this_communication.PrimaryObj;
order_set_name := comm_primary_obj.OrderSetName;
order_name := comm_primary_obj.Name;
continue_processing := true;
ClientGuid := this_communication.ClientGUID;
VisitGuid := this_communication.ClientVisitGUID;
ChartGuid := this_communication.ChartGuid;
CallingEvent := this_communication.CallingEvent;
CallingField := this_communication.CallingFieldName;
CurrentMinute:= extract minute NOW;
CurrentHour := extract hour NOW;
NextHour := extract hour NOW + 1;
HourAfterNext:= extract hour NOW + 2;
// GATHER INFORMATION ABOUT THIS ORDER
SCIP := last of (field_list where field_list.DataItemName = "PRX_AntibioticNameforMLM");
SCIPValue := SCIP.Value;
Frequency := last of (field_list where field_list.DataItemName = "frequencycode");
FrequencyValue := Frequency.Value;
Route := last of (field_list where field_list.DataItemName = "orderroutecode");
RouteValue := Route.Value;
RequestedTime:= last of (field_list where field_list.DataItemName = "RequestedTime");
RequestedTimeValue := RequestedTime.value;
RequestedDate:= last of (field_list where field_list.DataItemName = "RequestedDate");
Override_Abx_Scheduling := first of ( field_list WHERE field_list.DataItemName = "PRX_Override_Abx_Scheduling" );
if ( exists Override_Abx_Scheduling ) then
if ( ( CallingEvent = "FieldChange" AND CallingField = "PRX_Override_Abx_Scheduling" ) OR CallingEvent = "FormOpen" or (CallingEvent = "FieldChange" AND Override_Abx_Scheduling.Value = true ) ) then
// if ( ( CallingEvent = "FieldChange" AND CallingField = "PRX_Override_Abx_Scheduling" ) OR CallingEvent = "FormOpen" ) then
if ( Override_Abx_Scheduling.Value = false ) then
continue_processing := true;
elseif ( Override_Abx_Scheduling.Value = true ) then
continue_processing := false;
if order_set_name <> "Family Birth Center Admission" Then //[BB] Added to exclude FBC antibiotics from this scheduling 7/19/16
if ( order_name = "Vancomycin:" ) then
//Determine if vancomycin load dose has been given
( o_vancoLoadExists,
o_vancoLoadReqDtm,
o_vancoAdmin) := READ LAST { "SELECT 1, CASE WHEN ot.TaskStatusCode = {{{SINGLE-QUOTE}}}Performed{{{SINGLE-QUOTE}}} THEN ot.PerformedFromDtm"
|| " ELSE o.RequestedDtm END"
|| " 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 o.FrequencyCode IN ({{{SINGLE-QUOTE}}}Once{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}STAT{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Now{{{SINGLE-QUOTE}}})"
|| " AND cv.ClientGUID = " || SQL(ClientGuid)
|| " AND cv.GUID = " || SQL(VisitGuid)
|| " AND cv.ChartGUID = " || SQL(ChartGuid)
|| " AND DateDiff(hh, o.Entered, GETDATE()) <= 48"
|| " AND (o.OrderStatusLevelNum > 15"
|| " AND o.OrderStatusLevelNum NOT IN ({{{SINGLE-QUOTE}}}69{{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}70{{{SINGLE-QUOTE}}}))"
|| " order by o.Entered ASC" };
endif;
if ( FrequencyValue.FrequencySummary matches pattern "Q%H" ) and (order_name <> "Piperacillin/Tazobactam:" and order_name <> "Piperacillin/Tazobactam;" ) then
if ( order_name = "Vancomycin:" ) then
if ( not exists o_vancoLoadExists ) then
spanhourfromnow := (now + 30 minute);
else
spanhourfromnow := ( ( o_vancoLoadReqDtm as Time ) + 30 minute );
endif;
else
spanhourfromnow := (now + 30 minute);
endif;
frequencyNum := Substring 2 Characters STARTING AT 2 From ( FrequencyValue.FrequencySummary as string );
plusminus := (frequencyNum as number);
newstarttime := (spanhourfromnow as time) + (plusminus hour) ;
newhr := extract hour newstarttime;
newhr := newhr formatted with "%2.2d";
newyr := extract year newstarttime;
newmn := extract month newstarttime;
newmn := newmn formatted with "%2.2d";
newdd := extract day newstarttime;
newdd := newdd formatted with "%2.2d";
filldate := (newyr || "-" || newmn || "-" || newdd || " 00:00") as time;
filltime := newhr || ":00";
hourtest := filltime;
RequestedDate.Value := filldate;
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue := filltime;
local_session.SessionVancoTroughScheduledDate := RequestedDate.Value;
local_session.SessionVancoTroughScheduledTime := RequestedTime.Value;
endif;
endif; //[BB] Added to exclude antibiotics from this scheduling 7/19/16
endif;
endif;
endif;
if ( continue_processing = true ) then
If (CallingEvent = "FieldChange" and ( CallingField = "frequencycode" OR CallingField = "PRX_Override_Abx_Scheduling" ) ) or CallingEvent = "FormOpen" then
// Gather information about the drug
(DrugKey, TherapeuticCategory, ExcludedClassType, PrimaryTherapeuticCategory) := read last
{
" select dm.DrugKey, ocmi.TherapeuticCategory , "
|| " ( select top 1 ctv.Value "
|| " from cv3catalogclasstypevalue ctv with (nolock) "
|| " join CV3ClassType ct on ct.guid = ctv.ClassTypeGUID and ct.code = {{{SINGLE-QUOTE}}}PRX_AutoSched_Exclude_for_MLM{{{SINGLE-QUOTE}}} and ct.UserDictionaryCode = {{{SINGLE-QUOTE}}}Medication_Auto_Scheduling{{{SINGLE-QUOTE}}} "
|| " where ctv.Value = {{{SINGLE-QUOTE}}}Yes{{{SINGLE-QUOTE}}} and ctv.catalogmasterguid = " || this_communication.ItemID || " ) "
|| " ,case when CHARINDEX ({{{SINGLE-QUOTE}}}|{{{SINGLE-QUOTE}}},ocmi.TherapeuticCategory) > 0 "
|| " then substring (ocmi.TherapeuticCategory, 1, CHARINDEX ({{{SINGLE-QUOTE}}}|{{{SINGLE-QUOTE}}},ocmi.TherapeuticCategory)-2)"
|| " else ocmi.TherapeuticCategory "
|| " end "
|| " from CV3OrderCatalogMasterItem ocmi with (nolock) "
|| " join cv3drugmapping dm with (nolock) on dm.catalogitemguid = ocmi.guid "
|| " where ocmi.guid = " || this_communication.ItemID || " "
};
// Determine if it is Vancomycin
If DrugKey = "D00125" then
Vancomycin := "Yes";
else
Vancomycin := "No";
endif;
// Gather information about the frequency
// Determine Frequency Interval ( "Q3H" = "3" & "hr(s)" )
(FrequencyInterval,FrequencyTimeUOM) := read last
{
" select timefromvalue,TimeUom from CV3Frequency with (nolock) "
|| " where code = {{{SINGLE-QUOTE}}}" || FrequencyValue.FrequencySummary || "{{{SINGLE-QUOTE}}}"
};
// Determine if it is a QxH Frequency
If FrequencyValue.FrequencySummary matches pattern "Q%H" then
FrequencyQxH := "Yes";
else
FrequencyQxH := "No";
endif;
// Determine Schedule Type ("A" = "Fixed" start time...BID,QHS etc... "S" = "Variable" start time....Q4H, Q8H etc...)
ScheduleType := read last
{
" select case when SUBSTRING(value,CHARINDEX({{{SINGLE-QUOTE}}}|{{{SINGLE-QUOTE}}},Value)+1,LEN(1)) = {{{SINGLE-QUOTE}}}A{{{SINGLE-QUOTE}}} then {{{SINGLE-QUOTE}}}Fixed{{{SINGLE-QUOTE}}} else {{{SINGLE-QUOTE}}}Variable{{{SINGLE-QUOTE}}} end "
|| " from CV3UserDictionaryValue with (nolock) "
|| " WHERE UserDictionaryCode = {{{SINGLE-QUOTE}}}PRX_Dosing Frequency{{{SINGLE-QUOTE}}} AND Active = 1 AND Value like {{{SINGLE-QUOTE}}}" || FrequencyValue.FrequencySummary || "%{{{SINGLE-QUOTE}}} "
};
// Convert the Frequency Code to Doses Per Day
(DosesPerDay) := read last
{
" select count (fsd.ScheduledTime) from CV3CodedFreqTranslation cft with (nolock) "
|| " join CV3FixedScheduleDefinition fsd with (nolock) on fsd.ParentGUID = cft.guid "
|| " where cft.FrequencyCode = {{{SINGLE-QUOTE}}}" || FrequencyValue.FrequencySummary || "{{{SINGLE-QUOTE}}} and "
|| " FrequencyClass = {{{SINGLE-QUOTE}}}<Default>{{{SINGLE-QUOTE}}} and cft.active = 1 "
};
// For the selected Frequency, find the first dose of the day and next scheduled dose today
(NextScheduledDoseTomorrow,NextScheduledDoseToday) := read last
{
" select top 1 "
|| " (select top 1 fsdx.ScheduledTime from CV3FixedScheduleDefinition fsdx with (nolock) where fsdx.ParentGUID = cft.guid "
|| " order by fsdx.ScheduledTime), "
|| " (select top 1 fsdy.ScheduledTime from CV3FixedScheduleDefinition fsdy with (nolock) where fsdy.ParentGUID = cft.guid "
|| " and fsdy.ScheduledTime > REPLACE(CONVERT(VARCHAR(5), GETDATE(), 108), {{{SINGLE-QUOTE}}}:{{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}{{{SINGLE-QUOTE}}}) "
|| " order by fsdy.ScheduledTime ) "
|| " from CV3CodedFreqTranslation cft with (nolock) "
|| " join CV3FixedScheduleDefinition fsd with (nolock) on fsd.ParentGUID = cft.guid "
|| " where cft.FrequencyCode = {{{SINGLE-QUOTE}}}" || FrequencyValue.FrequencySummary || "{{{SINGLE-QUOTE}}} and FrequencyClass = {{{SINGLE-QUOTE}}}<Default>{{{SINGLE-QUOTE}}} and cft.active = 1 "
};
// If there are no more scheduled doses for today, use the first scheduled dose tomorrow
If NextScheduledDoseToday is not null then
NextScheduledDoseTime:= NextScheduledDoseToday;
NextScheduledDoseDay := "today";
NextScheduledDoseDate:= (Now) FORMATTED WITH "%.2t";
else
NextScheduledDoseTime:= NextScheduledDoseTomorrow;
NextScheduledDoseDay := "tomorrow";
NextScheduledDoseDate:= (Now + 1 day) FORMATTED WITH "%.2t";
endif;
NextScheduledDoseTime:= NextScheduledDoseTime formatted with "%4.4d"; // Zero Pad to 4 characters (900 becomes 0900)
NextScheduledDoseTime:= (SUBSTRING 2 CHARACTERS STARTING AT 1 FROM NextScheduledDoseTime) || ":" || // hours
(SUBSTRING 2 CHARACTERS STARTING AT 3 FROM NextScheduledDoseTime); // minutes
If TherapeuticCategory in ExcludedTherapeuticCatagories then
ExcludedTherapeuticCategory := "Yes";
else
ExcludedTherapeuticCategory := "No";
endif;
// Proceed if this is a supported Theraputic Category and not individually flagged for Exclusion
// and not a "one-time" order
// and not in a Hold session
// and not a SCIP drug
If ( PrimaryTherapeuticCategory in PrimaryTherapeuticCatagoriesSupported and
( ExcludedClassType = "No" or ExcludedClassType is null ) and
FrequencyInterval is not null and
ScheduleType is not null and
worksheetinfo.sessiontype <> "Hold" and
SCIPValue is null ) then
// GATHER INFORMATION ABOUT MOST RECENTLY ADMINISTERED ORDER (past 2 days) OF THE SAME CATEGORY
(ExistingOrderLastGiven, ExistingOrderFrequency, ExistingOrderHoursSinceGiven,
ExistingOrderName, ExistingOrderTherapeuticCategory, ExistingOrderDrugKey,
ExistingRoute, ExistingNextTaskPending, ExistingNextTaskCanceled) := read last
{
" select oto.performedfromdtm, o.FrequencyCode, datediff (HH, oto.performedfromdtm, getdate()), "
|| " o.name, ocmi.TherapeuticCategory, dm.DrugKey, ot.OrderRoute "
|| " ,(select top 1 oto2.SignificantDtm from cv3ordertaskoccurrence oto2 with (nolock) "
|| " where oto2.clientguid = ot.clientguid and oto2.orderguid = o.guid and oto2.ordertaskguid = ot.guid "
|| " and oto2.SignificantDtm > getdate()-2 and oto2.taskstatuscode = {{{SINGLE-QUOTE}}}Pending{{{SINGLE-QUOTE}}}) "
|| " ,(select top 1 oto2.SignificantDtm from cv3ordertaskoccurrence oto2 with (nolock) "
|| " where oto2.clientguid = ot.clientguid and oto2.orderguid = o.guid and oto2.ordertaskguid = ot.guid "
|| " and oto2.SignificantDtm > getdate()-2 and oto2.taskstatuscode = {{{SINGLE-QUOTE}}}Canceled{{{SINGLE-QUOTE}}}) "
|| " from cv3ordercatalogmasteritem ocmi with (nolock) "
|| " join cv3drugmapping dm with (nolock) on dm.catalogitemguid = ocmi.guid "
|| " join cv3order o with (nolock)on o.ordercatalogmasteritemguid = ocmi.guid "
|| " and o.ClientGUID = " || ClientGuid || " "
|| " and o.TypeCode = {{{SINGLE-QUOTE}}}Medication{{{SINGLE-QUOTE}}} and ocmi.TherapeuticCategory = {{{SINGLE-QUOTE}}}" || TherapeuticCategory || "{{{SINGLE-QUOTE}}} "
|| " join cv3ordertask ot with (nolock) on ot.clientguid = o.clientguid and ot.orderguid = o.guid "
|| " join cv3ordertaskoccurrence as oto with (nolock) on oto.clientguid = ot.clientguid and oto.orderguid = ot.orderguid "
|| " and oto.ordertaskguid = ot.guid and oto.SignificantDtm > getdate()-2 and oto.taskstatuscode = {{{SINGLE-QUOTE}}}Performed{{{SINGLE-QUOTE}}} "
|| " order by oto.performedfromdtm "
};
(ExistingOrderInterval) := read last {"select timefromvalue from CV3Frequency with (nolock) where code = {{{SINGLE-QUOTE}}}" || ExistingOrderFrequency || "{{{SINGLE-QUOTE}}}"};
ExistingNextTaskPendingDate:= ExistingNextTaskPending FORMATTED WITH "%.2t";
ExistingNextTaskPendingTime:= extract hour ExistingNextTaskPending || ":" || extract minute ExistingNextTaskPending;
ExistingNextTaskCanceledDate:= ExistingNextTaskCanceled FORMATTED WITH "%.2t";
ExistingNextTaskCanceledTime:= extract hour ExistingNextTaskCanceled || ":" || extract minute ExistingNextTaskCanceled;
// Determine how the order compares to the most recently charted order of the same therapeutic category
CategoryMatch := "No";
DrugMatch := "No";
FrequencyMatch:= "No";
RouteMatch := "No";
if TherapeuticCategory = ExistingOrderTherapeuticCategory then
CategoryMatch := "Yes";
else
CategoryMatch := "No";
endif;
if DrugKey = ExistingOrderDrugKey then
DrugMatch := "Yes";
else
DrugMatch := "No";
endif;
if FrequencyValue.FrequencySummary = ExistingOrderFrequency then
FrequencyMatch := "Yes";
else
FrequencyMatch := "No";
endif;
if RouteValue = ExistingRoute then
RouteMatch := "Yes";
else
RouteMatch := "No";
endif;
// SCENARIOS
If CategoryMatch = "No" then
// Different Category (no drug of the same category in the past 2 days)
Scenario := "6";
If ScheduleType = "Variable" then
// Variable Start Time
TargetHour := NextHour;
TargetDate := NOW;
else
// Fixed Start Time
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue := NextScheduledDoseTime;
RequestedDate.Value := NextScheduledDoseDate;
endif;
else
// Same Category
If DrugMatch = "Yes" then
// Same Category / Same Drug
If Vancomycin = "No" or (Vancomycin = "Yes" and RouteMatch = "Yes") then
// Same Category / Same Drug / Not Vanco Same Route
If FrequencyMatch = "Yes" then
// Same Category / Same Drug / Not Vanco Same Route / Same Frequency
Scenario := "4";
If ExistingNextTaskPending is not null then
TargetHour := extract hour ExistingNextTaskPending;
TargetDate := ExistingNextTaskPending;
else
TargetHour := extract hour ExistingNextTaskCanceled;
TargetDate := ExistingNextTaskCanceled;
endif;
else
// Same Category / Same Drug / Not Vanco Same Route / Different Frequency
If FrequencyQxH = "Yes" then
// Same Category / Same Drug / Not Vanco Same Route / Different Frequency / QxH
Scenario := "3&5";
TargetHour := extract hour ExistingOrderLastGiven + FrequencyInterval;
TargetDate := ExistingOrderLastGiven;
else
// Same Category / Same Drug / Not Vanco Same Route / Different Frequency / non-QxH
If DosesPerDay <= 2 then
// Same Category / Same Drug / Not Vanco Same Route / Different Frequency / non-QxH / < 2 doses/day
Scenario := "8";
dlg_result := call {{{SINGLE-QUOTE}}}MessageBox{{{SINGLE-QUOTE}}}.Show with
"\n\nThis medication was last given on " || (SUBSTRING 10 CHARACTERS STARTING AT 1 FROM (ExistingOrderLastGiven as string)) ||
" at" || (SUBSTRING 6 CHARACTERS STARTING AT 11 FROM (ExistingOrderLastGiven as string)) || "." ||
"\n\n\nThe next scheduled administration time will be " || NextScheduledDoseDay || " at " || NextScheduledDoseTime || "." ||
"\n\n\nYour judgement is required for scheduling. " ||
"\n\n\nPlease select an appropriate start time.","Start Time", "OK" as {{{SINGLE-QUOTE}}}MessageBoxButtons{{{SINGLE-QUOTE}}},"Question" as {{{SINGLE-QUOTE}}}MessageBoxIcon{{{SINGLE-QUOTE}}};
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue := NextScheduledDoseTime;
RequestedDate.Value := NextScheduledDoseDate;
else
// Same Category / Same Drug / Not Vanco Same Route / Different Frequency / non-QxH / > 2 doses/day
Scenario := "7";
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue := NextScheduledDoseTime;
RequestedDate.Value := NextScheduledDoseDate;
endif; // Doses per Day < 2 >
endif; // FrequencyQxH
endif; // Frequency Match
else
// Same Category / Same Drug / Vanco Same Route
Scenario := "10";
If ScheduleType = "Variable" then
// Variable Start Time
TargetHour := NextHour;
TargetDate := NOW;
else
// Fixed Start Time
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue := NextScheduledDoseTime;
RequestedDate.Value := NextScheduledDoseDate;
endif;
endif; // Vancomycin
else
// Same Category / Different Drug
If ExcludedTherapeuticCategory = "Yes" then
// Same Category / Different Drug / Excluded Category Type
Scenario := "9";
If ScheduleType = "Variable" then
// Variable Start Time
TargetHour := NextHour;
TargetDate := NOW;
else
// Fixed Start Time
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue := NextScheduledDoseTime;
RequestedDate.Value := NextScheduledDoseDate;
endif;
else
// Same Category / Different Drug / Not an Excluded Category Type
If ExistingOrderInterval is null then
// Same Category / Different Drug / One-Time Dose
if (CallingEvent = "FormOpen" and FrequencyValue.FrequencySummary is not null) or CallingEvent = "FieldChange" then
Scenario := "11";
dlg_result := call {{{SINGLE-QUOTE}}}MessageBox{{{SINGLE-QUOTE}}}.Show with
"\n\n This medication cannot be be auto-scheduled " ||
"\n\n " || ExistingOrderName || " was given on " || (SUBSTRING 10 CHARACTERS STARTING AT 1 FROM (ExistingOrderLastGiven as string)) ||
" at" || (SUBSTRING 6 CHARACTERS STARTING AT 11 FROM (ExistingOrderLastGiven as string)) || "." ||
"\n\n Please enter a start time. " ||
"\n\n " || "\n ","Unable to Auto-Schedule", "OK" as {{{SINGLE-QUOTE}}}MessageBoxButtons{{{SINGLE-QUOTE}}},"Question" as {{{SINGLE-QUOTE}}}MessageBoxIcon{{{SINGLE-QUOTE}}};
RequestedDate.Value := (Now) FORMATTED WITH "%.2t";
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue:= "";
endif;
else
If ExistingOrderHoursSinceGiven > ExistingOrderInterval then
// Same Category / Different Drug / Not One-Time Dose / Outside the Span
Scenario := "2";
If ScheduleType = "Variable" then
// Variable Start Time
TargetHour := NextHour;
TargetDate := NOW;
else
// Fixed Start Time
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue := NextScheduledDoseTime;
RequestedDate.Value := NextScheduledDoseDate;
endif;
else
// Same Category / Different Drug / Not One-Time Dose / Within the Span
If FrequencyQxH = "No" then
// Same Category / Different Drug / Not One-Time Dose / Within the Span / QxH
If DosesPerDay <= 2 then
// Same Category / Different Drug / Not One-Time Dose / Within the Span / non-QxH / < 2 doses/day
Scenario := "18";
dlg_result := call {{{SINGLE-QUOTE}}}MessageBox{{{SINGLE-QUOTE}}}.Show with
"\n\nThis medication was last given on " || (SUBSTRING 10 CHARACTERS STARTING AT 1 FROM (ExistingOrderLastGiven as string)) ||
" at" || (SUBSTRING 6 CHARACTERS STARTING AT 11 FROM (ExistingOrderLastGiven as string)) || "." ||
"\n\n\nThe next scheduled administration time will be " || NextScheduledDoseDay || " at " || NextScheduledDoseTime || "." ||
"\n\n\nYour judgement is required for scheduling. " ||
"\n\n\nPlease select an appropriate start time.","Start Time", "OK" as {{{SINGLE-QUOTE}}}MessageBoxButtons{{{SINGLE-QUOTE}}},"Question" as {{{SINGLE-QUOTE}}}MessageBoxIcon{{{SINGLE-QUOTE}}};
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue := NextScheduledDoseTime;
RequestedDate.Value := NextScheduledDoseDate;
else
// Same Category / Same Drug / Not Vanco Same Route / Different Frequency / non-QxH / > 2 doses/day
Scenario := "17";
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue := NextScheduledDoseTime;
RequestedDate.Value := NextScheduledDoseDate;
endif;
else
Scenario := "1";
If ExistingNextTaskPending is not null then
ExistingNextTaskTime := ExistingNextTaskPendingTime;
ExistingNextTaskDate := ExistingNextTaskPendingDate;
ExistingNextTaskDTM := ExistingNextTaskPending FORMATTED WITH "%.4t";
else
ExistingNextTaskTime := ExistingNextTaskCanceledTime;
ExistingNextTaskDate := ExistingNextTaskCanceledDate;
ExistingNextTaskDTM := ExistingNextTaskCanceled FORMATTED WITH "%.4t";
endif; // Is there a Pending task (if not use next Canceled task)
dlg_result := call {{{SINGLE-QUOTE}}}MessageBox{{{SINGLE-QUOTE}}}.Show with
"\n\n The last dose of {{{SINGLE-QUOTE}}}" || ExistingOrderName || "{{{SINGLE-QUOTE}}}" ||
" was given at " || ExistingOrderLastGiven FORMATTED WITH "%.4t" || "." ||
"\n\n This order will be scheduled to start at " || ExistingNextTaskDTM || "." ||
"\n\n Select YES to continue with this time. " ||
"\n\n Select No to start Now or modify the start time. " || "\n ","Start Time", "YesNo" as {{{SINGLE-QUOTE}}}MessageBoxButtons{{{SINGLE-QUOTE}}},"Question" as {{{SINGLE-QUOTE}}}MessageBoxIcon{{{SINGLE-QUOTE}}};
If (dlg_result as string) = "Yes" then
// Same Category / Different Drug / Not One-Time Dose / Within the Span / "Yes", Start next scheduled
// Scenario 1C
Scenario := Scenario || " C";
CalculatedHour:= extract hour ExistingNextTaskPending;
// Determine if the scheduled start time would cause a bedtime dose
BedTimeDoses:= "";
NextDose := CalculatedHour + FrequencyInterval;
indexList := 1 seqto DosesPerDay;
for i in indexList do
If NextDose >= 24 then NextDose := NextDose -24; endif;
If NextDose >= 48 then NextDose := NextDose -48; endif;
If NextDose < waketime and NextDose > bedtime then
If NextDose < 10 then
BedTimeDose := "0" || NextDose || ":00"; // zero pad if necessary & append minutes
else
BedTimeDose := NextDose || ":00"; // just append minutes
endif;
BedTimeDoses := BedTimeDoses || " " || BedTimeDose; // add it to the list
endif;
NextDose := NextDose + FrequencyInterval;
enddo;
// If a PO bed time dose would result from the automated scheduling, ask the clinician to schedule it themselves
If BedTimeDoses <> "" and RouteValue in PORoutes then
dlg_result := call {{{SINGLE-QUOTE}}}MessageBox{{{SINGLE-QUOTE}}}.Show with
"\n\n Automatic {{{SINGLE-QUOTE}}}start time{{{SINGLE-QUOTE}}} calculation has determined that this medication can be started on " || ExistingNextTaskDate || " at " || CalculatedHour || ":00." ||
"\n\n\nHowever, this would create an administration schedule for a dose to be given " || RouteValue || " at" || BedTimeDoses || " , which falls during the patient{{{SINGLE-QUOTE}}}s bedtime hours." ||
"\n\n\n Your judgement is required for scheduling. " ||
"\n\n\n Please select an appropriate start time " || "\n ","Calculated Start Time Would Create Bed Time Doses ", "OK" as {{{SINGLE-QUOTE}}}MessageBoxButtons{{{SINGLE-QUOTE}}},"Error" as {{{SINGLE-QUOTE}}}MessageBoxIcon{{{SINGLE-QUOTE}}};
RequestedDate.Value := (Now) FORMATTED WITH "%.2t";
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue:= "";
else
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue := ExistingNextTaskTime;
RequestedDate.Value := ExistingNextTaskDate;
endif; // BedTimeDoses <> "" and ExistingRoute = "PO"
else
// Same Category / Different Drug / Not One-Time Dose / Within the Span / "No", Start Now
// Scenario 1 A or B
TargetHour := NextHour;
TargetDate := Now;
endif; // Start Now? (YES or NO)
endif; // Within the Span
endif; // QxH
endif; // One-Time Dose
endif; // Excluded Category
endif; // Drug Match
endif; // Category Match
// SCHEDULED TIME ADJUSTMENTS - for variable start time frequencies
If TargetHour is not null and FrequencyTimeUOM = "hr(s)" then
// Adjust for Calculated Dose Hour greater than 24 (next dose falls after midnight today)
If TargetHour < 24 then
// CalculatedHour := TargetHour formatted with "%2.2d"; 09.22.2017 DW HD# 2763521 This formatting introduced on 6/1/2015 created an issue with the top of the hour >=45 scheuling programming.
CalculatedHour := TargetHour;
ElseIf TargetHour >= 24 and TargetHour < 48 then
CalculatedHour := TargetHour - 24;
TargetDate := TargetDate + 1 day;
ElseIf TargetHour >= 48 then
CalculatedHour := TargetHour - 48;
TargetDate := TargetDate + 2 day;
endif;
// Adjust for Calculated Dose Time that is in the past...begin now (existing med has missed recent doses)
TimeNow := (extract year NOW) FORMATTED WITH "%2.2d" || (extract month NOW) FORMATTED WITH "%2.2d" ||
(extract day NOW) FORMATTED WITH "%2.2d" || (extract hour NOW) FORMATTED WITH "%2.2d" ||
(extract minute NOW) FORMATTED WITH "%2.2d";
TimeScheduled:= (extract year TargetDate) FORMATTED WITH "%2.2d" || (extract month TargetDate) FORMATTED WITH "%2.2d" ||
(extract day TargetDate) FORMATTED WITH "%2.2d" || CalculatedHour FORMATTED WITH "%2.2d" || "00";
if TimeScheduled < TimeNow then
CalculatedHour :=NextHour;
TargetDate := NOW;
endif;
// Adjust for Administration time calculated for < 15 minutes...offset the time by an hour
If CurrentMinute >= 45 and CalculatedHour = (EXTRACT HOUR Now) +1 then
CalculatedHour := CalculatedHour + 1; Scenario := Scenario || " B";
else
CalculatedHour := CalculatedHour ; Scenario := Scenario || " A";
endif;
// The Adjustments could have placed the start time to after midnight....if so, adjust date and hour
If CalculatedHour >= 24 then
CalculatedHour := CalculatedHour - 24;
a := "in calc hour";
TargetDate := TargetDate + 1 day;
endif;
// Format the date and time as required by the form fields
CalculatedTime := CalculatedHour || ":00";
CalculatedDate := TargetDate FORMATTED WITH "%.2t";
// Determine if the scheduled start time would cause a bedtime dose
BedTimeDoses:= "";
NextDose := CalculatedHour + FrequencyInterval;
indexList := 1 seqto DosesPerDay;
for i in indexList do
If NextDose >= 24 then NextDose := NextDose -24; endif;
If NextDose >= 48 then NextDose := NextDose -48; endif;
If NextDose < waketime and NextDose > bedtime then
If NextDose < 10 then
BedTimeDose := "0" || NextDose || ":00"; // zero pad if necessary & append minutes
else
BedTimeDose := NextDose || ":00"; // just append minutes
endif;
BedTimeDoses := BedTimeDoses || " " || BedTimeDose; // add it to the list
endif;
NextDose := NextDose + FrequencyInterval;
enddo;
// If a PO bed time dose would result from the automated scheduling, ask the clinician to schedule it themselves
If BedTimeDoses <> "" and RouteValue in PORoutes then
dlg_result := call {{{SINGLE-QUOTE}}}MessageBox{{{SINGLE-QUOTE}}}.Show with
"\n\n Automatic {{{SINGLE-QUOTE}}}start time{{{SINGLE-QUOTE}}} calculation has determined that this medication can be started on " || CalculatedDate || " at " || CalculatedHour || ":00." ||
"\n\n\nHowever, this would create an administration schedule for a dose to be given " || RouteValue || " at" || BedTimeDoses || " , which falls during the patient{{{SINGLE-QUOTE}}}s bedtime hours." ||
"\n\n\n Your judgement is required for scheduling. " ||
"\n\n\n Please select an appropriate start time " || "\n ","Calculated Start Time Would Create Bed Time Doses ", "OK" as {{{SINGLE-QUOTE}}}MessageBoxButtons{{{SINGLE-QUOTE}}},"Error" as {{{SINGLE-QUOTE}}}MessageBoxIcon{{{SINGLE-QUOTE}}};
RequestedDate.Value := (Now) FORMATTED WITH "%.2t";
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue:= "";
else
RequestedTimeValue.ReqTimeCode := "Scheduled/Start Time";
RequestedTimeValue.ReqTimeValue := CalculatedTime;
RequestedDate.Value := CalculatedDate;
endif; // BedTimeDoses <> "" and ExistingRoute = "PO"
endif; // Target Time (variable hourly shedules)
If useridcode in FireOnUser then
dialogResult := call {{{SINGLE-QUOTE}}}MessageBox{{{SINGLE-QUOTE}}}.Show with
" Select {{{SINGLE-QUOTE}}}YES{{{SINGLE-QUOTE}}} for detailed MLM information", " Scenario " || Scenario,"YESNO" as {{{SINGLE-QUOTE}}}MessageBoxButtons{{{SINGLE-QUOTE}}};
if (dialogResult as string) = "Yes" then
break;
endif;
endif;
else
// Scenario#X - no automtated scheduling (initialize date and time fields...today & no time)
// Re-initialize the time value if the MLM was evoked by a frequency change on a med of the included ther. category
If CallingEvent = "FieldChange" and CallingField = "frequencycode" and
PrimaryTherapeuticCategory in PrimaryTherapeuticCatagoriesSupported and
(ExcludedClassType = "No" or ExcludedClassType is null) then
RequestedTimeValue.ReqTimeCode := "";
RequestedTimeValue.ReqTimeValue:= "";
if (RequestedDate.Value > Now) then
dialogResult := call {{{SINGLE-QUOTE}}}MessageBox{{{SINGLE-QUOTE}}}.Show with "\n Did you intend to schedule this medication for one time on " || RequestedDate.Value FORMATTED WITH "%.2t" || " ?" ||
" \n\n If this is not the intended administration date, please adjust the scheduled date.", " Potential Schedule Conflict ","OK" as {{{SINGLE-QUOTE}}}MessageBoxButtons{{{SINGLE-QUOTE}}};
endif;
endif;
/* Scenario#X */
if useridcode in FireOnUser then
dialogResult := call {{{SINGLE-QUOTE}}}MessageBox{{{SINGLE-QUOTE}}}.Show with
" Select {{{SINGLE-QUOTE}}}YES{{{SINGLE-QUOTE}}} for detailed MLM information","Scenario X ","YESNO" as {{{SINGLE-QUOTE}}}MessageBoxButtons{{{SINGLE-QUOTE}}};
if (dialogResult as string) = "Yes" then
break;
endif;
endif;
endif; // Is this a medication to be processed? (i.e.supported Theraputic Category, flagged for Exclusion etc...)
endif; // If CallingEvent <> "FormOpen"
if ( order_set_name IN ( "Pneumonia Antibiotic", "Skin Antibiotic Inpatient", "Vancomycin Orders") AND order_name = "Vancomycin:" ) then
local_session.SessionVancoTroughScheduledDate := RequestedDate.Value;
local_session.SessionVancoTroughScheduledTime := RequestedTime.Value;
endif;
endif;
;;
evoke:
;;
logic:
conclude true;
;;
action:
return this_communication, this_form;
;;
end: