Concurrent/consecutive events

pekara2

New Member
Joined
Apr 9, 2014
Messages
2
Hi

I'm hoping that someone can help me with this issue before I become folically challenged..... I work in Health and one the areas that I want to investigate is the transfer of patients between hospital sites. So far no problem as long as the patient only moves a limited number of times biut its not proving to be that simple......

IDPatientAdmission dateDischarge datesite
1Mrs White1/1/157/1/15a
2Mr Pink3/1/56/1/15a
3Mr Pink6/1/1510/1/15b
4Mrs White7/1/1512/1/15b
5Ms Black8/1/1512/1/15a
6Mrs White8/1/158/1/15a
7Mr Pink10/1/1512/1/15c
8Ms Black12/1/1518/1/15b
9Mr Pink12/1/1515/1/15a
10Mr Pink15/1/1528/1/15b

<TBODY>
</TBODY>



















What I need to get to is - can anyone help?

IDPatientAdmission dateDischarge date
A1Mrs White1/1/1512/1/15
A2Mr Pink3/1/1528/1/15
A3Ms Black8/1/1518/1/15

<TBODY>
</TBODY>
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi

Can you not just take for each patient the minimum date for Admission and the Maximum for Descharge?
 
Upvote 0
Not really as the patient might be admitted again for another (unlinked) spell e.g. Mrs White might be an inpatient again on the 17/4/15...... It is driving me to distraction at the moment....
 
Upvote 0
I've added an additional 4 columns to the Table

Text - InSite
Text - OutSite
DateTime - InDate
DateTime - OutDate

This piece of code would then update all the fields looking for continued stay.

Code:
Option Compare Database
Sub ContinuedStay()
Dim rs As DAO.Recordset
Dim tempRs As DAO.Recordset
Dim pRecord As Variant
Dim temp As Variant


Set rs = CurrentDb.OpenRecordset("SELECT * From Data")
temp = rs.GetRows(10)
If Not (rs.EOF And rs.BOF) Then
    rs.MoveFirst 'Unnecessary in this case, but still a good habit
    Do Until rs.EOF = True
        Set tempRs = CurrentDb.OpenRecordset("SELECT * From Data WHERE Patient = '" & rs!Patient & "' AND [Admission date] = #" & Format(rs("Discharge date"), "mm/dd/yyyy") & "#")
        If tempRs.RecordCount > 0 Then
            pRecord = tempRs.GetRows(1)
            Do Until tempRs.RecordCount = 0
                Set tempRs = CurrentDb.OpenRecordset("SELECT * From Data WHERE Patient = '" & pRecord(1, 0) & "' AND [Admission date] = #" & Format(pRecord(3, 0), "mm/dd/yyyy") & "# AND [Discharge date] <> #" & Format(pRecord(3, 0), "mm/dd/yyyy") & "#")
                If tempRs.RecordCount > 0 Then pRecord = tempRs.GetRows(1)
            Loop
            tempRs.Close
                rs.Edit
                rs!InSite = rs!Site
                rs!OutSite = pRecord(4, 0)
                rs!InDate = rs("Admission date")
                rs!OutDate = pRecord(3, 0)
                rs.Update
        Debug.Print rs!ID
        Else
                rs.Edit
                rs!InSite = rs!Site
                rs!OutSite = rs!Site
                rs!InDate = rs("Admission date")
                rs!OutDate = rs("Discharge date")
                rs.Update
                Debug.Print rs!ID
        End If
        rs.MoveNext
        Erase pRecord
    Loop
Else
    MsgBox "There are no records in the recordset."
End If


MsgBox "Finished looping through records."


rs.Close 'Close the recordset
Set rs = Nothing 'Clean up
Set tempRs = Nothing 'Clean up
End Sub

You could then write a query to return the min(InDate) and Max(OutDate) for each patient???

Excel 2010
ABCDEFGHI
1IDPatientAdmission dateDischarge datesiteInSiteOutSiteInDateOutDate
21Mr Pink03/01/200506/01/2015aaa03/01/200528/01/2015
36Mrs White01/01/201507/01/2015aac01/01/201512/01/2015
48Mrs White08/01/201508/01/2015bbb08/01/201508/01/2015
59Ms Black08/01/201512/01/2015aab08/01/201518/01/2015

<tbody>
</tbody>
Data



A possible erroneous entry at ID 8 as Mrs White was at two different Hospitals on the same date.
 
Last edited:
Upvote 0
Here's what the Query might look like.

Select A.*, B.InSite, B.OutSite FROM
(SELECT DISTINCT Patient, Min(InDate) As Admission, OutDate As Discharge FROM Data
Group By Patient, OutDate) As A
LEFT Join Data As B
ON A.Patient + Format(A.Admission, "ddmmyy") = B.Patient + Format(B.InDate, "ddmmyy")
 
Upvote 0

Forum statistics

Threads
1,221,845
Messages
6,162,350
Members
451,760
Latest member
samue Thon Ajaladin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top