Wrote one of the most complicated algorithms in my career yesterday (all the while feeling like garbage which made it more of a miracle). I was going to try to reproduce the code here but it would probably make no sense out of context. But the problem went something like this:
Code:
1 Query all blood sample records for every patient encounter in the hospital
2 Only pull records from each patient's most recent encounter
3 If that encounter's set of records includes a record of type 1, with field A populated
- Print the most recent record of that type
- Don't print the other records in the set
4 If that set of records includes a record of type 1, without field A populated
- and that set of records has no records of type 1 with field A populated
- and that set of records contains a record of type 2
- Print the record of type 1 and 2
Took me a little longer than usual to wrap my head around it. The tricky part is that it needed nested loops, and on point 4 it needed two nested loops within a loop, which was also contingent on point 3 already being dealt with.
Originally I attempted to flag every single record with an is_this_printed_flag, but later switched to flagging types of encounter. First I identified encounters from point 3 as type 1, and then encounters from point 4 as type 2 (any others defaulted to 0). Then when I went to print, as the records were displayed in the correct order and sorted by person, I looked for specific encounter/record types and broke the loop when the correct rows were found.
Still not 100% sure I've got it right, but that is a problem with specification, which is a bit confusing too.
It may not look extremely hard, but most of the time I'm querying and manipulating data, or issuing Google searches. Usually I don't actually have to think this much.