We help IT Professionals succeed at work.

How do I create a daily census?

302 Views
Last Modified: 2013-11-27
This seems like it should be easy, but I can't figure it out.  I have a database that includes a table with all patients admitted to our ICU including the date and time of admission and discharge from the ICU.  We need to generate a daily census between two dates (can be entered by the person running the query) to count the number of patients in the ICU on each date at a specific time (08:00 AM).

For example if we need the data from Jan 1, 2007 to Jan 31, 2007 I would like to end up with a table that has a row for each date in that range and the number of patients in the ICU at 08:00 AM on that date.

Thank you very much,

Paul Warshawsky
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2010

Commented:
Hello Paul,

T make this work well, you will need another table, tblDays, that has dates in it, covering any
conceivable date you might need for the query.  Assuming you build that table (it would be
very easy to populate with VBA code), then something like this could work:

SELECT d.Dt,
    (SELECT Count(p.*)
    FROM tblPatients t
    WHERE t.AdmittedAt <= (d.Dt + TimeValue([Enter census time])) AND
        t.DischargedAt >= (d.Dt + TimeValue([Enter census time]))) AS PatientCount
FROM tblDays t
WHERE d.Dt Between [Enter start date] AND [Enter end date]
ORDER BY d.Dt

Regards,

Patrick
CERTIFIED EXPERT
Top Expert 2010

Commented:
Paul,

And to use form controls rather than parameters:

SELECT d.Dt,
    (SELECT Count(p.*)
    FROM tblPatients t
    WHERE t.AdmittedAt <= (d.Dt + TimeValue([Forms]![NameOfForm]![CensusTime])) AND
        t.DischargedAt >= (d.Dt + TimeValue([Forms]![NameOfForm]![CensusTime]))) AS PatientCount
FROM tblDays t
WHERE d.Dt Between [Forms]![NameOfForm]![StartDate] AND [Forms]![NameOfForm]![EndDate]
ORDER BY d.Dt


Regards,

Patrick

Author

Commented:
This sort of solution occurred to me as well, but I have to say it seems a bit clunky (no offense intended!)  We may need this data from 3 years ago or 5 years from now, meaning I have to have a table with a decade worth of dates in it (or update the table regularly in the future.)

The census time is fixed (8:00 AM), by the way.  Also would need to deal with patients who have not been discharged (i.e. DischargeDateTime is NUL).

Any other thoughts?

Paul
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.