need to get data based on a date plus or minus four hours from another date

Posted on 2014-09-05
Medium Priority
Last Modified: 2014-09-22
Attached is a report.  i need to pull the medication 'taken time' based on four hours plus or minus the procedure start time.

The procedure start time is a calculated field based on a given event.  The formula is on the report called procedure start.

Example:  Test Heidi had a surgery on 6/10.  There are two taken times showing, because the report is pulling all medications she has ever been given.  I want just the medications given +/- four hours from the procedure start time.

Thank you for your assistance.
Question by:Becky Edwards
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 75

Expert Comment

by:Anthony Perkins
ID: 40307046
You may find members here somewhat hesitant about downloading a file here, especially one.that is not txt or pdf.  So if you are trying to describe something here you may be better off pasting it in as an image.
LVL 35

Expert Comment

ID: 40307434
Anthony Perkins,

 Posting the actual report (RPT) file is usually the best option with a question like this, as long as the report doesn't include any "sensitive" information.  That way we can see the report structure, etc. for ourselves.

 FWIW, in this case the file d/l'ed with an HTML extension, but it is actually a CR report file.  I'm not sure what happened there.  I recently read that EE was having problems with some file uploads, so maybe EE changed the extension.

LVL 16

Accepted Solution

DcpKing earned 2000 total points
ID: 40307435
Within the report, or within the code providing data for the report, you can probably use a function datediff to get the number you want.

datediff has 3 parameters - the units, the first datetime, and the last datetime. Note that the format of the units can vary - in SSRS "m" indicates months whereas in T-SQL you use just an m - no quotes!

So in your case you have a patient who had surgery on June 10 but you must also have a time. So we'll assume that surgery was started at 2014:06:10 15:00:00 (3 pm). This can be called tiSurgery.

In a query for all medications administered +/- four hours of that time one would be comparing a medication administration datetime from a table, which can be called tiMedAdmin, in the following way:

abs (  datediff(hour, tiSurgery, tiMedAdmin)  )  < 4

Values where tiMedAdmin is before tiSurgery will be negative, hence the use of the abs() function (absolute value).


Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

LVL 35

Expert Comment

ID: 40307449

 Group selection may work.  Go to Report > Selection Formulas > Group and enter the following formula:

 DateAdd ("h", -4, Maximum ({@Proc Start}, {ORDER_MED.ORDER_MED_ID})) to
 DateAdd ("h", 4, Maximum ({@Proc Start}, {ORDER_MED.ORDER_MED_ID}))

 That uses DateAdd to subtract 4 hours from the start time and add 4 hours, to create the range.

 I am assuming that ORDER_MED_ID is a unique ID for every time a patient is given any medication, as opposed to an ID for the medications themselves.  IOW, you do not have the same ORDER_MED_ID for every time a patient is given medication X.  (I hope that made sense :-)

 If the group selection formula works, note that group selection is really suppression.  The report is still reading all of the same records (it has to, in order to get the value for {@Proc Start}, and then determine if that group should be included).  So, if you use any CR summaries, they will include the groups that are not shown.  Also, if the group tree is visible when someone runs the report, the tree will include the groups that are not shown, but if someone tries to select one of them, CR will just move to the nearest visible group.

 If the group selection works, but, for example, you want to use summaries, or the report is just reading a lot of extra data that is then not shown, and that slows the report down; then you may need to do this by writing a query that selects the correct data before it is sent to the report, and using that as the datasource.  That would be the most efficient solution.


Author Closing Comment

by:Becky Edwards
ID: 40337389
Actually, Mike, this is what I was looking for. A way to create a formula based on two fields.  I may have problems because one of the fields is actually a formula, but I will cross that road when I get there.

Thank you,

LVL 16

Expert Comment

ID: 40337774
Then ask that question too (separately). Post a comment here saying you're starting another question, with the question title, and people who've seen this one can help you there too.

As for the field being a formula, do you mean that it is an expression involving two or more other fields? If so, you might get something like this:

abs (  datediff(hour, tiSurgery, (tiMedStart + (3 * tiMedInterval) ) )  )  < 4

where you might be looking at a start time and a number of intervals after (where meds are given at each interval)



Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question