Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Ciara
Creator
Creator

Finding same surgeon for morning and afternoon OR sessions

I’m trying to count late starts per OR per day in the morning and afternoon sessions.  I’ve been able to highlight if the operation took place in the morning session or the afternoon session by looking at the ‘start time’ of the operation (if it is <13:00 then its morning otherwise its afternoon). However this isn’t always accurate.  (explained below). I’ve also ascertained if it was the first case of the morning or afternoon session by getting the earliest start time of each session.

Where I am having difficulty is:

  1. Excluding late afternoon sessions if the surgeon is the same for the whole day (figure 1) – this is the most important
  2. I need to recalculate the ‘First Case’ of the afternoon based on the surgeon change first and then based on the earliest time – this is secondary but would still love some input

Here is an example of my data. 

Figure 1: List for OR01 on 27/02/2015 with only 1 surgeon for the whole day.  I want to exclude the first case late start flag.  I’ve been trying to pull the surgeon from the first case of the day and the last case of the day and if they are equal then exclude

Ciara_0-1587554782656.jpeg

Below for 09/02/2015 in OR02 there were 2 surgeons for the day. 

  • Morning session – first case on time
  • Afternoon session – first case on time however it was the same surgeon for the morning session
  • The actual first session of the afternoon should have been the first case for surgeon SN61 and not surgeon NN36 last case

Ciara_1-1587554782667.jpeg

Any help is appreciated.

Thanks

Ciara

1 Solution

Accepted Solutions
ArnadoSandoval
Specialist II
Specialist II

Hi @Ciara 

Thank you for the RawData, it is a lot easier to work with real data instead of air-code 🙂;  I focus this reply on the 27/02/2015 records, then we could focus on the 09/02/2015 because my questions as data integrity between your report and the application's report is still pending 😯; before writing my reply, below is the list of Qlik features and Qlik Community questions that help writing the script (in no particular order):

I implemented several levels of preceding loads in the script, basically to comply with the Separation of Concerns  design principle, you may implement one or two levels of SoC in your script, if you chose to use what is written in this reply; here is the script:

 

 

NoConcatenate
Temp_1:
LOAD
    ScheduleOperationDate,
    OperationRoomID,
    SurgeonUniqueID,
    TimeFlag,
    FirstCase_Flag,
    "TimeStamp(StartDateTime)",
    "TimeStamp(EndDateTime)",
    MorningLateStartFlag,
    AfternoonLateStartFlag,
     ScheduleOperationDate & '|' & OperationRoomID As OM_Date
FROM [lib://Surgeons/RawData.xlsx]
(ooxml, embedded labels, table is RawData);
   
Map_OM_Date_Surgeons:
Mapping Load
   OM_Date,
   Count(DISTINCT SurgeonUniqueID) As Surgeons
Resident Temp_1
Group By OM_Date;

// transformations
NoConcatenate 
// - applying rule on AfternoonLateStartFlag on the SurgeonId + TimeFlag group
Temp_2:
Load *,
     If(Surgeons > 1, AfternoonLateStartFlag, if(Surgeons = 1 and AfternoonLateStartFlag = 'Late' and TimeFlag_RT = 1, 'Exclude Late', AfternoonLateStartFlag)) As T2_AfternoonLateStartFlag
;
// - adding group running total on SurgeonId + TimeFlag
Load *, 
     If(RecordNo = 1, 1, if(TimeFlag = Peek('TimeFlag') and SurgeonUniqueID = Peek('SurgeonUniqueID'), Peek('TimeFlag_RT') + 1, 1 )) As TimeFlag_RT
;
// - ecluding ALL the late in the AfternoonLateStartFlag
Load *,
     If(Surgeons > 1, AfternoonLateStartFlag, If(Surgeons = 1 and AfternoonLateStartFlag = 'Late', 'Exclude Late', AfternoonLateStartFlag)) As T_AfternoonLateStartFlag,
     RecNo() as RecordNo;
Load *,
     ApplyMap('Map_OM_Date_Surgeons', OM_Date, -1) As Surgeons
Resident Temp_1
Order By "TimeStamp(StartDateTime)";

// cleansing
Drop Table Temp_1;
Rename Table Temp_2 to RawData;

 

 

Comments:

The Map table on OR_Date was created immediately after loading the RawData into the Temp_1 table; We need the DISTINCT modifier of the COUNT function.

 You read preceding loads bottom to top

The first thing done when processing the RawData in the Temp_1 table was perform the ApplyMap with the Count of Surgeons, the column was named Surgeons.

The first preceding load count the records saving the result into the column RecordNo; then it applies the rule on the 'Late' AfternoonLateStartFlag without mercy, It creates a new column for the result, named  T_AfternoonLateStartFlag; you may not do that in your solution, but it is a good practice for future debugging.

The merciless transformation to create the T_AfternoonLateStartFlag, does not return the result you specified in your question; We added a new group running count, this one reset to 1 when you get a new SurgeonId + TimeFlag group. This will help us to transform the first time the surgeon was late on the first afternoon TimeFlag, if any; this is very generic in my opinion, what about the surgeon started at 06:00 PM on the afternoon; anyhow, this group running count was named TimeFlag_RT

The next preceding load applies the rule to reset the first 'Late' on the AfternoonLateStartFlag when required, the column was named T2_AfternoonLateStartFlag; once again a new column was introduced for the same reason given above.

We finish the load script with its cleaning, dropping the table Temp_1 and renaming Temp_2 to RawData.

These are the solution's screenshots:

Day-OR-Surgeons.jpg

The above screenshot show the number of surgeons per Day-OR, the Count(Distinct worked.

Merciless-Late-Afternoon-Flag.jpg

The merciless transformation done on the AfternoonLateStartFlag was not good enough!

Group-Running-Count.jpg

This screenshot shows the running counts, both of them, and the highlighted data confirm the group running count reset exactly where it shoud.

Late-Afternoon-Flags.jpg

Finally, this screenshot compares the AfternoonLateStartFlag transformations side by side.

Best regards,

Arnaldo Sandoval

Arnaldo Sandoval
A journey of a thousand miles begins with a single step.

View solution in original post

17 Replies
ArnadoSandoval
Specialist II
Specialist II

Hi Ciara, 

I will suggest you to add a column to the table counting the number of Surgeons per Day per OR, something like this; I named the column: SurgeonCount ; it will be good if you  can add this column while loading your application-dashboard data, this column will simplify your logic described here:

 I’ve been trying to pull the surgeon from the first case of the day and the last case of the day and if they are equal then exclude

Because when the SurgeonCount is equal to 1, you can exclude the data with a cleaner and probably efficient way.

Day-OR-SurgeonCount-01.jpg

Day-OR-SurgeonCount-02.jpg

Now, regarding your second scenario, with two surgeons sharing the OR on the same day (09.Feb.2015), you wrote this:

  • Afternoon session – first case on time however it was the same surgeon for the morning session
  • The actual first session of the afternoon should have been the first case for surgeon SN61 and not surgeon NN36 last case

 

This rule confused me, I have difficulties understanding why the surgeon performing the first surgery of the afternoon suddenly hands it over to the second surgeon. My confusion is because this rule make no sense at all, your report will produce misleading results, other reports in the organization will not reconcile with your report; Would you please elaborate justifying the rule you wrote?

Hope this helps,

Arnaldo Sandoval

Arnaldo Sandoval
A journey of a thousand miles begins with a single step.
Ciara
Creator
Creator
Author

Hi Arnaldo

That would actually make much more sense, thank you for your reply.

I've been trying to figure out the best way of counting the surgeons per OR per day in my script but not having any luck.

I have a unique identifier for each row which is the PatientCaseID but I just want to count the surgeons in the OR regardless of how many patients there were.  I can't use distinct in my script load.

Perhaps I'm over complicating it.  Tried to do a separate table and then a mapping load to the original and it filed without error but it didn't bring up correct numbers.  

SurgeonCount:
Load
OR_Date,
Count (ScheduleOperationDateTime&'|'&OperationRoomID&'|'&SurgeonName) as SurgCount
Resident OR_Stats
Group By OR_Date;

Map_SurgeonCount:
Mapping Load
OR_Date,
SurgCount
Resident SurgeonCount;

Sorry that I'm not getting this 🙈

ArnadoSandoval
Specialist II
Specialist II

Hi Ciara,

You are in the right track, actually I thought yesterday that using a mapping table is the way to go, that will make easier this reply; I am not sure if OR_DATE is the same column appearing on your screenshot, e.g. ScheduleOperationDate, actually you also have ScheduleOperationDateTime in your code !!! I am assuming all these fields identify the same calendar date

I will count the Surgeons per OR per day with this script.

 

Map_SurgeonCount:
Mapping Load
OR_Date & '|' & OperationRoomID As DayRoom,
Count(*) As SurgCount
Resident OR_Stats
Group By OR_Date & OperationRoomID;

 

I will prefer to create the Map_SurgeonCount table in one go; if you can safely create the Map_SurgeonCount earlier in the script, it will be easier (less overload) to apply it to your OR_Stats table; the script code below applies the map following the load script know to me !!!

 

Temp_OR_Stats:
Load *,
     ApplyMap('Map_SurgeonCount', OR_Date & '|' & OperationRoomID, 'ERROR') As SurgeonCount
Resident OR_Stats;

Drop Table OR_Stats;
Rename Table Temp_OR_Stats, OR_Stats; 

 

It creates Temp_OR_Stats while applying the map, once it is done, It drops the OR_Stats table, followed by renaming Temp_OR_Start back to OR_Stats

The ApplyMap's default value is 'ERROR', you could use a negative 1  (-1) as well, the idea behind is to add a sanity check after the Rename Table statement, so you know your Surgeon Count was applied without errors, otherwise, you have some debugging to do.

You wrote,

I have a unique identifier for each row which is the PatientCaseID but I just want to count the surgeons in the OR regardless of how many patients there were.  I can't use distinct in my script load.

Indeed you were over complicating, you need to count Surgeons per Day-Operating_Rooms, no need to go into the Patient Case ID.

This should help with the first of your questions, we could move to the next question once you are happy with this approach.

Best regards,

Arnaldo Sandoval

Arnaldo Sandoval
A journey of a thousand miles begins with a single step.
Ciara
Creator
Creator
Author

Hi Arnaldo

Thank you again for your reply.  OR_Date was the concatenation of the ScheduledOperationDate and OperatingRoomID but I can separate these out.

There seems to be a syntax error in the 'Count(*)' line.  The script wont load with this line the way it is.  I'll search for solutions but if you had thoughts I'd be glad to hear them.

Thanks

Ciara

ArnadoSandoval
Specialist II
Specialist II

Hi Ciara,

Yes, Qlik get unwell by the asterisk 🙂; replace it with 

Count(SurgeonUniqueID)

Your OR_Date sounds good then, as long as it does not contain the Time side, the Count() should be based on a date without time, just DD/MM/YYYY or any date format, it does not matter! then the ApplyMap() should be also use OR_Date

Hope this helps,

Arnaldo Sandoval

 

Arnaldo Sandoval
A journey of a thousand miles begins with a single step.
Ciara
Creator
Creator
Author

Hi Arnaldo

Unfortunately this is giving me the same figures as the way I did it before.  It's like its counting every instance of the surgeon for the OR_Date instead of just the distinct values.

Since we cant use distinct in the load script is there any other alternative that you know of?

Appreciate all the help 😊

Thanks

Ciara

ArnadoSandoval
Specialist II
Specialist II

Hi Ciara,

I will try to replicate your environment here, but it will help me a lot if you could share with me a text file with the records appearing in your screenshots,  for the 27/02/2015 and 09/02/2015, I hope you can write them to a text file, so I could use your data checking out the code; otherwise, I will have to create the file manually.

Thanks in advance,

Arnaldo Sandoval

Arnaldo Sandoval
A journey of a thousand miles begins with a single step.
Ciara
Creator
Creator
Author

Oh of course.  

Thanks Arnaldo

ArnadoSandoval
Specialist II
Specialist II

Hi Ciara,

My apologies for no replying earlier, I got busy replying to other question and it is midnight in this side of the world (Sydney), so I will look at you problem tomorrow morning!

Best regards,

Arnaldo Sandoval.

Arnaldo Sandoval
A journey of a thousand miles begins with a single step.