I'm trying to group multiple medical claims into one event, or inpatient stay. To keep this simple, let's say I have a patient who goes to the hospital on 1/1/2017, is released on 1/5/2017, and is transferred to another hospital on that same day, and is released from that other hospital on 1/10/2017.
So I have two claims, one with an admit date of 1/1/2017 and discharge date of 1/5/2017, and the other claim has an admit date of 1/5/2017 and discharge date of 1/10/2017. Because one starts right after the other, it is considered one inpatient stay.
In Oracle, I would like to combine that into one line, with an admit date of 1/1/2017, and a discharge date of 1/10/2017, based on the fact that the one claim has a discharge date of 1/5/2017, and the second claim has an admit date on that same date.
Any help on which direction to go into would be greatly appreciated.
UPDATE: Please see the sample data below:
CLAIM_ID MEME_RECORD_NO ADMIT_DATE DISCHARGE_DATE
1 127300 1/3/2017 1/11/2017
2 127300 1/12/2017 1/20/2017
3 180100 1/3/2017 1/6/2017
4 180100 1/6/2017 1/20/2017
5 265700 1/2/2017 1/5/2017
6 265700 1/5/2017 1/17/2017
7 300000 2/1/2017 2/5/2017
8 300000 2/5/2017 2/9/2017
9 300000 2/9/2017 2/12/2017
CLAIM_ID 1 and 2 are separate events, since the ADMIT_DATE for CLAIM_ID 2 is greater than the discharge date for CLAIM_ID 1 (even though they're the same patient), CLAIM_ID 3 and CLAIM_ID 4 combined is one event, since the discharge date for CLAIM_ID 3 is the same as the ADMIT_DATE for CLAIM_ID 4, and the scenario repeats itself for CLAIM_ID's 5 and 6. For CLAIM_ID'S 7, 8 and 9, this is also one event, so all 3 would be combined. In addition to actually grouping them, I would also like to number the rows with an EVENT_ID field
Assuming the above were a table, and I queried it, the output should be 5 events. The final product should look like this:
EVENT_ID MEME_RECORD_NO ADMIT_DATE DISCHARGE_DATE
1 127300 1/3/2017 1/11/2017
2 127300 1/12/2017 1/20/2017
3 180100 1/3/2017 1/20/2017
4 265700 1/2/2017 1/17/2017
5 300000 2/1/2017 2/12/2017
I really appreciate any help on this.
Related
I would like to calculate the time difference in months from the first timestamp for each row of the same ID.
For example my data currently looks similar to this:
ID TimeStamp
1 01-Jan-21
1 26-Apr-21
2 03-Jan-21
2 26-May-21
2 26-Oct-21
3 04-Jan-21
3 18-Mar-21
I would like it to look like this:
ID TimeStamp MonthSince1st
1 01-Jan-21 .
1 26-Apr-21 3
2 03-Jan-21 .
2 26-May-21 4
2 26-Oct-21 9
3 04-Jan-21 .
3 18-Mar-21 2
What should I do?
This code first makes sure that we're working with a date variable and not a string - if timestamp is already a date variable you can skip the first line and continue with timestamp instead of ts.
compute ts=number(timestamp, DATE9).
formats ts (DATE9).
The aggregate command will add the first timestamp to all the rows of the ID.
Then we can calculate the difference between the timestamp in each row and the first one for that ID.
aggregate outfile=* mode=addvariables /break=id /startdate=min(ts).
compute MonthsFromStart=DATEDIF(ts, startdate, "months").
If instead of 0 in the first row of that ID you prefer a missing value, use this instead of the second line:
sort cases by id ts.
if id=lag(id) MonthsFromStart=DATEDIF(ts, startdate, "months").
I have a table like below:
From Date
Issue Id
Issue Id (group)
Status
Till Date
19-07-2021 17:21
4
4
Approved
19-07-2021 17:23
19-07-2021 17:23
4
4
In Progress
19-07-2021 17:23
19-07-2021 17:23
4
4
In Review
19-07-2021 17:25
19-07-2021 17:25
4
4
In Progress
19-07-2021 18:56
19-07-2021 18:56
4
4
In Review
20-07-2021 08:47
20-07-2021 08:47
4
4
Resolved
20-07-2021 14:45
20-07-2021 14:45
4
4
Closed
12-07-2021 10:49
4
4
Open
19-07-2021 17:21
27-04-2016 09:07
3
3
Open
10-01-2017 08:40
10-01-2017 08:40
3
3
Closed
10-01-2017 08:40
3
3
Resolved
10-01-2017 08:40
I need to do the following things:
For Issue Id 4 find the total time in hours or minutes or seconds or days for a particular type of status. For e.g There are 2 In Review rows. So the total time between From Date to Till date will be 17:23 (19-07) till 8:47(20-07).
calculate total time a issue is in between closed and In Review (here Till date for closed issues is unfortunately null).
Basically I am trying to create a dashboard where for each issue i'd i would like to see for how long was a issue "In Review" or "In Progress" before it was closed. So the dashboard will have "Issue Id" in the X axis and "Total Time for Review" or "Total Time for Progress" in the Y axis. For e.g Issue 4 was in a total of 1:31:01 Hours in the "In Progress" state (17:23 to 17:23 on 19th July and 17:25 to 18:56 on 19th July).
I am trying this:
IF [STATUS] = 'In progress' and [STATUS] = 'Closed'
THEN
DATEDIFF('day',[Date Create],[Till Date])
END but it says tables can only be aggregated and using Count function only.
Can someone please help? How can we create a calculated field for the above scenarios.
Think of your IF statements being applied to each row, you cannot have a status that is both in progress and closed.
I would arrange the text table like this:
Columns: Status
Rows: Issue ID (group) | Issue ID
Text Mark: Calculated Field (Named something like Total Time).
That will group all of the statuses together. You can change the aliases of the status if you want to say "Total Time for ..."
Then your calculated field would be:
DATEDIFF("day", [From Date], [Till Date])
And make sure you drag the pill over it is summing it. That will collapse everything at the status level, and then total the days.
I would like to try and sort this data by descending number of events and from latest date, grouped by ID
I have tried proc sql;
proc sql;
create table new as
select *
from old
group by ID
order by events desc, date desc;
quit;
The result I currently get is
ID Date Events
1 09/10/2015 3
1 27/06/2014 3
1 03/01/2014 3
2 09/11/2015 2
3 01/01/2015 2
2 16/10/2014 2
3 08/12/2013 2
4 08/10/2015 1
5 09/11/2014 1
6 02/02/2013 1
Although the dates and events are sorted descending. Those IDs with multiple events are no longer grouped.
Would it be possible to achieve the below in fewer steps?
ID Date Events
1 09/10/2015 3
1 27/06/2014 3
1 03/01/2014 3
3 01/01/2015 2
3 08/12/2013 2
2 09/11/2015 2
2 16/10/2014 2
4 08/10/2015 1
5 09/11/2014 1
6 02/02/2013 1
Thanks
It looks to me like you're trying to sort by descending event, then by either the earliest or latest date (I can't tell which one from your explanation), also descending, and then by id. In your proc sql query, you could try calculating the min or max of the Date variable, grouped by event and id, and then sort the result by descending event, the descending min/max of the date, and id.
I want to transform a Hive table by aggregating based on averages. However, I don't want the average value of an entire column, I want the average of the records in that column that have the same type in another column.
Here's an example, easier than trying to explain:
TABLE I HAVE:
Timestamp CounterName CounterValue MaxCounterValue MinCounterValue
00:00 Counter1 3 3 100:00 Counter2 4 5 2
00:00 Counter3 1 4 1
00:00 Counter4 6 6 100:05 Counter1 3 5 200:05 Counter2 2 2 200:05 Counter3 4 5 400:05 Counter4 6 6 5.......
TABLE I WANT:
CounterName AvgCounterValue MaxCounterValue MinCounterValue
Counter1 3 5 1Counter2 3 5 2Counter3 2.5 5 1Counter4 6 6 1
So I have a list of a bunch of counters, which each have multiple records (one per 5 minute time period). Every time each counter is logged, it has a value, a max value during that 5 minutes, and a min value. I want to aggregate this huge table so that it just has one record for each counter, which records the overall average value for that counter from all the records in the table,and then the overall min/max value of the counter in the table.
The reason this is difficult is because all the documentation says is how to aggregate by the average of a column in one table - I don't know how to split it up in groups.
Here's the script I've started with:
FROM HighCounters INSERT OVERWRITE TABLE MdsHighCounters
SELECT
HighCounters.CounterName AS CounterName,
HighCounters.CounterValue AS CounterValue
HighCounters.MaxCounterValue AS MaxCounterValue,
HighCounters.MinCounterValue AS MinCounterValue
GROUP BY HighCounters.CounterName;
And I don't know where to go from there... any ideas? Thanks!!
I think I solved my own problem:
FROM HighCounters INSERT OVERWRITE TABLE MdsHighCounters
SELECT
HighCounters.CounterName AS CounterName,
AVG(HighCounters.CounterValue) AS CounterValue,
MAX(HighCounters.MaxCounterValue) AS MaxCounterValue,
MIN(HighCounters.MinCounterValue) AS MinCounterValue
GROUP BY HighCounters.CounterName;
Does this look right to you?
I have an MS Access Database table that records communication status of values from several meters. The data is logged directly to the table, but I need to make sure that the table is populating. From the sample data you can see that the Comm columns doesn't read false or 0, so I want to return a log whenever the difference between now and "Date / Time" is greater than 5 minutes.
Date / Time FCB Comm BOF Comm EAF Comm FGP Comm
9/6/2011 10:29:10 1 1 1 1
9/6/2011 10:28:01 1 1 1 1
9/6/2011 10:27:11 1 1 1 1
9/6/2011 10:26:20 1 1 1 1
9/2/2011 08:17:01 1 1 1 1
9/2/2011 08:16:10 1 1 1 1
9/2/2011 08:15:02 1 1 1 1
9/2/2011 08:14:08 1 1 1 1
I wanted to know if anyone could tell me if this could like a reasonable query to run?
SELECT Data.[Date / Time], Data.[Ford Chiller Building Comm Okay],
Data.[Basic Oxygen Furnace Comm Okay], Data.[Electro-Arc Furnace Comm Okay],
Data.[J-9 Shop Comm Okay], Data.[Ford Glass Plant Comm Okay]
FROM Data
where DateDiff("n",now(), Data.[Date / Time] ) < 5;
You need something running continuously that generates a notification whenever expected data doesn't appear, and there's a couple of approaches you can take to do that.
One is to continuously run a query like the one you have above, checking the most recent date in the table against the value of the now() function.
Another approach is to take the latest date in your table, wait (sleep) for 5 minutes, and then check the table again for any newer entries. My expectation is that this approach will generate fewer hits on your table.
You could also just check the most recent date every 5 minutes regardless of the previous time checked and see if data hasn't come in.
You need to set up your notification loop first, then you can experiment with different approaches.
all you should really need to do is return the number of rows in the table whose timestamp is within 5 minutes of now(). You shouldn't need additional row detail, just is the count 0 or not?