cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating Length of Stay in a specefic time of the day

Dear Community,

 

I am working on an emergecny department model and I have a code (entrance control) that calculate the Average Length of stay for all patients (Average simulation time for each entity). I need to expand the code in a way to be able to calculate the simulation time only in a specific time of the day (e.g. between 3a and 11a only). Not the whole day time.

 

I have copied the entrance control for the code. I wonder if any one can help me with.

 

is
do
local myPatient : string := to_str(@) ;
local index : integer := tab.indexydim + 1 ;

tab["Patient",index] := myPatient ;
tab["Entrance_Time",index] := EventController.Simtime ;


end;

10 REPLIES

Re: Calculating Length of Stay in a specefic time of the day

Phenom
Phenom

with timeOfDay(DateTime) you can extract the time of a dateTime value; this you could use to restrict the average to a period; but you need to be more exact in definition of the period. If you want to calculate the average dwell time of patients, that  enter the model between start and end, you will need a entrance control like this (with start and end as global variables of type time):

is
do
    local myPatient : string := to_str(@) ;
    local index : integer := tab.indexydim + 1 ;
    if timeOfDay(eventController.absSimTime) >= start and 
       timeOfDay(eventController.absSimTime) < end then
       tab["Patient",index] := myPatient ;
       tab["Entrance_Time",index] := EventController.Simtime ;
   end;

end;

 

 

In the entrance control of the drain, you need than to search the patient and calculate the exit and dwell time as base for the average dwell time.


Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net


Re: Calculating Length of Stay in a specefic time of the day

Hi Steffen

 

Let's say for ex. I want to calculate the length of stay for patients only on Monday between 3a - 7a (entrance time). Can you help me with this?

 

Also here I copied the entrance control for the drain.

 

 

is
do
local myPatient : string := to_str(@) ;

tab["Exit_Time",myPatient ] := EventController.Simtime ;

tab["DT",myPatient ] := tab["Exit_Time",myPatient ] - tab["Entrance_Time",myPatient ] ;


end;

Re: Calculating Length of Stay in a specefic time of the day

Valued Contributor
Valued Contributor

Hello Mohamed,

 

Steffen already gave you the method for your goal. You need to modify your entrance control with like he said. You have to add

if timeOfDay(eventController.absSimTime) >= 03:00:00 and 
       timeOfDay(eventController.absSimTime) < 07:00:00 then
....
end;

 to check if it's between 3am and 7am.

 

Regards

 

Fated

Re: Calculating Length of Stay in a specefic time of the day

Phenom
Phenom

for the entrance control insert two global variables to the frame:

 

start; data type time; value: 3:00:00

end; data type time; value: 7:00:00

 

then the exit control of the source should work

 

In the entrance control of the source, you need first to search the patient, than you can update the table!

is
  found:boolean;
do
   local myPatient : string := to_str(@) ;
   tab.setCursor(1,1); --if the patient is in the first column
   found:=tab.find({1,1}..{1,*},myPatient);
   if found then

       tab["Exit_Time",tab.cursorY] := EventController.Simtime ;

       tab["DT",tab.cursorY] := tab["Exit_Time",tab.cursorY] - 
                                            tab["Entrance_Time",tab.cursorY];
    else
        --not in the table, in this case okay
    end;  


end;

If you use the rowindex for the patient, you need to check the row index (getRowNo /= -1), otherwise you get an error for patients outside of the recorded time.

 


Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net


Re: Calculating Length of Stay in a specefic time of the day

Hi Steffen,

 

Sorry again but the code is not working well. It is showing error from the first entity. I have attached my model and named the code with your name so you can identify. If you are not able to edit the model, I can send you a simpler version using Plant Simulation 12.

 

Thanks and Sorry again

Mohamed

Re: Calculating Length of Stay in a specefic time of the day

Phenom
Phenom

have a look into the example


Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net


Re: Calculating Length of Stay in a specefic time of the day

Valued Contributor
Valued Contributor

Can you post your Model in Plant Simulation 12?

Re: Calculating Length of Stay in a specefic time of the day

Phenom
Phenom

here in V12


Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net


Re: Calculating Length of Stay in a specefic time of the day

Valued Contributor
Valued Contributor

Thanks Steffen for the model. Originally i wanted the model from the topic creator to take a look at it. Maybe he has solved his problem.

 

Regards

Florian