maintenance: title: SCH_FUNC_DCSUMMARY_PRINT_STHTESTING;; mlmname: SCH_FUNC_DCSUMMARY_PRINT_STHTESTING;; arden: version 2.5;; version: 5.50;; institution: Allscripts;; author: Shawn Head;; specialist: ;; date: 2015-05-11;; validation: testing;; library: purpose: print electronic DC Summary document report from MLM ;; explanation: This called MLM uses ReportRequest class to print discharge summary document report. It also set report{{{SINGLE-QUOTE}}}s parameter values and distribution information Change history 05.11.2015 STH CSR# 32070 go-live 6/9/2015 - Create electronic Discharge Summary report that will be sent to PDF, then converted to interface message (DEV) 7.7.2015 STH CSR#: 32070 - Testing for missing reports. ;; keywords: Discharge Summary, Day of Discharge Note, DC Summary ;; knowledge: type: data-driven;; data: standard_libs := MLM {{{SINGLE-QUOTE}}}std_include_libs{{{SINGLE-QUOTE}}}; include standard_libs; using "SCMLib"; using "SCM.Common.Interfaces"; using namespace "SCMLib"; using namespace "SCM.Common.Interfaces"; //(ClientGuid,ChartGuid,VisitGuid,DCSummary,DCSummaryGUID) := ARGUMENT; /* clientguid := "20526020001"; chartguid := "9000443888100170"; visitguid := "9000443888100270"; DCSummaryGUID := null; dcSummary := "Day of Discharge%"; (VisitID, MRN) := read last { " select visitidcode, idcode from cv3clientvisit with (nolock) " || " where clientguid = " || sql(ClientGuid) || " and chartguid = " || sql(ChartGuid) || " and guid = " || sql(VisitGuid) }; */ /* (idcode,visitidcode,clientguid,chartguid,visitguid,ClientDocumentGUID) := read { " select cv.ClientGUID ,cv.ChartGUID ,cv.GUID as {{{SINGLE-QUOTE}}}cv_guid{{{SINGLE-QUOTE}}} ,cv.ClientDisplayName ,cv.IDCode ,cv.VisitIDCode ,cv.TypeCode ,cv.AdmitDtm ,cv.DischargeDtm ,(select name from CV3Location where guid = cv.CurrentLocationGUID) as {{{SINGLE-QUOTE}}}UNIT{{{SINGLE-QUOTE}}} ,cv.DischargeDisposition ,(select dbo.SXACalculateAgeByDatePartsFN(c.BirthDayNum,c.BirthMonthNum,c.BirthYearNum,{{{SINGLE-QUOTE}}}{{{SINGLE-QUOTE}}},isnull(cv.dischargedtm,cv.admitdtm))) as {{{SINGLE-QUOTE}}}age{{{SINGLE-QUOTE}}} ,DateDiff(hh,cv.AdmitDtm, isnull(cv.dischargedtm,getdate())) as {{{SINGLE-QUOTE}}}LOS_HOURS{{{SINGLE-QUOTE}}} ,cv.VisitStatus into #tmp_cv from CV3ClientVisit cv with (Nolock) inner join CV3Client c with (Nolock) on cv.ClientGUID = c.GUID where (typecode in ({{{SINGLE-QUOTE}}}INPATIENT{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}OBSERVATION{{{SINGLE-QUOTE}}}) and VisitStatus in ({{{SINGLE-QUOTE}}}adm{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}dsc{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}CLS{{{SINGLE-QUOTE}}}) and isnull(DischargeDtm,admitdtm) >= {{{SINGLE-QUOTE}}}2019-01-01 00:00:00.000{{{SINGLE-QUOTE}}} and (DischargeDtm <= getdate() or DischargeDtm is null)) select distinct cv.* ,cd.GUID as {{{SINGLE-QUOTE}}}cd_guid{{{SINGLE-QUOTE}}} ,cd.Entered ,cd.CreatedWhen ,cd.tobesigned ,cdh.historydtm ,cdh.historyreason ,cdh.historytype ,cu.displayname ,cd.DocumentName into #tmp_documents from #tmp_cv cv left join cv3clientdocument as cd on cv.clientguid = cd.clientguid and cv.chartguid = cd.chartguid and cv.cv_guid = cd.clientvisitguid and cd.PatCareDocGUID = {{{SINGLE-QUOTE}}}5000001002202001{{{SINGLE-QUOTE}}} and cd.IsCanceled = 0 left join cv3clientdochistory as cdh on cd.clientguid = cdh.clientguid and cd.guid = cdh.clientdocguid and cdh.historyType = 1 left join cv3user as cu on cd.authoredproviderguid= cu.guid left join cv3patientcaredocument as pcd on cd.patcaredocguid = pcd.guid left join cv3organizationalunit as ou on pcd.orgunitguid = ou.guid where cd.ToBeSigned = 1 or cd.GUID is null select convert(varchar(5),DateDiff(s, cv.DischargeDtm,getdate())/86400) as {{{SINGLE-QUOTE}}}DC_Days{{{SINGLE-QUOTE}}}, convert(varchar(5),DateDiff(s,cv.DischargeDtm, getdate())%86400/3600) as {{{SINGLE-QUOTE}}}DC_hours{{{SINGLE-QUOTE}}}, convert(varchar(5),DateDiff(s, cv.DischargeDtm,getdate())%3600/60) as {{{SINGLE-QUOTE}}}DC_minutes{{{SINGLE-QUOTE}}}, case when d.DocumentName is null then {{{SINGLE-QUOTE}}}MISSING{{{SINGLE-QUOTE}}} else {{{SINGLE-QUOTE}}}ON CHART{{{SINGLE-QUOTE}}} END as{{{SINGLE-QUOTE}}}DischargeSummary{{{SINGLE-QUOTE}}} ,case when cd.DocumentName is null then {{{SINGLE-QUOTE}}}NO{{{SINGLE-QUOTE}}} else {{{SINGLE-QUOTE}}}YES{{{SINGLE-QUOTE}}} end as {{{SINGLE-QUOTE}}}SCM_DC_NOTE_PRESENT{{{SINGLE-QUOTE}}} ,d.ToBeSigned ,d.CreatedWhen ,CD.ENTERED ,cd.guid ,cv.* into #tmp_final from #tmp_documents d with (nolock) left join CV3ClientDocument cd with (Nolock) on d.ClientGUID = cd.ClientGUID and d.ChartGUID = cd.ChartGUID and d.cv_guid = cd.ClientVisitGUID and cd.PatCareDocGUID = {{{SINGLE-QUOTE}}}9000001101102020{{{SINGLE-QUOTE}}} INNER JOIN #tmp_cv CV ON d.CLIENTGUID = CV.CLIENTGUID AND D.CHARTGUID = CV.CHARTGUID AND D.cv_guid = CV.cv_guid select top 1 idcode ,visitidcode ,clientguid ,ChartGUID ,cv_guid ,GUID from #tmp_final where SCM_DC_NOTE_PRESENT = {{{SINGLE-QUOTE}}}YES{{{SINGLE-QUOTE}}} AND ToBeSigned IS NULL DROP TABLE #tmp_final,#tmp_cv, #tmp_documents "}; */ error_destination := destination { Alert } with [ alert_type := "Warning", short_message := "ObjectsPlus Error from MLM", priority := "low", scope := "chart", Rule_group := "ObjectsPlus Error from MLM", Rule_number := 1001, Rule_subgroup := "", Send_with_order := "", Alert_dialog_settings := "", Display_alert := true ]; PhoneNumber := read last {" set concat_null_yields_null off select p.AreaCode + p.PhoneNumber from CV3User u with (nolock) join Cv3Phone p with (nolock) on p.PersonGUID = u.GUID " || " where u.displayname = {{{SINGLE-QUOTE}}}SCM, Text Messaging{{{SINGLE-QUOTE}}} and p.PhoneNote = {{{SINGLE-QUOTE}}}HIS Test{{{SINGLE-QUOTE}}}"}; abc123 := abc123 || "\n\n" || "PRODUCTION"; for x in (1 seqto count(ClientDocumentGUID)) do CD_GUID := ClientDocumentGUID[x]; CV_GUID := VisitGUID[x]; C_GUID := ClientGUID[x]; CT_GUID := ChartGUID[x]; acct := VisitIDCode[x]; MRN := IDCode[x]; if (CD_GUID <> "" OR CD_GUID is not null) then try abc123 := abc123 || "\n\n" || "Enter Try"; report_request_obj := call {{{SINGLE-QUOTE}}}ObjectsPlusXA.SunriseClinicalManager.ReportRequest{{{SINGLE-QUOTE}}}.CreateReportRequest with ("DischargeSummary_PDF" as {{{SINGLE-QUOTE}}}String{{{SINGLE-QUOTE}}}); abc123 := abc123 || "\n\n" || "Created Report Object"; if (report_request_obj.Parameters is not null and report_request_obj.Parameters.Count > 0) then abc123 := abc123 || "\n\n" || "Entered If parameters exists section"; report_parameter_list := (); for parameterIndex in (1 seqto report_request_obj.Parameters.Count) do abc123 := abc123 || "\n\n" || "Entered for parameterindex loop count #:" || parameterIndex; report_parameter_list := report_parameter_list, report_request_obj.Parameters[parameterIndex]; enddo; endif; abc123 := abc123 || "\n\n" || "set report parameter list"; param_ClientDocGUID := first (report_parameter_list where report_parameter_list.Label = "varClientDocumentGUID"); param_ClientGUID:= first (report_parameter_list where report_parameter_list.Label = "varClientGUID"); param_ChartGUID := first(report_parameter_list where report_parameter_list.Label = "varClientChartGUID"); param_VisitGUID := first(report_parameter_list where report_parameter_list.Label = "varClientVisitGUID"); param_VisitID := first(report_parameter_list where report_parameter_list.Label = "varVisitID"); param_VisitMRN := first(report_parameter_list where report_parameter_list.Label = "varVisitMRN"); abc123 := abc123 || "\n\n" || "set report parameter values"; if param_VisitID.AllowModification then void := call param_VisitID.{{{SINGLE-QUOTE}}}SetValue{{{SINGLE-QUOTE}}} with STRING(acct) as {{{SINGLE-QUOTE}}}System.String{{{SINGLE-QUOTE}}}; endif; if param_VisitMRN.AllowModification then void := call param_VisitMRN.{{{SINGLE-QUOTE}}}SetValue{{{SINGLE-QUOTE}}} with STRING(MRN) as {{{SINGLE-QUOTE}}}System.String{{{SINGLE-QUOTE}}}; endif; if param_ClientDocGUID.AllowModification then void := call param_ClientDocGUID.{{{SINGLE-QUOTE}}}SetValue{{{SINGLE-QUOTE}}} with STRING(CD_GUID) as {{{SINGLE-QUOTE}}}System.String{{{SINGLE-QUOTE}}}; endif; if param_ClientGUID.AllowModification then void := call param_ClientGUID.{{{SINGLE-QUOTE}}}SetValue{{{SINGLE-QUOTE}}} with STRING(C_GUID) as {{{SINGLE-QUOTE}}}System.String{{{SINGLE-QUOTE}}}; endif; if param_ChartGUID.AllowModification then void := call param_ChartGUID.{{{SINGLE-QUOTE}}}SetValue{{{SINGLE-QUOTE}}} with STRING(CT_GUID) as {{{SINGLE-QUOTE}}}System.String{{{SINGLE-QUOTE}}}; endif; if param_VisitGUID.AllowModification then void := call param_VisitGUID.{{{SINGLE-QUOTE}}}SetValue{{{SINGLE-QUOTE}}} with STRING(CV_GUID) as {{{SINGLE-QUOTE}}}System.String{{{SINGLE-QUOTE}}}; endif; abc123 := abc123 || "\n\n" || "check parameters for modify and set them to desired values"; report_request_obj.PrintPolicy := "Broadcast" as {{{SINGLE-QUOTE}}}PrintPolicy{{{SINGLE-QUOTE}}}; report_request_obj.ProcessReportLocally := false; report_request_obj.PrintJobDestination := "PDFHL7"; reportRequest.PrintJobPriority := "Normal" as {{{SINGLE-QUOTE}}}PrintJobPriority{{{SINGLE-QUOTE}}}; report_request_obj.NumberOfCopies := 1; abc123 := abc123 || "\n\n" || "set other report vales"; // print the report void := call report_request_obj.Save; abc123 := abc123 || "\n\n" || "save and print report"; // Call Dispose on report_request_obj to clean it up if report_request_obj is not null then void := call report_request_obj.Dispose; report_request_obj := null; endif; endtry; catch exception ex abc123 := abc123 || "\n\n" || "entered catch error exception"; error_occurred := true; error_message := "{{+R}}Auto Print:{{-R}}\n" || ex.Message || "\n\n"; if ex.InnerException is not null net_object then error_message := error_message || "Inner Exception: " || ex.InnerException.Message || "\n\n"; endif; // Send a Text Message Section // Call Dispose on report_request_obj to clean it up if report_request_obj is not null then void := call report_request_obj.Dispose; report_request_obj := null; endif; endcatch; endif; enddo; // Send a Text Message Section Page_MLM := mlm {{{SINGLE-QUOTE}}}SCH_FUNC_PAGE{{{SINGLE-QUOTE}}}; MessageSubject:= "Discharge Summary MLM Alert"; MessageBody := " ClientGUID: " || ClientGuid || "\n\n " || "ChartGUID: " || ChartGuid || "\n\n " || "ClientVisitGUID: " || VisitGuid || "\n\n" || "DCSummaryGUID: " || DCSummaryGUID || "\n\n" || "DCSummary: " || DCSummary || "ClientDocGUID: " || ClientDocumentGUID || "\n\n" || "cd_guid: " || CD_GUID || "\n\n" || "abc123: " || abc123; if error_occurred then void := call Page_MLM with(PhoneNumber, MessageSubject, MessageBody); endif; // Diagnostic Alert - Can be enabled if needed // send_alert := "DoNotSend"; // alert_dest := destination { Alert: warning, "Informational", high, chart, "Informational", 15042, send_alert, "No Override Allowed" }; ;; priority: 50 ;; evoke: ;; logic: conclude true; ;; action: if Error_occurred then write "An error has occured in the MLM {{+B}}SCH_FUNC_DCSUMMARY_PRINT{{-B}} " || "Please notify your System Administrators that an error message has " || "occurred for this patient. They will review the following error " || "message: \n" at error_destination; write error_message at error_destination; endif; // Diagnostic Alert - Can be enabled if needed // write " Messages " || " Execute the Called PRINT MLM - " || NOW || " " || ClientDocumentGUID at alert_dest; ;; Urgency: 50;; end: