Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Patients that return within 30 days of last visit

Patients that return within 30 days of last visit

Patients that return within 30 days of last visit

Good day to all,

I am using Crystal 2011 with SQL database. I have historical visit data on patients. I want to pull patients that have a patient type of "ONC" if they came to the ER (patient type "ED") within 30 days following their "ONC" visit. I was thinking I might have to do a main and a sub... pulling the ONC patients in the main and somehow use the sub to filter them if they presented in 30 days to the ER. Stumped at the moment and would like your help with a solution. Thanks in advance!

RE: Patients that return within 30 days of last visit

First limit the patient type in the record selection formula to the two types and add a date for the start of the evaluation period. Then create two formulas:

//{@ONC Date}:
if {table.patienttype}="ONC" then

//{@ER Date}:
if {table.patienttype}="ER" then

Insert a group on patient and then go to report->selection formula->GROUP and enter:

distinctcount({table.patienttype})=2 and
{@ER Date} >{@ONC Date} and
datediff("d",{@ERDate},{@ONC Date})<= 30


RE: Patients that return within 30 days of last visit

Sorry, that should have been:

distinctcount({table.patienttype},{table.patientID})=2 and
{@ER Date} >{@ONC Date} and
datediff("d",minimum({@ERDate},{table.PatientID}),maximum({@ONC Date},{table.patientID}))<= 30

Not sure how this will play out if patients have more than one of each date. Would have to see some sample data to decide how to handle this.


RE: Patients that return within 30 days of last visit

Thanks lbass for your quick response... Yes there can be more than one of each date for both ONC (CCCCS) and ER visits. I have included some sample data below... apologize for the formatting but not sure how to make it display right on the forum here. For privacy sake there are no names. Med rec no is the patient id. I used your date formulas to pull some records. Here is the code:

If {TSM180_MST_COD_Pat_Type.cod_dtl_ext_id}='CCCCS' then

ERDate is the same with the exception of changing it to 'ER'. I applied the group criteria but don't think it is working as it should... may be due to multiple date issues. Hope this helps.

med_rec code ONCDate ERDate
00200016 ER 09/27/2017
00200108 ER 09/04/2017
00200108 ER 09/12/2017
00200108 ER 09/14/2017
00200108 CCCCS 08/17/2017
00200108 ER 08/26/2017
00200108 ER 09/02/2017
00200108 ER 09/03/2017
00202109 ER 09/29/2017
00202225 ER 09/28/2017
00202336 ER 08/27/2017
00202360 ER 08/04/2017
00202372 ER 09/03/2017
00202386 CCCCS 08/31/2017
00202449 ER 09/05/2017
00202614 ER 08/10/2017
00202670 ER 08/31/2017
00202694 ER 09/13/2017
00202704 CCCCS 09/27/2017
00202704 CCCCS 08/14/2017
00202784 ER 08/13/2017
00202844 ER 08/19/2017
00202918 ER 08/18/2017
00202925 ER 08/29/2017
00202925 ER 09/27/2017
00202966 ER 09/07/2017
00202966 ER 09/23/2017
00203055 CCCCS 09/15/2017
00203055 CCCCS 08/18/2017
00203099 ER 09/30/2017
00203111 ER 08/06/2017
00203111 CCCCS 09/12/2017
00203111 CCCCS 08/14/2017
00203152 ER 09/16/2017
00203200 ER 08/08/2017
00203200 ER 09/06/2017

RE: Patients that return within 30 days of last visit

It looks to me like your sample data only has one patient that meets your criteria. If you applied my group selection formula, you should see 0020108. But on second thought, I think the last line of my formula should be changed to remove the minimum({@ERDate},{table.patientID}) and replace it just with {@ERdate}. Leave the rest of the datediff clause as is.

Please show the results you get for your sample data after implementing this change so I can see how it is displaying. This should show any ER activity within the thirty days following the most recent ONC date for that patient.


RE: Patients that return within 30 days of last visit

Thanks again for your assistance...
Here is my current record selection:

{TSM180_MST_COD_Pat_Type.cod_dtl_ext_id}in['CCCCS','ER'] and//Cancer Center Patients, ER Patients

Here is the group selection (grouped on Medrec #:

distinctcount({TSM180_MST_COD_Pat_Type.cod_dtl_ext_id})=2 and

Here are a couple of observations... I don't think the results are eliminating patients that are ER visits only. I only want to see cancer patients that had an ER visit within 30 days of their "CCCCS" visit. Also when I add the group criteria above the @ONCDate disappears from the data and @ERDate is all that is there. Somehow the ER patients that are not Cancer center patients need to be eliminated if possible before the 30 day timeframe is evaluated... ??.. I think. Again... thanks for your expert assistance lbass.

RE: Patients that return within 30 days of last visit

Is the medical record no the patient ID or is it specific to a visit? Assuming that it IS the patient ID and that you have grouped on it, you just need to add the group clause to the first line of the group selection formula—look back at my code. Right now your formula is just checking the whole report to see if there are two types of patients, when it is meant to be checking whether there are two types per patient.


RE: Patients that return within 30 days of last visit

The medical record number is unique to each patient. I have used it as the grouping field here. Patients also will have a visit number that is unique for that visit. All unique visits for a patient regardless of type or reason point to his\her medical record number... ie:

MR# M003516789 John Doe can have multiple unique visits:
Visit# 4000345891, 4000456987, 4000789553 etc. etc.

I was assuming the Datediff clause was taking care of the group select... I see now what you mean... so my group select before your distinctcount statement should be... ????= (????, {TPM300_PAT_VISIT.med_rec_no}) Sorry for being a little slow on the uptake here... Thanks for your help and patience.

RE: Patients that return within 30 days of last visit

Copy the formula below and then go to report->selection formula->GROUP and paste it in. This is the entire formula--don't add anything to it, please:

distinctcount({TSM180_MST_COD_Pat_Type.cod_dtl_ext_id}, {TPM300_PAT_VISIT.med_rec_no})=2 and


RE: Patients that return within 30 days of last visit

Lbass... I believe this will do it! Thank you sir for your kind, professional, patient, instructional, and expert assistance! They will have to pick through the results carefully to get the exact records they want because of the possibility of multiple visits and accounts but this will produce the record set required I'm sure. Thanks again and if you ever decide to run for president let me know... you'll have my vote! :>)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close