Skip to content

Instantly share code, notes, and snippets.

@dianekaplan
Created September 25, 2016 12:32
Show Gist options
  • Save dianekaplan/7f755811f3880e40e170bb4438ace116 to your computer and use it in GitHub Desktop.
Save dianekaplan/7f755811f3880e40e170bb4438ace116 to your computer and use it in GitHub Desktop.
function [out1] = simple_waiting(input)
% The input will be a directory name
% out1 is an array of parsed patient info
% (didn't have to make proper parser- just got the answers in this file)
clear
clc
close all
data_matrix = [1,735724.291666667,735724.322916667,735724.343750000,5;2,735724.331250000,735724.340277778,735724.371527778,18];
%edited to have both wait:
%data_matrix =
%[1,735724.291666667,735724.322916667,735724.343750000,5;2,735724.322916667,735724.340277778,735724.371527778,18];
% get the problem again even just by repeating that last row:
%data_matrix = [1,735724.291666667,735724.322916667,735724.343750000,5;2,735724.331250000,735724.340277778,735724.371527778,18;2,735724.331250000,735724.340277778,735724.371527778,18]
patient_queue = [];
highest_wait_num = 0;
[rows, columns] = size(data_matrix);
for i = 1:rows
this_row_arrival = datetime (data_matrix(i, 2), 'ConvertFrom', 'datenum');
this_row_exam_start = datetime (data_matrix(i, 3), 'ConvertFrom', 'datenum');
now = this_row_arrival; %making a copy called 'now' so it's clear below
%now = datetime(this_row_arrival, 'InputFormat', 'dd-MMM-yyyy HH:mm:ss')
% check patient queue: if anyone left in the meantime, remove them
for j = 1:length(patient_queue)
%if patient_queue{j} < this_row_arrival %Comparison is not defined between double and datetime arrays.
if patient_queue{j} < now
%if true
patient_queue(j) = [];
end
end
% if new patient isn't seen immediately (tb > ta), add tb to the queue
if this_row_exam_start > this_row_arrival
patient_queue{end+1} = this_row_exam_start;
end
% get the current queue size
patient_queue_non_zero = (~cellfun('isempty',patient_queue));
indices = find(patient_queue_non_zero);
current_queue_count = length(indices);
% if the current queue size beats the highest we've seen, update it
if current_queue_count > highest_wait_num
highest_wait_num = current_queue_count;
end
end
patient_queue{j}
highest_wait_num
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment