I have come up with a solution that works well for me. This might not be the perfect I was initially looking for, but it works for me for these reasons:
- When I'm done with this work other programmers will periodically work on the reports and I want to make their life as easy as possible in this regard.
- A report-generator will be nice, but not the most productive thing to do at the moment.
I believe my solution is fairly easy to read and maintain without sacrificing too much performance:
GatherData
set command="do LoopThroughRegions(status,date,state,.dataCollection)"
if ($length(street)>0){
set command="do LoopThroughData(status,date,state,region,street,.dataCollection)"
} elseif ($length(region)>0){
set command="do LoopThroughStreets(status,date,state,region,.dataCollection)"
}
set date=fromDate-1,status=""
for{
set status=$order(^GLOBAL(status)) quit:status=""
for{
set date=$order(^GLOBAL(status,date)) quit:((date>toDate)||(date=""))
xecute (command)
}
}
quit
LoopThroughRegions(status,date,state,dataCollection)
set currentRegion=""
for{
set currentRegion=$order(^GLOBAL(status,date,region,currentRegion)) quit:currentRegion=""
do LoopThroughStreets(status,date,state,currentRegion,.dataCollection)
}
quit
LoopThroughStreets(status,date,state,region,dataCollection)
set currentStreet=""
for{
set currentStreet=$order(^GLOBAL(status,date,state,region,currentStreet)) quit:currentStreet=""
do LoopThroughData(status,date,state,region,currentStreet,.dataCollection)
}
quit
LoopThroughData(status,date,state,region,street,dataCollection)
set dataItem=""
for{
set dataItem=$order(^GLOBAL(status,date,state,region,street,dataItem)) quit:dataItem=""
// Do stuff
}
quit
Unless a better solution is provided I will select my own answer for future reference. Hopefully it might even help someone else as well.