maintenance: title: Calculate Durations for Tasks;; mlmname: STD_FUNC_TASK_DURATION;; 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: Calculates the durations based on the standard times and on a percentage of a frequency. ;; explanation: Pass in a number and a string representation of time units, and it will converted the information into an ARDEN Duration. The expected spellings are: "minutes", "hours", "days", "weeks", "months", "hours", and "task %". In addition, the facility must map its Dictionary Codes to the Core UOM in the Units of Measure Dictionary. To calculate the DURATION from "task %", the MLM converts the facility-defined units of measure to the system-defined values in the Unit of Measure Dictionary called CoreUOM. The expected CoreUOM are: "s", "min", "hr", "day", "week", "month", "year" ;; keywords: Duration; Calculation; ;; knowledge: type: data-driven;; data: (some_number, time_unit, frequency_unit) := ARGUMENT; /* System-defined units of measures in the Unit of Measure Dictionary*/ /* called CoreUOM. */ day_string:= "day"; hour_string:= "hr"; minute_string:= "min"; month_string:= "month"; second_string:= "s"; week_string:= "week"; year_string:= "year"; /*-------------------------------------------*/ /* Convert standard TIME units to a duration */ /*-------------------------------------------*/ If time_unit is in ("minutes", "hours", "days", "weeks", "months", "years") then if time_unit = "minutes" then answer:= some_number MINUTES; elseif time_unit = "hours" then answer:= some_number HOURS; elseif time_unit = "days" then answer:= some_number DAYS; elseif time_unit = "weeks" then answer:= some_number WEEKS; elseif time_unit = "months" then answer:= some_number MONTHS; elseif time_unit = "years" then answer:= some_number YEARS; endif; /* if time_unit */ endif; /* If time_unit is in */ /*---------------------------*/ /* Get FREQUENCY information */ /*---------------------------*/ if time_unit = "Task %" and exist frequency_unit then /* Gets the Frequency information from the Enterprise data */ (frequency_code, frequency_type, time_from_value, time_to_value, time_uom, time_core_uom):= read last {"SELECT f.Code, f.DefinitionType, f.TimeFromValue, f.TimeToValue," || " f.TimeUom, u.CoreUOM " || " FROM CV3Frequency AS f JOIN CV3UnitOfMeasure AS u" || " ON f.TimeUom = u.Code " || " WHERE f.Code = " || SQL (frequency_unit) }; /* Handle frequency templates and by parsing the frequency string */ /* If changes are made to this code, also change them in SYS_CALC_FREQMULT_DAILY */ /* This is a temporary workaround for frequency templates */ If NOT Exist frequency_type then /* Declare C functions to parse the frequency string */ func_get_token := interface {char* msvcrt:strtok(char*, char*)}; func_get_str := interface {char* msvcrt:strstr(char*, char*)}; /* Declare characters used for delimiting the string */ /* Delimiters are Case Sensitive */ q_delim:= "Q"; h_delim:= "H"; m_delim:= "M"; /* Determine if the letter in at the back of the string is H or M */ get_H:= call func_get_str with (frequency_unit, h_delim); get_M:= call func_get_str with (frequency_unit, m_delim); /* Remove the front Q, so xH or xM is left */ trim_Q:= call func_get_token with (frequency_unit, q_delim); /* Set the time_core_uom */ /* Remove the H or the M, leaving a string representation of a number */ if exist get_H then time_core_uom := hour_string; freq_num_str := call func_get_token with (trim_Q, h_delim); elseif exist get_M then time_core_uom := minute_string; freq_num_str := call func_get_token with (trim_Q, m_delim); endif; /* if exist get_H */ /* Convert string to number */ time_from_value := freq_num_str as number; endif; /* If NOT Exist frequency_type */ endif; /*if time_unit = "Task %"*/ ;; evoke: ;; logic: /*---------------------------------*/ /* Convert FREQUENCY to a duration */ /*---------------------------------*/ if exist time_core_uom and time_unit = "Task %" then if time_core_uom = day_string then if frequency_type = 1 /* y times per day */ then frequency_duration:= (1/ time_from_value) * 1 day ; else frequency_duration:= time_from_value * 1 day; endif; elseif time_core_uom = hour_string then if frequency_type = 1 /* y times per hour */ then frequency_duration:= (1/ time_from_value) * 1 hour ; else frequency_duration:= time_from_value * 1 hour ; endif; elseif time_core_uom = minute_string then if frequency_type = 1 /* y times per minute*/ then frequency_duration:= (1/ time_from_value) * 1 minute ; else frequency_duration:= time_from_value * 1 minute ; endif; elseif time_core_uom = second_string then if frequency_type = 1 /* y times per second */ then frequency_duration:= (1/time_from_value) * 1 second ; else frequency_duration:= time_from_value * 1 second ; endif; elseif time_core_uom = week_string then if frequency_type = 1 /* y times per week */ then frequency_duration:= (1/time_from_value) * 1 week ; else frequency_duration:= time_from_value * 1 week ; endif; elseif time_core_uom = month_string then if frequency_type = 1 /* y times per month */ then frequency_duration:= (1/time_from_value) * 1 month; else frequency_duration:= time_from_value * 1 month; endif; elseif time_core_uom = year_string then if frequency_type = 1 /* y times per year */ then frequency_duration:= (1/time_from_value) * 1 year ; else frequency_duration:= time_from_value * 1 year ; endif; endif; /* if time_core_uom */ /* Calculate Task % answer */ answer := frequency_duration * (SOME_NUMBER/100); endif; /* if exist time_core_uom */ /************************/ /* Always conclude true */ /************************/ Conclude True; ;; action: Return answer; ;; end: