0

use array or better selection query?

Hi

I am developing a database to assist with followup on patients attending our hospital.

I am trying to create an list of patients who were admitted during a specified date range (usually 10-14 days after discharge), and stayed overnight.

The data is being drawn from a table called 'AGENDA' which is essentially all of the diary entries for the hospital.

This is the code I wrote initially. This works well, but if there are any patients that were admitted or discharged after the selected date range, they fail to be selected.

 

let sd := 'First admission date';
let ed := 'Second admission date';
let list := (select Agenda where Date >= sd and Date <= ed and contains(analysis, "Admit") and PatientID.'last discharge date' > Date and PatientID.'last discharge date' <= ed);
list

 

Then, I wondered if I need to create an array from two disctint select... query scripts, and then refine the selection.  However, I can't seem to get this to work....

let sd := 'First admission date';
let ed := 'Second admission date';
let admit := (select Agenda where Date >= sd and Date <= ed and contains(analysis, "Admit"));
let admitdate := admit.Date;
let discharge := (select Agenda where Date >= sd and Date <= ed and contains(analysis, "Discharge"));
let dischargedate := discharge.Date;
let myarray := (array(admit,discharge));
let selection := myarray[dischargedate > admitdate]
selection

 

I'd be grateful for any guidance on where I am going wrong?

 

Thanks

Jonathan

1reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
    • Fred
    • Fred
    • 9 days ago
    • Reported - view

    This line doesn’t work:

    let selection := myarray[dischargedate > admitdate]

    because dischargedate and admitdate are arrays as well. Since admit and discharge are arrays, you just created an array of dates.

    To compare two arrays you can get more background from this post.

    You can try something like:

    let selection := admit[var v := this;
                    count(discharge[Date > v.Date])>0]
    

    Here we are taking each instance in the admit array and put in the variable v. Then we take each instance in the discharge array and see if the Date in discharge is greater than the Date in admit. We only keep instances where the count is greater than 0.

    Like
Like Follow
  • 9 days agoLast active
  • 1Replies
  • 28Views
  • 2 Following