How can I identify handoffs and transitions in a matrix

2 views (last 30 days)
Hello,
I have a matrix like the following. Rows represent nurses, and columns represent observations made at different points in time. Column 1 is time 1. Column 2 is time 2, etc.
I would like to identify handoffs, where one nurse comes in and replaces another. You can see one of these handoffs in dat[1:2, 1:2] below. The problem is that sometimes the handoff stretches across two time periods, as nurses discuss information important to the surgery. More often it happens in just one time period. How do identify when these handoffs occur, and the frequency of them?
dat
1 0 0 0 0
0 1 1 1 0
0 0 0 1 1
Thanks in advance for any assistance.
Russ

Answers (1)

Gitesh Nandre
Gitesh Nandre on 20 Aug 2014
Can you please explain the exact output format that you want to represent a hand-off in? It will be helpful if you can explain it for the same example which you have given above. Do you wish to know between which two nurses a hand-off occurred? Also, what do you exactly mean by a frequency of hand-offs?
Based on your explanation and the example, I am assuming that a hand-off occurs when a next nurse starts observing. I am also assuming that only two nurses are involved per hand-off. These assumptions translate to observing transitions from 0 to 1 for each matrix row. One quick way to check for the transition is to compute the difference between successive time steps (columns) for each row.
A possible solution is provided below based on the above assumption. In that solution, differences along the adjacent columns of 'dat' matrix are computed using the diff function as follows:
>> dat = [1 0 0 0 0; 0 1 1 1 0; 0 0 0 1 1];
>> col_diff = diff(dat,1,2);
Additional information about the 'diff' function can be found in documentation link: MATLAB 'diff' documentation page
The output of the ‘diff’ function is stored in the variable named ‘col_diff’. The next step is to identify the columns in each row of ‘col_diff’ where the value is 1. A value of 1 in a particular row implies that at a previous time step, the nurse was not performing any observations, but is currently observing. The ‘find’ function can be used to identify the columns which contain a value of 1 for each row in the following manner:
>> [row handoff_times] = find(col_diff==1);
Additional information about the 'find' function can be found in documentation link: MATLAB 'find' documentation page
In the above code, the variable named ‘handoff_times’ is the variable of interest and stores the column number corresponding to the handoff. Since the computations performed used the ‘diff’ function, the values of the column numbers in ‘handoff_times’ will be less than the actual value by 1. The values can be adjusted using the following code:
>> handoff_times = handoff_times + 1;
The entire code snippet is included below for your reference:
dat = [1 0 0 0 0; 0 1 1 1 0; 0 0 0 1 1];
col_diff = diff(dat,1,2);
[row handoff_times] = find(col_diff==1);
handoff_times = handoff_times + 1;
  2 Comments
Russ
Russ on 20 Aug 2014
Gitesh,
I think this is very close. A handoff entails one nurse and one leaving. This could occur over multiple time segments (columns). If a nurse enters and simply joins the previous nurse for the reaminder of the time, this is not a handoff. So, in dat =
1 0 0 0 0
0 1 1 1 0
0 0 0 1 1
there is handoff between row 1 and row 2 at column 2, because nurse 2 enters and nurse 1 leaves. There is another handoff between nurse 3 and nurse 1 at column 5 because nurse 3 entered at column 4 and nurse 2 exited at column 5.
The perfect solution would provide, the nurse that entered (indicated by row number), the nurse that left (indicated by row number), and when the leaving nurse exited (column number). I understand then that the number of handoffs would simply be the number of rows in the results.
Thank you so much for your help so far!
Russ
Gitesh Nandre
Gitesh Nandre on 25 Aug 2014
Thanks for clarifying more handoff scenarios. We can still make use of 'diff' logic to find the possible handoffs first. Then, we can eliminate the false handoffs by taking into account the fact that whether previous nurse has left or not.I am assuming that handoffs occur in only forward direction from first row to the last row.I am also assuming that a handoff occurs only between adjacent rows. As a result of these assumptions, we will have to consider that there will be no possible handoff for first row i.e. first nurse can't be 'coming' nurse in any handoff scenario.
Based on these assumptions, above answer can rewritten as follows:
dat = [1 0 0 0 0; 0 1 1 1 0; 0 0 0 1 1]; % input matrix
dat = [zeros(size(dat,1),1) dat]; % prefixing a column of zeros to input matrix
% to handle cases where nurses start observing
% directly from time 1
col_diff = diff(dat,1,2);
[handoff_row handoff_col] = find(col_diff==1);
output_index = 1;
for ii = 1:length(handoff_row) %iterating over possible handoff locations
jj = handoff_row(ii); % jj is row number for ith possible handoff
kk = handoff_col(ii); % kk is column number for ith possible handoff
if jj == 1 % nurse 1 can not be 'coming' nurse in any handoff scenario
continue;
end
for col = kk:size(col_diff,2) % iterating until last column of col_diff
if(col_diff(jj,col) == -1) % breaking when nurse 2 has left but
break; % nurse 1 has not left or nurse 1 is also leaving.
end
if(col_diff(jj-1,col) == -1) % If nurse 1 has left but nurse 2 has not
handoff(output_index).leaving_nurse = jj - 1; % This is real handoff and store
handoff(output_index).coming_nurse = jj; % it in a handoff structure array
handoff(output_index).time = col;
output_index = output_index + 1;
break;
end
end
end

Sign in to comment.

Categories

Find more on Simulation, Tuning, and Visualization in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!