Here is more information regarding this request:
This is an Oracle 9i database.
The patient data is in one table and the comments are in another with a one to many relationship (joined by a textid in each table).
We can't change the database, beings it is a third party vendor application.
Here is the sql:
SELECT
'Inpatient' AS Source,
pt.Active,
pt.Brandname,
pt.Computed_Form,
pt.Computed_FrequencySig,
pt.Computed_ItemOrder,
pt.Description,
NVL(pt.Dosestrength,'0') AS Dosestrength,
pt.FrequencyCode,
pt.HospitalNumber as Patient_ID,
pt.ItemType,
pt.PRN,
pt.Profile,
pt.Room,
pt.Route,
pt.RXNumber,
pt.StartDate,
pt.StopDate,
0 AS Dose_Amount,
'' AS Dose_Due,
'' AS Dose_Unit_Desc,
'' AS Frequency_Desc,
'' AS Last_Taken,
'' AS Med_Hist_Comment,
'' AS Med_Name,
'' AS Route_Description,
'' AS Status_Desc,
pt.Description || pt.Dosestrength ||pt.Computed_FrequencySig as DrugDoseFreq,
tl.linenumber,
tl.textline
FROM
HCS.PATIENTTHERAPY_VIEW pt
INNER JOIN HCS.TEXTLINE tl ON tl.textid = pt.therapycommentstextid
WHERE
pt.HospitalNumber = :AccountNbr AND
(pt.ROUTE IS NULL OR pt.ROUTE NOT IN ('IV','EPID', 'FNB')) AND
pt.PROFILE IN ('IT','IV','MED','TPN') AND
pt.ACTIVE = 'Y' AND
pt.FrequencyCode NOT IN ('NOW','ONCALL','ONCE','STAT','X1') AND
(pt.STOPDATE IS NULL OR pt.STOPDATE >= SYSDATE) AND
(pt.Computed_FrequencySig Is Null Or pt.Computed_FrequencySig=' ' Or (pt.Computed_FrequencySig Not Like '%AS%NEEDED%' AND pt.Computed_FrequencySig Not Like '%PRN%'))
____________________________________________________________
Here is better display of the sample data:
Description Dose PatientID LineNumber Comment
Albuterol-Ipratropium 0 123456789 1 QID/PRN
Calcium Acetate 667 123456789 0
Carvedilol 12.5 123456789 0
Cinacalet 30 123456789 0
Insuline Regular Human 1 unit/0.01 ML 123456789 1 ***Sliding scale regular insulin**
Insuline Regular Human 1 unit/0.01 ML 123456789 3 Give 30 minutes before meal
Insuline Regular Human 1 unit/0.01 ML 123456789 2 (BS-100)/30=# of units of insulin