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

Posted on 2014-09-05
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 500 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).


PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

717 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