maintenance: title: Generic Lookup;; mlmname: ACS_generic_Lookup ;; arden: version 2.5;; version: 5.50;; institution: Allscripts;; author: ACS;; specialist: Allscripts Custom Services;; date: 2011-12-05;; validation: testing;; library: purpose: Generic tool to lookup past patient data, based upon passed parameters. ;; explanation: Change history 05.01.2014 DW CSR# 32070 - Add Admit Date to PN LOS text box 19.05.2015 DW CSR# 32982 - Add Skipped Doses to {{{SINGLE-QUOTE}}}Medication and Allergies{{{SINGLE-QUOTE}}}=> {{{SINGLE-QUOTE}}}Active Medications with detail{{{SINGLE-QUOTE}}} radio button ;; keywords: ;; knowledge: type: data-driven;; data: /******************************* Make Changes Here *************************************/ ///*** REM - change current to NOW - 24 hours ////*** when data ready is ready to be within last 24 hours current := Now - 24 hours; /****************** Make Your code stretch NO WIDER THAN THIS! *************************/ (This_communicationobj, Client_guid, Client_visit_guid, Client_chart_guid, Getdata_from,//“historical” or “current” (use SQL or current object navigation) Data_value_type,//Object to retrieve (“HealthIssue”, “order”, etc.) Data_item,//Attribute to retrieve (“name”, “itemname”, “typecode”, “code”, etc.) Filterable_item,//Filterable attribute (“name”, “itemname”, “typecode”, “code”, etc.) Filterable_operator,//Filterable operator (“=”, “<>”, “in”, “matches pattern”, etc.) Filterable_value,//Filterable value(s)(“chronic”, “atb”,“(‘480.00’,’480.30’)", etc.) Additional_condition)//Additional condition(s) := ARGUMENT; // Initialize Return_Data_item :=();//List object attributes retrieved Return_Data_item_value :=();//List of values for the attribute(s) Return_UOM_or_code :=();//List of UOMs (units of measure) for the attributes Return_relevant_time :=();//List of medically relevant times Return_start_or_alt_name:=();//List of start times (if relevant) Return_stop_or_alt_code :=();//List of stop times (if relevant) Return_user_or_other :=();//List of userguids who entered data. Return_Significant_data:=();//List of other “significant data” as a text field. Return_Sig_count := (); //list of significant COUNT data. Return_Sig_Nt_count := (); //list of Non significant COUNT data.... Added By Shivprasad Jadhav For CSR : 32982 strUser_guid :=""; strSQL :=""; strWhere :=""; strFilterSQL :=""; IF exist This_communicationobj THEN strUser_guid := This_communicationobj.UserGUID; ENDIF; if called_by_editor then Data_value_type := "Vitals"; //"Orders"; //"Lab Results"; strUser_guid := read last {userinfo: guid}; data_item := "ocmi.name"; // "Lab Results"; //"hi.shortname + {{{SINGLE-QUOTE}}} {{{SINGLE-QUOTE}}} + hi.description"; Filterable_item:= "ocmi.name"; // "ch.code"; //"o.name"; ///, Filterable_operator:= "IN"; // "like"; // (“=”, “<>”, “in”, “matches pattern”, etc.) Filterable_value:= "{{{SINGLE-QUOTE}}}SCH_vs_pulse ox saturation{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Resp Rate{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}L/min{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Noninvasive Systolic BP{{{SINGLE-QUOTE}}}," ||"{{{SINGLE-QUOTE}}}Noninvasive Diastolic BP{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Farenheit{{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}Heart Rate{{{SINGLE-QUOTE}}}"; // " {{{SINGLE-QUOTE}}}Basic Metabolic Panel{{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}Electrolytes{{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}Liver Panel{{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}Hemoglobin and Hemtocrit{{{SINGLE-QUOTE}}}," // ||"{{{SINGLE-QUOTE}}}Prothrombin/INR{{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}APTT{{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}CBC (Includes Diff){{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}CBC with Manual Diff{{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}Creatinine{{{SINGLE-QUOTE}}}" ; //"{{{SINGLE-QUOTE}}}Pulmonary Health Education Consult{{{SINGLE-QUOTE}}}"; (client_guid, client_visit_guid, client_chart_guid) := read last {clientvisit: clientguid, guid, chartguid}; Getdata_from := "Historical"; // Additional_condition:="ALL"; //o.OrderStatusLevelNum >= {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} " ; //"all"; endif; IF Getdata_from = "Historical" THEN // assemble the main condition strWhere := " where ClientGUID = " || SQL(Client_guid); IF any(exists Filterable_item AND (not (Filterable_item is in ("", "No")))) AND any(exists Filterable_operator AND (not(Filterable_operator is in ("", "No")))) AND any(exists Filterable_value AND (not (Filterable_value is in ("", "No")))) THEN strFilterSQL := " ( " || Filterable_item||" "||Filterable_operator||" "; IF Filterable_operator = "IN" THEN strFilterSQL := strFilterSQL ||"("|| Filterable_value||")"; ELSEIF Filterable_operator = "LIKE" THEN if count Filterable_value = 1 then strFilterSQL := strFilterSQL || "{{{SINGLE-QUOTE}}}%" || Filterable_value|| "%{{{SINGLE-QUOTE}}}"; else // enable multiple LIKEs in SQL strFilterSQL := strFilterSQL ||"{{{SINGLE-QUOTE}}}%"|| Filterable_value[1] || "%{{{SINGLE-QUOTE}}}"; for m in 2 seqto count Filterable_value do strFilterSQL := strFilterSQL || " or " || Filterable_item || " " || Filterable_operator|| " " ||"{{{SINGLE-QUOTE}}}%"|| Filterable_value[m] || "%{{{SINGLE-QUOTE}}}" ; enddo; endif; ELSE strFilterSQL := strFilterSQL || SQL(Filterable_value); ENDIF; // Filterable_operator ="IN" strFilterSQL := strFilterSQL || " ) "; ENDIF; // any(exists Filterable_item AND ... // CASE STMT FOR POSSIBLE HISTORICAL LOOKUPS // HEALTH ISSUES #################################################################### IF Data_value_type ="HealthIssue" THEN // create main SQL strSQL := " SELECT "|| Data_item ||", ch.code, hi.TouchedWhen, hi.CreatedBy " ||" FROM CV3HealthIssueDeclaration hi" ||" left outer join CV3CodedHealthIssue ch " ||" on ch.GUID = hi.CodedHealthIssueGUID " ; // apend the condition strWhere := strWhere || " AND Status = {{{SINGLE-QUOTE}}}Active{{{SINGLE-QUOTE}}} AND hi.Active = 1 "; IF strFilterSQL <>"" THEN strSQL := strSQL || strWhere || " AND "|| strFilterSQL ; ENDIF; // get the returnable data (Return_Data_item, Return_Data_item_value, Return_relevant_time, Return_user_or_other) := read{ "" ||strSql|| " " }; IF NOT EXISTS Return_Data_item THEN Return_Data_item := "\b No Problems Listed. \b0" ; ENDIF; // SERVICE ########################################################################## ELSEIF Data_value_type = "Service" THEN // create main SQL IF strUser_guid <> "" THEN /*(Return_Data_item_value):= read last {"SELECT Discipline FROM CV3CareProvider where " || " GUID =" || SQL(strUser_guid) || " AND Active = 1 " };*/ // Below New SQL Added By Shivprasad for CSR : 32338 (Return_Data_item_value):= read last {" Select Stuff (( Select {{{SINGLE-QUOTE}}},{{{SINGLE-QUOTE}}}+ d.Code " || " From cv3Careprovider cp (Nolock) Inner Join SXAAMCareProviderSpecialtyXREF cpx" || " On cp.GUID=cpx.CareProviderGUID " || " Inner Join CV3Discipline d (Nolock) On d.GUID=cpx.DisciplineGUID " || " Where cp.GUID =" || SQL(strUser_guid) || " AND cp.Active = 1 Order by d.TouchedWhen " || " FOR XML PATH({{{SINGLE-QUOTE}}}{{{SINGLE-QUOTE}}}), TYPE).value({{{SINGLE-QUOTE}}}.{{{SINGLE-QUOTE}}}, {{{SINGLE-QUOTE}}}varchar(max){{{SINGLE-QUOTE}}}), 1, 1, {{{SINGLE-QUOTE}}}{{{SINGLE-QUOTE}}}) as Discipline " } ; IF NOT Exists Return_Data_item_value Then Return_Data_item_value := "\b No Service Data Available. \b0" ; EndIf; ENDIF; // LOS ############################################################################## ELSEIF Data_value_type ="LOS" THEN (admit_date, admit_date_modified) := read last {"SELECT v.AdmitDtm, CONVERT(char (10),v.AdmitDtm,101) " || " FROM cv3clientvisit v " || " WHERE v.clientGUID = " || sql(Client_guid) || " and v.guid = " || sql(Client_visit_guid) || " and v.active = 1 " //non-closed visits , primarytime = admitdtm}; hospital_hour:= INT((NOW - admit_date) / 1 hour) ; hospital_day := INT(hospital_hour /24 ) + 1 ; Formatted_NOW := NOW FORMATTED WITH "%.4t"; IF Exists hospital_day Then Return_Data_item_value:= Return_Data_item_value, "\b Date of Admission: \b0 " || admit_date_modified || "\n\b Hospital Day: \b0 # " || hospital_day || ", Hour # " || hospital_hour || " (current date and time : " || Formatted_NOW || ")" ; ELSE Return_Data_item_value := "\b No LOS Data Available. \b0" ; ENDIF; // VITAL SIGNS ###################################################################### ELSEIF Data_value_type = "Vitals" THEN /////// 021512 - added to fetch all Lines not just last 24 hrs //////////// if Additional_condition matches pattern "Line Access%" then current:= NOW - 30 days; endif; /////////////////////////////////////////////// strSQL := " select ocmi.name, isnull(sp.valuetext, SOBS.value) vs_vals, " ||" sp.obsuom, " //ob.unitofmeasure , " ||" convert(char(16), sp.recordeddtm, 110) + {{{SINGLE-QUOTE}}} {{{SINGLE-QUOTE}}} " ||" + convert(char(5), sp.recordeddtm, 14), " ||" d.documentname, ocmi.leftjustifiedlabel " ||" from cv3clientdocument d " ||" JOIN SXACDObservationParameter sp " ||" ON d.ClientGUID = sp.ClientGUID " ||" and d.ChartGUID = sp.ChartGUID " ||" and d.guid = sp.ownerguid " ||" and d.PatCareDocGUID = sp.PatCareDocGUID " ||" JOIN CV3ObsCatalogMasterItem ocmi " ||" ON ocmi.GUID = sp.ObsMasterItemGUID " /* ||" join cv3observationDocument o " ||" on o.ownerguid = d.guid " ||" and o.ObservationDocumentGUID = sp.ObservationDocumentGUID " ||" and o.ObsMasterItemGUID = ocmi.guid " ||" and o.active = 1 " ||" left outer join cv3observation ob " ||" on sp.ObservationGUID = ob.GUID " */ ||" LEFT outer JOIN SCMObsFSListValues SOBS " ||" on sp.ClientGUID = SOBS.ClientGUID " ||" and sp.ObservationDocumentGUID = SOBS.ParentGUID " ||" AND SOBS.Active = 1 " || " and SOBS.ClientGUID =" || sql(Client_guid) ||" WHERE d.clientGUID = " || sql(Client_guid) ||" and d.chartguid = " || sql(client_chart_guid) ||" and d.clientvisitguid = " || sql(Client_visit_guid) ||" and sp.recordeddtm >= " || sql(current) ; /// 041912 - added "and SOBS.ClientGUID =" || sql(Client_guid) to the sql above IF strFilterSQL <> "" THEN // append filter strSQL := strSQL || " AND " || strFilterSQL ; ENDIF; (vs_names, vs_vals, vs_uoms ,vs_times, vs_docs, vs_labels) := read { "" || strSQL || "order by sp.RecordedDtm " }; if exists vs_vals then // set return values Return_Data_item:= vs_names; Return_Data_item_value:= vs_vals; Return_UOM_or_code := vs_uoms; Return_relevant_time:= vs_times; Return_start_or_alt_name:= ""; Return_stop_or_alt_code:= ""; Return_user_or_other:= ""; Return_Significant_data:= vs_labels; Return_Sig_Count := ""; endif; IF NOT Exists Return_Data_item_value Then Return_Data_item_value := "\b No Vital Sign Data Available. \b0" ; EndIf; // I & O ############################################################################ ELSEIF Data_value_type is in ("IO_Drains_shift", "IO_NG_shift") THEN strSQL := " select ocmi.name, x.outvalue, sp.obsuom, " //ob.unitofmeasure , ||" sp.RecordedDtm , d.documentname " ||" , case " ||" when sp.shiftdailyhourlytotal = 1 then {{{SINGLE-QUOTE}}}Shift total{{{SINGLE-QUOTE}}} " ||" when sp.shiftdailyhourlytotal = 2 then {{{SINGLE-QUOTE}}}Daily total{{{SINGLE-QUOTE}}} " ||" when sp.shiftdailyhourlytotal = 3 then {{{SINGLE-QUOTE}}}Hourly total{{{SINGLE-QUOTE}}} " ||" else {{{SINGLE-QUOTE}}}unknown{{{SINGLE-QUOTE}}} " ||" end as shift_daily_hourly " ||" from cv3clientdocument d " /* ||" join cv3observationDocument o " ||" on o.ownerguid = d.guid " ||" and o.active = 1 " */ ||" JOIN SXACDObservationParameter sp " ||" ON d.ClientGUID = sp.ClientGUID " ||" and d.ChartGUID = sp.ChartGUID " ||" and d.PatCareDocGUID = sp.PatCareDocGUID " ||" and d.guid = sp.ownerguid " // ||" and o.ObservationDocumentGUID = sp.ObservationDocumentGUID " ||" JOIN CV3ObsCatalogMasterItem ocmi " ||" ON ocmi.GUID = sp.ObsMasterItemGUID " ||" left outer join CV3ClientObsEntryItem oei on oei.GUID = sp.ParameterGUID " ||" and oei.IsUpdate = 1 " //get latest item only /* ||" join cv3observation ob " ||" on sp.ObservationGUID = ob.GUID " ||" and ob.shiftdailyhourlytotal = 1 " // shift total only */ ||" join cv3observationxinfo x " ||" on sp.ObservationGUID = x.observationxinfoguid " ||" WHERE d.clientGUID = " || sql(Client_guid) ||" and d.chartguid = " || sql(client_chart_guid) ||" and d.clientvisitguid = " || sql(Client_visit_guid) ||" and sp.shiftdailyhourlytotal = 1 " // shift total only ; IF strFilterSQL <> "" THEN // append condition strSQL := strSQL || " AND " || strFilterSQL ; ENDIF; (io_names, io_vals, io_uoms, io_times, io_docs, io_sdh_tots) := read { "" || strSQL || "", primarytime = recordeddtm}; if exists io_times then // get the latest recorded values latest_shft_io_time := max (io_times); latest_shft_io_vals := io_vals where((time of io_vals) = latest_shft_io_time); latest_shft_io_names := io_names where((time of io_names) = latest_shft_io_time); latest_shft_io_sdh_tots := io_sdh_tots where((time of io_sdh_tots) = latest_shft_io_time); latest_shft_total := sum (latest_shft_io_vals as number); // set return values Return_Data_item:= ,Data_value_type; Return_Data_item_value:= ,latest_shft_total; Return_UOM_or_code := ,(first io_uoms); Return_relevant_time:= ,latest_shft_io_time; Return_start_or_alt_name:= ""; Return_stop_or_alt_code:= ""; Return_user_or_other:= ""; Return_Significant_data:= ""; Return_Sig_Count := ""; endif; IF NOT Exists Return_Data_item_value Then Return_Data_item_value := "\b No Shift I&O Data Available for \b0" || Data_value_type ; EndIf; //Added below elseif section for IO_NG_shift_NB in Newborn Assessment and Discharge Summary document (CSR-33427) (Vikas) ELSEIF Data_value_type is in ("IO_NG_shift_NB") THEN //break; strSQL := " select ocmi.name, isnull(x.outvalue,x.invalue) as outvalue, sp.obsuom, " //ob.unitofmeasure , ||" sp.RecordedDtm , d.documentname " ||" , case " ||" when sp.shiftdailyhourlytotal = 1 then {{{SINGLE-QUOTE}}}Shift total{{{SINGLE-QUOTE}}} " ||" when sp.shiftdailyhourlytotal = 2 then {{{SINGLE-QUOTE}}}Daily total{{{SINGLE-QUOTE}}} " ||" when sp.shiftdailyhourlytotal = 3 then {{{SINGLE-QUOTE}}}Hourly total{{{SINGLE-QUOTE}}} " ||" else {{{SINGLE-QUOTE}}}unknown{{{SINGLE-QUOTE}}} " ||" end as shift_daily_hourly " ||" from cv3clientdocument d " /* ||" join cv3observationDocument o " ||" on o.ownerguid = d.guid " ||" and o.active = 1 " */ ||" JOIN SXACDObservationParameter sp " ||" ON d.ClientGUID = sp.ClientGUID " ||" and d.ChartGUID = sp.ChartGUID " ||" and d.PatCareDocGUID = sp.PatCareDocGUID " ||" and d.guid = sp.ownerguid " ||" and d.DocumentName = {{{SINGLE-QUOTE}}}B2. Newborn Intake and Output{{{SINGLE-QUOTE}}} " // ||" and o.ObservationDocumentGUID = sp.ObservationDocumentGUID " ||" JOIN CV3ObsCatalogMasterItem ocmi " ||" ON ocmi.GUID = sp.ObsMasterItemGUID " ||" left outer join CV3ClientObsEntryItem oei on oei.GUID = sp.ParameterGUID " ||" and oei.IsUpdate = 1 " //get latest item only /* ||" join cv3observation ob " ||" on sp.ObservationGUID = ob.GUID " ||" and ob.shiftdailyhourlytotal = 1 " // shift total only */ ||" join cv3observationxinfo x " ||" on sp.ObservationGUID = x.observationxinfoguid " ||" WHERE d.clientGUID = " || sql(Client_guid) ||" and d.chartguid = " || sql(client_chart_guid) ||" and d.clientvisitguid = " || sql(Client_visit_guid) ||" and sp.shiftdailyhourlytotal = 1 " // shift total only ; IF strFilterSQL <> "" THEN // append condition strSQL := strSQL || " AND " || strFilterSQL ; ENDIF; //Break; (io_names, io_vals, io_uoms, io_times, io_docs, io_sdh_tots) := read { "" || strSQL || "", primarytime = recordeddtm}; if exists io_times then // get the latest recorded values latest_shft_io_time := max (io_times); latest_shft_io_vals := io_vals where((time of io_vals) = latest_shft_io_time); latest_shft_io_names := io_names where((time of io_names) = latest_shft_io_time); latest_shft_io_sdh_tots := io_sdh_tots where((time of io_sdh_tots) = latest_shft_io_time); latest_shft_total := sum (latest_shft_io_vals as number); // set return values Return_Data_item:= ,Data_value_type; Return_Data_item_value:= ,latest_shft_total; Return_UOM_or_code := ,(first io_uoms); Return_relevant_time:= ,latest_shft_io_time; Return_start_or_alt_name:= ""; Return_stop_or_alt_code:= ""; Return_user_or_other:= ""; Return_Significant_data:= ""; Return_Sig_Count := ""; endif; IF NOT Exists Return_Data_item_value Then Return_Data_item_value := "\b No Shift I&O Data Available for \b0" || Data_value_type ; EndIf; ELSEIF Data_value_type is in ( "IO24", "IOSOC") THEN IF Data_value_type = "IO24" THEN sql_last_24hr := " AND RecordedDateTime >= getDate() - 1 "; else sql_last_24hr := " "; endif; (All_IO_RecDTm, All_IO_TotIT, All_IO_TotOP, All_IO_Tot24 ) := READ {" SELECT RecordedDateTime,TotalIntake,TotalOutput,Total24hr " || " FROM SCMObsFSGrandTotals " || " WHERE ClientGUID = " || SQL(client_guid) || " and chartguid = " || sql(client_chart_guid) || " AND ShIftDailyHourlyTotal = 1 " //shift total || " AND TotalType = 3 " //grand total || " AND Active = 1 " || sql_last_24hr || " order by RecordedDateTime desc " }; IF Data_value_type = "IO24" THEN All_IO_RecDTm := first 4 from All_IO_RecDTm; All_IO_TotIT := first 4 from All_IO_TotIT; All_IO_TotOP := first 4 from All_IO_TotOP; All_IO_Tot24 := first 4 from All_IO_Tot24; endif; //Variables for total Intake_Total:= 0 As NUMBER ; Output_Total:= 0 As NUMBER ; Fluid_Balance:= 0 As NUMBER; max_io_time := first(All_IO_RecDTm); min_io_time := last(All_IO_RecDTm); For ictr IN 1 seqto count All_IO_RecDTm Do //Calculating Total Intake AND OutPut If Exists All_IO_TotIT[ictr] Then Intake_Total := Intake_Total + ( All_IO_TotIT[ictr] As Number ); EndIF; If Exists All_IO_TotOP[ictr] Then Output_Total := Output_Total + (All_IO_TotOP[ictr] As NUMBER ) ; EndIF; EndDo; Fluid_Balance := Intake_Total - Output_Total; if exists All_IO_RecDTm then Return_Data_item:= ("Intake Total","Output Totalr","Fluid Balance") ; Return_Data_item_value:= Intake_Total, Output_Total, Fluid_Balance ; Return_UOM_or_code := ("mL", "mL", "mL"); Return_relevant_time:= (max_io_time, max_io_time, max_io_time); Return_start_or_alt_name:= (min_io_time, min_io_time, min_io_time); Return_stop_or_alt_code:= (max_io_time, max_io_time, max_io_time); Return_user_or_other:= ""; Return_Significant_data:= ""; Return_Sig_Count := ""; endif; IF NOT Exists Return_Data_item_value Then Return_Data_item_value := "\b No I&O Summary Data Available. \b0" ; EndIf; /* // Orders ################################################################# ELSEIF Data_value_type = "Orders" THEN strSQL := " select o.name, isnull(o.summaryline,{{{SINGLE-QUOTE}}}{{{SINGLE-QUOTE}}}), requesteddtm " ||" , OTO.TaskName, therapeuticcategory, therapeuticcategoryID " ||" , max(OTO.PerformedFromDtm) " ||" from cv3order o " ||" left outer join cv3ordertaskoccurrence oto " ||" on oto.clientguid = o.clientguid " ||" and oto.orderguid = o.guid " ||" AND OTO.TaskStatusCode = {{{SINGLE-QUOTE}}}Performed{{{SINGLE-QUOTE}}} " ||" and oto.active = 1 " ||" join cv3ordercatalogmasteritem ocmi" ||" on ocmi.guid = o.ordercatalogmasteritemguid" ||" WHERE o.Active = {{{SINGLE-QUOTE}}}1{{{SINGLE-QUOTE}}} " ||" and o.OrderStatusLevelNum <= {{{SINGLE-QUOTE}}}50{{{SINGLE-QUOTE}}}" ||" and o.IsSuspended = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} " ||" and o.IsHeld = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} " || " and o.clientGUID = " || sql(Client_guid) ||" and o.chartguid = " || sql(client_chart_guid) ||" and o.clientvisitguid = " || sql(Client_visit_guid) ; IF strFilterSQL <> "" THEN // append condition strSQL := strSQL || " AND " || strFilterSQL ; ENDIF; IF Additional_condition <> "" THEN strSQL := strSQL || " AND " || Additional_condition ; ENDIF; strSQL := strSQL || " group by o.name, o.summaryline, requesteddtm, OTO.TaskName "; (ord_names, ord_summs, ord_times, task_names, cl_val, cl_code, task_times) := read { "" || strSQL , primarytime = requesteddtm }; if exists ord_names then Return_Data_item:= ord_names; Return_Data_item_value:= ord_summs; Return_UOM_or_code := ""; Return_relevant_time:= ord_times; Return_start_or_alt_name:= ""; Return_stop_or_alt_code:= ""; Return_user_or_other:= ""; Return_Significant_data:= task_times; endif; IF NOT Exists Return_Data_item then Return_Data_item_value := "\b No Active Order Data Available. \b0" ; EndIf; */ // Orders ############################################################ // ELSEIF Data_value_type = "Therap_Cat_Orders" THEN //"Abx Orders" THEN ELSEIF Data_value_type = "Orders" THEN /* //// Previous fetch of Antibiotics done by ClassType strsql:="select o.name,o.SummaryLine, tv.value, ct.code, requesteddtm " ||" from CV3ORder o" ||" join cv3catalogclasstypevalue tv" ||" on tv.catalogmasterguid = o.ordercatalogmasteritemguid" ||" inner join cv3classtype ct" ||" On tv.classtypeguid = ct.guid" ||" WHERE o.Active = {{{SINGLE-QUOTE}}}1{{{SINGLE-QUOTE}}} " ||" and o.OrderStatusLevelNum <= {{{SINGLE-QUOTE}}}50{{{SINGLE-QUOTE}}}" ||" and o.IsSuspended = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} " ||" and o.IsHeld = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} " ||" and o.clientguid = " || sql(Client_guid) //{{{SINGLE-QUOTE}}}9000001864400200{{{SINGLE-QUOTE}}}" ||" and o.ChartGUID = " || sql(Client_chart_guid) ||" and o.ClientVisitGUID = " || sql(Client_visit_guid) ; //||" and ct.code = {{{SINGLE-QUOTE}}}PN_Antibiotics{{{SINGLE-QUOTE}}}" ; */ /* if Additional_condition <> "All" then strsql:="select o.name,o.SummaryLine, therapeuticcategory, " ||" therapeuticcategoryID, " ||" requesteddtm, OTO.TaskName, max(OTO.PerformedFromDtm) " ||" from CV3ORder o" ||" left outer join cv3ordertaskoccurrence oto " ||" on oto.clientguid = o.clientguid " ||" and oto.orderguid = o.guid " ||" AND OTO.TaskStatusCode = {{{SINGLE-QUOTE}}}Performed{{{SINGLE-QUOTE}}} " ||" and oto.active = 1 " ||" join cv3ordercatalogmasteritem ocmi" ||" on ocmi.guid = o.ordercatalogmasteritemguid" ||" WHERE o.Active = {{{SINGLE-QUOTE}}}1{{{SINGLE-QUOTE}}} " ||" and o.OrderStatusLevelNum <= {{{SINGLE-QUOTE}}}50{{{SINGLE-QUOTE}}}" ||" and o.IsSuspended = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} " ||" and o.IsHeld = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} " ||" and o.clientguid = " || sql(Client_guid) ||" and o.ChartGUID = " || sql(Client_chart_guid) ||" and o.ClientVisitGUID = " || sql(Client_visit_guid) ; elseif Additional_condition = "All" then */ //Hide Start: By Shivprasad /* strsql := "select o.name,o.SummaryLine, ocmi.therapeuticcategory, " ||" therapeuticcategoryID, requesteddtm, OTO.TaskName, " ||" max(OTO.PerformedFromDtm), OrderStatusCode, StopDate " ||" , e.admininstructions, count(OTO.PerformedFromDtm) " ||" from CV3ORder o" ||" left outer join cv3ordertaskoccurrence oto " ||" on oto.clientguid = o.clientguid " ||" and oto.orderguid = o.guid " ||" AND OTO.TaskStatusCode = {{{SINGLE-QUOTE}}}Performed{{{SINGLE-QUOTE}}} " ||" and oto.active = 1 " ||" join cv3ordercatalogmasteritem ocmi " ||" on ocmi.guid = o.ordercatalogmasteritemguid " //||" WHERE o.Active = {{{SINGLE-QUOTE}}}1{{{SINGLE-QUOTE}}} " //||" and o.OrderStatusLevelNum <= {{{SINGLE-QUOTE}}}50{{{SINGLE-QUOTE}}}" ||" left outer join CV3MedicationExtension e " ||" on e.ClientGUID = o.ClientGUID " ||" and e.GUID = o.GUID " ||" WHERE o.clientguid = " || sql(Client_guid) ||" and o.ChartGUID = " || sql(Client_chart_guid) ||" and o.ClientVisitGUID = " || sql(Client_visit_guid) ||" and o.IsSuspended = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} " ||" and o.IsHeld = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} "; // endif; if Additional_condition <> "All" then strsql := strsql || " and o.Active = {{{SINGLE-QUOTE}}}1{{{SINGLE-QUOTE}}} " || " and o.OrderStatusLevelNum <= {{{SINGLE-QUOTE}}}60{{{SINGLE-QUOTE}}}"; IF Additional_condition <> "" THEN strSQL := strSQL || " AND " || Additional_condition ; endif; endif; IF strFilterSQL <> "" THEN strSQL := strSQL || " AND "|| strFilterSQL ; endif; strSQL := strSQL || " group by o.name, o.summaryline, requesteddtm, " ||" ocmi.therapeuticcategory, therapeuticcategoryID, OTO.TaskName, " ||" OrderStatusCode, Stopdate " ||" , e.admininstructions " ; */ //Hide End : By Shivprasad //Added By Shivprasad Jadhav For CSR : 32982 strsql := "select o.guid , o.name,o.SummaryLine, ocmi.therapeuticcategory, " ||" therapeuticcategoryID, requesteddtm, OTO.TaskName, " ||" max(OTO.PerformedFromDtm) as PerformDate, OrderStatusCode, StopDate " ||" , e.admininstructions, count(OTO.PerformedFromDtm) as cntPerformed ,0 as cntNotPerformed " ||" Into #Temp1 " ||" from CV3ORder o" ||" left outer join cv3ordertaskoccurrence oto " ||" on oto.clientguid = o.clientguid " ||" and oto.orderguid = o.guid " ||" AND OTO.TaskStatusCode = {{{SINGLE-QUOTE}}}Performed{{{SINGLE-QUOTE}}} " ||" and oto.active = 1 " ||" join cv3ordercatalogmasteritem ocmi " ||" on ocmi.guid = o.ordercatalogmasteritemguid " ||" left outer join CV3MedicationExtension e " ||" on e.ClientGUID = o.ClientGUID " ||" and e.GUID = o.GUID " ||" WHERE o.clientguid = " || sql(Client_guid) ||" and o.ChartGUID = " || sql(Client_chart_guid) ||" and o.ClientVisitGUID = " || sql(Client_visit_guid) ||" and o.IsSuspended = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} " ||" and o.IsHeld = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} "; // endif; if Additional_condition <> "All" then strsql := strsql || " and o.Active = {{{SINGLE-QUOTE}}}1{{{SINGLE-QUOTE}}} " || " and o.OrderStatusLevelNum <= {{{SINGLE-QUOTE}}}60{{{SINGLE-QUOTE}}}"; IF Additional_condition <> "" THEN strSQL := strSQL || " AND " || Additional_condition ; endif; endif; IF strFilterSQL <> "" THEN strSQL := strSQL || " AND "|| strFilterSQL ; endif; strSQL := strSQL || " group by o.guid ,o.name, o.summaryline, requesteddtm, " ||" ocmi.therapeuticcategory, therapeuticcategoryID, OTO.TaskName, " ||" OrderStatusCode, Stopdate " ||" , e.admininstructions " ; strsql1 := "select o.guid ,o.name,o.SummaryLine, ocmi.therapeuticcategory, " ||" therapeuticcategoryID, requesteddtm, OTO.TaskName, " ||" max(OTO.PerformedFromDtm) as PerformDate , OrderStatusCode, StopDate " ||" , e.admininstructions, IsNull (Case When ( OTO.TaskStatusCode = {{{SINGLE-QUOTE}}}Overdue{{{SINGLE-QUOTE}}}) Then COUNT(OTO.TaskStatusCode)End, 0) as cntNonPerformed " ||" Into #Temp2 " ||" from CV3ORder o" ||" left outer join cv3ordertaskoccurrence oto " ||" on oto.clientguid = o.clientguid " ||" and oto.orderguid = o.guid " ||" AND OTO.TaskStatusCode in( {{{SINGLE-QUOTE}}}Overdue{{{SINGLE-QUOTE}}}) " ||" and oto.active = 1 " ||" join cv3ordercatalogmasteritem ocmi " ||" on ocmi.guid = o.ordercatalogmasteritemguid " ||" left outer join CV3MedicationExtension e " ||" on e.ClientGUID = o.ClientGUID " ||" and e.GUID = o.GUID " ||" WHERE o.clientguid = " || sql(Client_guid) ||" and o.ChartGUID = " || sql(Client_chart_guid) ||" and o.ClientVisitGUID = " || sql(Client_visit_guid) ||" and o.IsSuspended = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} " ||" and o.IsHeld = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} "; // endif; if Additional_condition <> "All" then strsql1 := strsql1 || " and o.Active = {{{SINGLE-QUOTE}}}1{{{SINGLE-QUOTE}}} " || " and o.OrderStatusLevelNum <= {{{SINGLE-QUOTE}}}60{{{SINGLE-QUOTE}}}"; IF Additional_condition <> "" THEN strSQL1 := strSQL1 || " AND " || Additional_condition ; endif; endif; IF strFilterSQL <> "" THEN strSQL1 := strSQL1 || " AND "|| strFilterSQL ; endif; strSQL1 := strSQL1 || " group by o.guid ,o.name, o.summaryline, requesteddtm, " ||" ocmi.therapeuticcategory, therapeuticcategoryID, OTO.TaskName, OTO.TaskStatusCode, " ||" OrderStatusCode, Stopdate " ||" , e.admininstructions " ; strsql2 := "select o.guid ,o.name,o.SummaryLine, ocmi.therapeuticcategory, " ||" therapeuticcategoryID, requesteddtm, OTO.TaskName, " ||" max(OTO.PerformedFromDtm) as PerformDate , OrderStatusCode, StopDate " ||" , e.admininstructions, IsNull (Case When (OTO.TaskStatusCode = {{{SINGLE-QUOTE}}}Not Performed{{{SINGLE-QUOTE}}} ) Then COUNT(OTO.TaskStatusCode)End, 0) as cntNonPerformed " ||" Into #Temp3 " ||" from CV3ORder o" ||" left outer join cv3ordertaskoccurrence oto " ||" on oto.clientguid = o.clientguid " ||" and oto.orderguid = o.guid " ||" AND OTO.TaskStatusCode = {{{SINGLE-QUOTE}}}Not Performed{{{SINGLE-QUOTE}}} " ||" and oto.active = 1 " ||" join cv3ordercatalogmasteritem ocmi " ||" on ocmi.guid = o.ordercatalogmasteritemguid " ||" left outer join CV3MedicationExtension e " ||" on e.ClientGUID = o.ClientGUID " ||" and e.GUID = o.GUID " ||" WHERE o.clientguid = " || sql(Client_guid) ||" and o.ChartGUID = " || sql(Client_chart_guid) ||" and o.ClientVisitGUID = " || sql(Client_visit_guid) ||" and o.IsSuspended = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} " ||" and o.IsHeld = {{{SINGLE-QUOTE}}}0{{{SINGLE-QUOTE}}} "; // endif; if Additional_condition <> "All" then strsql2 := strsql2 || " and o.Active = {{{SINGLE-QUOTE}}}1{{{SINGLE-QUOTE}}} " || " and o.OrderStatusLevelNum <= {{{SINGLE-QUOTE}}}60{{{SINGLE-QUOTE}}}"; IF Additional_condition <> "" THEN strSQL2 := strSQL2 || " AND " || Additional_condition ; endif; endif; IF strFilterSQL <> "" THEN strSQL2 := strSQL2 || " AND "|| strFilterSQL ; endif; strSQL2 := strSQL2 || " group by o.guid ,o.name, o.summaryline, requesteddtm, " ||" ocmi.therapeuticcategory, therapeuticcategoryID, OTO.TaskName, OTO.TaskStatusCode, " ||" OrderStatusCode, Stopdate " ||" , e.admininstructions " ; // strSQL := strSQL || strSQL1 || " " || " Update p set p.cntNotPerformed=np.cntNonPerformed from #Temp1 p join #Temp2 np on p.Name=np.Name " // || " Select * from #Temp1 Drop Table #Temp1 Drop Table #Temp2 "; strSQL := strSQL || strSQL1 || strSQL2 || " " || " Update p set p.cntNotPerformed=(np.cntNonPerformed + np1.cntNonPerformed)from #Temp1 p join #Temp2 np on p.guid=np.guid join #Temp3 np1 on p.guid=np1.guid " || " Select name,SummaryLine, therapeuticcategory,therapeuticcategoryID, requesteddtm, TaskName, PerformDate , OrderStatusCode, StopDate ,admininstructions, cntPerformed , cntNotPerformed from #Temp1 Drop Table #Temp1, #Temp2 , #Temp3 "; //name,SummaryLine, therapeuticcategory,therapeuticcategoryID, requesteddtm, TaskName, PerformDate , OrderStatusCode, StopDate ,admininstructions, cntPerformed , cntNotPerformed // End : Shivprasad Code (ord_names, ord_summs, cl_val, cl_code, ord_times, task_names, task_times, o_stat, Stop_d, ord_admin_inst, num_given, Num_Nt_given) := read //Num_Nt_given Addedby Shivprasad for CSR:32982 { "" || strSQL , primarytime = requesteddtm }; if exists ord_summs then Return_Data_item:= ord_names; Return_Data_item_value:= ord_summs; Return_UOM_or_code:= cl_val; // therapeuticcategory Return_relevant_time:= ord_times; // Return_start_or_alt_name:= ""; Return_start_or_alt_name:= ord_admin_inst; Return_stop_or_alt_code:= stop_d; Return_user_or_other:= o_stat; Return_Significant_data:= task_times; Return_Sig_Count := num_given; Return_Sig_nt_Count := Num_Nt_given ; //Added By Shivprasad Jadhav For CSR : 32982 endif; IF NOT Exists Return_Data_item_value Then Return_Data_item_value := "\b No Active Antibiotic Data Available. \b0" ; EndIf; //LAb Results ############################################################### ELSEIF Data_value_type IN ( "Lab Results", "Micro Results") THEN strsql:= "select o.Name, o.GUID, o.PerformedDtm, bo.ItemName, bo.Value, " ||" bo.ResultItemCode, bo.entered, tol.Text, bo.unitofmeasure " ||" from CV3Order o " ||" join CV3BasicObservation bo on bo.clientguid = o.clientguid " ||" and bo.chartguid = o.chartguid " ||" and bo.clientvisitguid = o.clientvisitguid " ||" and o.GUID = bo.OrderGUID " ||" left outer join CV3TextualObservationLine tol " ||" on bo.clientguid = tol.clientguid " ||" and bo.GUID = tol.ObservationGUID" ||" where o.clientguid = "|| sql(Client_guid) ||" and o.ChartGUID = " ||sql(Client_chart_guid) ||" and bo.entered >= "|| sql(current) ||" and IsHistory = 0 " ; //||" order by o.Name desc"; IF strFilterSQL <> "" THEN strSQL := strSQL || " AND "|| strFilterSQL ; endif; if data_value_type = "Lab Results" then strSQL := strSQL || " group by o.Name , o.GUID, o.PerformedDtm, bo.ItemName, " ||" bo.Value, bo.ResultItemCode, bo.entered, tol.Text, bo.unitofmeasure "; endif; (ord_names, ord_guids, ord_times, cl_names, cl_vals, cl_codes, cl_enter, cl_text, cl_uom ) := read { "" || strSQL || "order by o.name desc" }; if exists ord_names then Return_Data_item:= ord_names; Return_Data_item_value:= cl_vals; Return_UOM_or_code := cl_uom; Return_relevant_time:= ord_times; Return_start_or_alt_name:= cl_names; Return_stop_or_alt_code:= cl_codes; Return_user_or_other:= ord_guids; Return_Significant_data:= cl_text; Return_Sig_Count := ""; endif; IF NOT Exists Return_Data_item Then Return_Data_item_value := "\b No Results. \b0" ; EndIf; ENDIF; // CASE STMT FOR POSSIBLE HISTORICAL LOOKUPS ENDIF; // Getdata_from = "Historical" ;; priority: 50 ;; evoke: ;; logic: conclude true; ;; action: return Return_Data_item, Return_Data_item_value, Return_UOM_or_code , Return_relevant_time, Return_start_or_alt_name, Return_stop_or_alt_code, Return_user_or_other, Return_Significant_data, This_communicationobj, Return_sig_count, Return_Sig_nt_Count; // Added By Shivprasad Jadhav For CSR : 32982 ;; Urgency: 50;; end: