329 lines
13 KiB
Plaintext
329 lines
13 KiB
Plaintext
maintenance:
|
|
|
|
title: Task Retrievals for Duplicate Task Checking;;
|
|
mlmname: STD_FUNC_TASK_RETRIEVAL;;
|
|
arden: version 2.5;;
|
|
version: 18.4;;
|
|
institution: Allscripts, Standard MLM;;
|
|
author: Allscripts Healthcare Solutions, Inc.;;
|
|
specialist: ;;
|
|
date: 2018-10-26;;
|
|
validation: testing;;
|
|
|
|
/* P r o p r i e t a r y N o t i c e */
|
|
/* Unpublished (c) 2013 - 2018 Allscripts Healthcare, LLC. and/or its affiliates. All Rights Reserved.
|
|
|
|
P r o p r i e t a r y N o t i c e: This software has been provided pursuant to a License Agreement, with
|
|
Allscripts Healthcare, LLC. and/or its affiliates, containing restrictions on its use. This software contains
|
|
valuable trade secrets and proprietary information of Allscripts Healthcare, LLC. and/or its affiliates and is
|
|
protected by trade secret and copyright law. This software may not be copied or distributed in any form or medium,
|
|
disclosed to any third parties, or used in any manner not provided for in said License Agreement except with prior
|
|
written authorization from Allscripts Healthcare, LLC. and/or its affiliates. Notice to U.S. Government Users:
|
|
This software is {{{SINGLE-QUOTE}}}Commercial Computer Software{{{SINGLE-QUOTE}}}.
|
|
|
|
All product names are the trademarks or registered trademarks of Allscripts Healthcare, LLC. and/or its affiliates.
|
|
*/
|
|
/* P r o p r i e t a r y N o t i c e */
|
|
|
|
library:
|
|
purpose: Retrieves OrderTaskOccurrences according to the rules stated in
|
|
std_duplicate_task.mlm. Returns information to the calling MLM.
|
|
;;
|
|
explanation: See the explanation in std_duplicate.mlm
|
|
;;
|
|
keywords: Duplicate Task;
|
|
;;
|
|
knowledge:
|
|
type: data-driven;;
|
|
data:
|
|
|
|
/* Arguments that are passed by the calling MLM */
|
|
(client_guid,
|
|
chart_guid,
|
|
client_visit_guid,
|
|
task_occurrence_guid,
|
|
task_name,
|
|
task_scope,
|
|
is_primary_task,
|
|
originating_order_guid,
|
|
past_time,
|
|
future_time,
|
|
tasks_to_be_canceled_string,
|
|
schedule_type_code,
|
|
order_task_guid ):= ARGUMENT;
|
|
|
|
/* Set to true if logging is needed.*/
|
|
log_execution_info := false;
|
|
|
|
If exist client_guid
|
|
then
|
|
/*------------------------------------------------------------------*/
|
|
/* Set Variables to Retrieve OrderTaskOccurrences from the Database */
|
|
/*------------------------------------------------------------------*/
|
|
|
|
/* Set the OrderTaskOccurrence{{{SINGLE-QUOTE}}}s scope by using the patient{{{SINGLE-QUOTE}}}s GUIDs */
|
|
If task_scope = "This Chart"
|
|
then
|
|
ID_equals_patient_GUID := "o.ClientGUID = " || SQL(client_guid)
|
|
|| " AND t.ChartGUID = " || SQL(chart_guid);
|
|
elseif task_scope = "This Visit"
|
|
then
|
|
ID_equals_patient_GUID := "o.ClientGUID = " || SQL(client_guid)
|
|
|| " AND t.ChartGUID = " || SQL(chart_guid)
|
|
|| " AND ord.ClientVisitGUID = " || SQL(client_visit_guid);
|
|
else
|
|
ID_equals_patient_GUID := "o.ClientGUID = " || SQL(client_guid);
|
|
endif; /* task_scope */
|
|
|
|
|
|
/* Set the OrderTaskOccurrences that are in memory to be canceled */
|
|
If exist tasks_to_be_canceled_string
|
|
then
|
|
ignore_these_task_occurrences := SQL(task_occurrence_guid) || ","
|
|
|| tasks_to_be_canceled_string;
|
|
else
|
|
ignore_these_task_occurrences := SQL(task_occurrence_guid);
|
|
endif; /* tasks_to_be_canceled_string */
|
|
|
|
|
|
/* When there is a CONTINUOUS order task (CV3OrderTask.ScheduleTypeCode) */
|
|
/* Exclude the OrderTaskOccurrences that have the same OrderTaskGUID */
|
|
If schedule_type_code = "Continuous"
|
|
then
|
|
AND_exclude_order_task_guid := " AND o.OrderTaskGUID <> "
|
|
|| SQL(order_task_guid);
|
|
else
|
|
AND_exclude_order_task_guid := "";
|
|
endif; /* If schedule_type_code */
|
|
|
|
// Select same kind of task (primary or follow-up)
|
|
if is_primary_task
|
|
then
|
|
AND_match_task_sequence_number := " AND t.TaskSeqNum = 0";
|
|
AND_exclude_follow_up_task_from_same_order := "";
|
|
else
|
|
AND_match_task_sequence_number := " AND t.TaskSeqNum <> 0";
|
|
AND_exclude_follow_up_task_from_same_order := " AND t.OrderGUID <> "
|
|
|| SQL(originating_order_guid);
|
|
endif;
|
|
|
|
/*---------------------------------------*/
|
|
/* Get the DATABASE OrderTaskOccurrences */
|
|
/*---------------------------------------*/
|
|
(db_order_name_list,
|
|
db_order_type_code_list,
|
|
db_significant_date_list,
|
|
db_scheduled_dtm_list,
|
|
db_earliest_scheduled_dtm_list,
|
|
db_latest_scheduled_dtm_list,
|
|
db_performed_from_dtm_list,
|
|
db_performed_to_dtm_list,
|
|
db_cds_occurrence_type_list,
|
|
db_order_guid_list,
|
|
db_order_task_guid_list,
|
|
db_task_name_list,
|
|
db_task_status_code_list,
|
|
db_process_type_list,
|
|
db_schedule_type_code_list,
|
|
db_master_GUID_list,
|
|
db_level_number_list ) := read
|
|
{ "SELECT ord.Name, ord.TypeCode, "
|
|
||" tzSignificant.TimeValue as SignificantDtmOffset,"
|
|
||" tzScheduled.TimeValue as ScheduledDtmOffset,"
|
|
||" tzEarliest.TimeValue as EarliestScheduledDtmOffset,"
|
|
||" tzLatest.TimeValue as LatestScheduledDtmOffset,"
|
|
||" tzPerformedFrom.TimeValue as PerformedFromDtmOffset,"
|
|
||" tzPerformedTo.TimeValue as PerformedToDtmOffset,"
|
|
||" o.CDSOccurrenceType,"
|
|
||" o.OrderGUID, o.OrderTaskGUID, o.TaskName, o.TaskStatusCode,"
|
|
||" t.ProcessType, t.ScheduleTypeCode, t.OrderCatalogMasterItemGUID,"
|
|
||" ts.LevelNumber "
|
|
||" FROM CV3OrderTask as t "
|
|
||" JOIN CV3Order as ord"
|
|
||" ON t.OrderGUID = ord.GUID AND t.ChartGUID = ord.ChartGUID AND t.ClientGUID = ord.ClientGUID "
|
|
||" JOIN CV3OrderTaskOccurrence as o "
|
|
||" ON o.OrderTaskGUID = t.GUID AND o.OrderGUID = t.OrderGUID AND o.ClientGUID = t.ClientGUID "
|
|
||" JOIN CV3TaskStatus as ts "
|
|
||" ON o.TaskStatusCode = ts.Code "
|
|
||" JOIN CV3ClientVisit as cv "
|
|
||" ON ord.ClientVisitGUID = cv.GUID AND ord.ClientGUID = cv.ClientGUID "
|
|
||" CROSS APPLY dbo.SXADBConvertLocalToOffsetTblFn(cv.TimeZone, o.ScheduledDtm) tzScheduled "
|
|
||" CROSS APPLY dbo.SXADBConvertLocalToOffsetTblFn(cv.TimeZone, o.SignificantDtm) tzSignificant "
|
|
||" CROSS APPLY dbo.SXADBConvertLocalToOffsetTblFn(cv.TimeZone, o.EarliestScheduledDtm) tzEarliest "
|
|
||" CROSS APPLY dbo.SXADBConvertLocalToOffsetTblFn(cv.TimeZone, o.LatestScheduledDtm) tzLatest "
|
|
||" CROSS APPLY dbo.SXADBConvertLocalToOffsetTblFn(cv.TimeZone, o.PerformedFromDtm) tzPerformedFrom "
|
|
||" CROSS APPLY dbo.SXADBConvertLocalToOffsetTblFn(cv.TimeZone, o.PerformedToDtm) tzPerformedTo "
|
|
||" WHERE t.ClientGUID = " || SQL (client_guid)
|
|
||" AND " || ID_equals_patient_GUID
|
|
||" AND o.CDSOccurrenceType >= 0 "
|
|
||" AND ts.LevelNumber In (50,60) "
|
|
||" AND o.TaskStatusCode <> {{{SINGLE-QUOTE}}}Not Performed{{{SINGLE-QUOTE}}} "
|
|
||" AND o.IsSuspended = 0 "
|
|
||" AND o.GUID NOT IN (" || ignore_these_task_occurrences || ")"
|
|
|| AND_exclude_order_task_guid
|
|
|| AND_match_task_sequence_number
|
|
|| AND_exclude_follow_up_task_from_same_order
|
|
||" AND t.ScheduleTypeCode In "
|
|
||" ({{{SINGLE-QUOTE}}}Continuous{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}ToSchedule{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Scheduled{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Unscheduled{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}PRN{{{SINGLE-QUOTE}}})"
|
|
||" AND ((ts.LevelNumber = 60 "
|
|
||" AND (o.SignificantDtm between " || SQL(past_time)
|
|
|| " and " || SQL(future_time)|| "))"
|
|
||" OR "
|
|
||" (ts.LevelNumber = 50 "
|
|
||" AND ( (o.ScheduledDtm between " || SQL(past_time)
|
|
|| " and " || SQL(future_time)|| ")"
|
|
||" OR (o.EarliestScheduledDtm between " || SQL(past_time)
|
|
|| " and " || SQL(future_time)|| ")"
|
|
||" OR (o.LatestScheduledDtm between " || SQL(past_time)
|
|
|| " and " || SQL(future_time)|| ")"
|
|
||" OR ((o.EarliestScheduledDtm <= " || SQL(future_time)
|
|
||") and (o.LatestScheduledDtm is null))"
|
|
||" OR ((o.EarliestScheduledDtm <= " || SQL(past_time)
|
|
|| ") and (o.LatestScheduledDtm >= "
|
|
|| SQL(future_time)|| "))"
|
|
||" )))"
|
|
,PrimaryTime = SignificantDtmOffset };
|
|
|
|
endif; /* If exist client_guid */
|
|
|
|
/*-----------------------------------------------------*/
|
|
/* Get the Unsubmitted OrderTaskOccurrences from CACHE */
|
|
/*-----------------------------------------------------*/
|
|
|
|
/* Initialize Variables */
|
|
unsub_master_GUID_list := ();
|
|
unsub_order_name_list := ();
|
|
unsub_order_type_code_list := ();
|
|
unsub_process_type_list := ();
|
|
unsub_schedule_type_code_list := ();
|
|
unsub_significant_date_list := ();
|
|
unsub_latest_scheduled_dtm_list := ();
|
|
unsub_performed_to_dtm_list := ();
|
|
unsub_task_name_list := ();
|
|
unsub_task_status_code_list := ();
|
|
unsub_task_guid_list := ();
|
|
|
|
/* Only get the cached data if the schedule_type_code <> "Continuous" */
|
|
If is_primary_task AND ( schedule_type_code <> "Continuous" )
|
|
then
|
|
|
|
(unsub_latest_scheduled_dtm_list,
|
|
unsub_performed_to_dtm_list,
|
|
unsub_task_name_list,
|
|
unsub_task_status_code_list,
|
|
unsub_task_guid_list,
|
|
unsub_significant_date_list ) := read
|
|
{Unsubmitted OrderTaskOccurrence: LatestScheduledDtm,
|
|
PerformedToDtm, TaskName, TaskStatusCode,
|
|
guid, significantdtm
|
|
WHERE CDSOccurrenceType >= 0
|
|
AND TaskStatusCode IS IN ("Pending", "OverDue", "Rescheduled", "Performed" )
|
|
AND GUID <> task_occurrence_guid
|
|
AND IsSuspended = FALSE
|
|
AND (
|
|
SignificantDtm IS WITHIN past_time to future_time
|
|
OR ScheduledDtm IS WITHIN past_time to future_time
|
|
OR EarliestScheduledDtm IS WITHIN past_time to future_time
|
|
OR LatestScheduledDtm IS WITHIN past_time to future_time
|
|
OR (EarliestScheduledDtm <= future_time and LatestScheduledDtm is null)
|
|
OR (EarliestScheduledDtm <= past_time and LatestScheduledDtm >= future_time)
|
|
)};
|
|
|
|
/* OrderTaskOccurrence Object */
|
|
(order_obj,
|
|
order_task_obj):= read last
|
|
{OrderTaskOccurrence: Order, OrderTask
|
|
REFERENCING EvokingObject };
|
|
|
|
/* OrderTask object */
|
|
(unsub_master_GUID,
|
|
unsub_process_type,
|
|
unsub_schedule_type_code) := read last
|
|
{OrderTask: OrderCatalogMasterItemGUID, ProcessType, ScheduleTypeCode
|
|
REFERENCING order_task_obj };
|
|
|
|
/* Order object */
|
|
(unsub_order_name,
|
|
unsub_order_type_code,
|
|
unsub_significant_date ) := read last
|
|
{Order: Name, TypeCode, SignificantDtm
|
|
REFERENCING order_obj };
|
|
|
|
/* Create equal sized lists */
|
|
index_list := 1 seqto count(unsub_task_name_list);
|
|
|
|
for J in index_list do
|
|
unsub_master_GUID_list := unsub_master_GUID_list,
|
|
unsub_master_GUID;
|
|
unsub_order_name_list := unsub_order_name_list,
|
|
unsub_order_name;
|
|
unsub_order_type_code_list := unsub_order_type_code_list,
|
|
unsub_order_type_code;
|
|
unsub_process_type_list := unsub_process_type_list,
|
|
unsub_process_type;
|
|
unsub_schedule_type_code_list := unsub_schedule_type_code_list,
|
|
unsub_schedule_type_code;
|
|
enddo;
|
|
|
|
endif; /* If schedule_type_code <> "Continuous" */
|
|
|
|
/*---------------------------------------------*/
|
|
/* Append Unsubmitted and Database Information */
|
|
/*---------------------------------------------*/
|
|
if is_primary_task
|
|
AND (exist DB_TASK_NAME_LIST or exist UNSUB_TASK_NAME_LIST)
|
|
then
|
|
latest_scheduled_dtm_list := unsub_latest_scheduled_dtm_list,
|
|
db_latest_scheduled_dtm_list;
|
|
master_GUID_list := unsub_master_GUID_list,
|
|
db_master_GUID_list;
|
|
order_name_list := unsub_order_name_list,
|
|
db_order_name_list;
|
|
order_type_code_list := unsub_order_type_code_list,
|
|
db_order_type_code_list;
|
|
performed_to_dtm_list := unsub_performed_to_dtm_list,
|
|
db_performed_to_dtm_list;
|
|
process_type_list := unsub_process_type_list,
|
|
db_process_type_list;
|
|
schedule_type_code_list := unsub_schedule_type_code_list,
|
|
db_schedule_type_code_list;
|
|
significant_date_list := unsub_significant_date_list,
|
|
db_significant_date_list;
|
|
task_name_list := unsub_task_name_list,
|
|
db_task_name_list;
|
|
task_status_code_list := unsub_task_status_code_list,
|
|
db_task_status_code_list;
|
|
else
|
|
latest_scheduled_dtm_list := db_latest_scheduled_dtm_list;
|
|
master_GUID_list := db_master_GUID_list;
|
|
order_name_list := db_order_name_list;
|
|
order_type_code_list := db_order_type_code_list;
|
|
performed_to_dtm_list := db_performed_to_dtm_list;
|
|
process_type_list := db_process_type_list;
|
|
schedule_type_code_list := db_schedule_type_code_list;
|
|
significant_date_list := db_significant_date_list;
|
|
task_name_list := db_task_name_list;
|
|
task_status_code_list := db_task_status_code_list;
|
|
endif; /* exist task_name_list */
|
|
;;
|
|
evoke:
|
|
;;
|
|
logic:
|
|
|
|
/* Always conclude true to return information to the calling MLM */
|
|
conclude true;
|
|
;;
|
|
action:
|
|
Return ( latest_scheduled_dtm_list,
|
|
master_GUID_list,
|
|
order_name_list,
|
|
order_type_code_list,
|
|
performed_to_dtm_list,
|
|
process_type_list,
|
|
schedule_type_code_list,
|
|
significant_date_list,
|
|
task_name_list,
|
|
task_status_code_list );
|
|
;;
|
|
end:
|