Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to achieve this.......

2710998Jul 22 2014 — edited Jul 22 2014

Hi All,

I have patients information in the following manner, this tells us when the patient was admitted and discharged and in between where the patient was transferred i,e one department to another. If the patient is transferred from one department to another the outgoing department is flagged as transfer-out and the new department is flagged as transfer-in.Within each department there are multiple beds, even within same department if the patient is moved from one bed to another this will also be captured as transfer-out and transfer-in, following data for your reference

SQL..

select A.pat_id,A.pat_enc_csn_id,P.hsp_account_id,A.department_id,d.department_name,A.bed_id,

TO_CHAR(A.effective_time, 'MM-DD-YYYY HH24:MI:SS') As admit_dte,

case when A.event_type_c = 1 then 'Admission'

     when A.event_type_c = 2 then 'Discharge'

     when A.event_type_c = 3 then 'Transfer-in'

     when A.event_type_c = 4 then 'Transfer-out'

     when A.event_type_c = 5 then 'Patient-update'

     when A.event_type_c = 6 then 'Census'

     when A.event_type_c = 7 then 'Hospital outpatient'

     when A.event_type_c = 8 then 'Leave of absense'

     else 'Leave of absense return' END AS event_type

from clarity_adt@clarprod A

inner join clarity_dep@clarprod d

on A.department_id = d.department_id

inner join hsp_account@clarprod P

on A.pat_enc_csn_id = P.prim_enc_csn_id

where

P.hsp_account_id = 46131492010

group by A.pat_id,A.pat_enc_csn_id,A.department_id,d.department_name,P.hsp_account_id,A.effective_time,A.bed_id,A.event_type_c

order by admit_dte

Pat_id               Pat_enc_csn_id   Hsp_account               Dept_id               Dept_name                                                 Bed_id            Admit_date                                    Event_type

Z325065458367367461314920101055137EMERGENCY CENTER RO100230106-01-2014 15:12:00Admission
Z325065458367367461314920101055137EMERGENCY CENTER RO100230106-01-2014 15:12:00Transfer-out
Z325065458367367461314920101055137EMERGENCY CENTER RO100180806-01-2014 15:12:00Transfer-in
Z325065458367367461314920101055137EMERGENCY CENTER RO100180806-01-2014 20:25:00Transfer-out
Z3250654583673674613149201010550715 ST PEDS TEAM CARE B10532506-01-2014 20:25:00Transfer-in
Z3250654583673674613149201010550715 ST PEDS TEAM CARE B10532506-01-2014 20:30:00Transfer-out
Z3250654583673674613149201010550715 ST PEDS TEAM CARE B10533406-01-2014 20:30:00Transfer-in
Z3250654583673674613149201010550715 ST PEDS TEAM CARE B10533406-05-2014 20:30:00Transfer-out
Z3250654583673674613149201010550625 SOUTH TOWER PICU10546506-09-2014 14:14:00Transfer-in
Z3250654583673674613149201010550625 SOUTH TOWER PICU10546506-09-2014 14:54:00Transfer-out
Z3250654583673674613149201010550715 ST PEDS TEAM CARE B10533406-09-2014 15:30:00Transfer-in
Z3250654583673674613149201010550715 ST PEDS TEAM CARE B10533406-10-2014 14:50:00Discharge

Now my requirement is to report the patient movement (transfer-in,transfer-out) only at department level and ignore the movement between beds in the same department, below is what I want, taken first 2 departments.

Pat_id                 Pat_enc_csn_id    hsp_account                  dept_id             dept_name                                                             admit_date                                  event_type

Z325065458367367461314920101055137EMERGENCY CENTER RO06-01-2014 15:12:00Admission
Z325065458367367461314920101055137EMERGENCY CENTER RO06-01-2014 20:25:00Transfer-out
Z3250654583673674613149201010550715 ST PEDS TEAM CARE B06-01-2014 20:25:00Transfer-in
Z3250654583673674613149201010550715 ST PEDS TEAM CARE B06-05-2014 20:30:00Transfer-out

Can some one please help me achieving this logic.

Hope I made it clear, using oracle 11g.

Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 19 2014
Added on Jul 22 2014
4 comments
376 views