NUBIC/ncs_navigator_core — pull request #1 by yipdw (2012-07-13 18:06:19+00:00)
Title: New PSC scheduled activity report -> Cases entity mapping code

This pull request contains a redesign of the PSC scheduled activity report -> Cases entity mapping code. The redesign maps rows in the scheduled activity report to Cases entities, building instruments, contacts, and contact links where appropriate, and saves generated entities.

I'd appreciate comments on whether or not the mapping is correct, as well as the usual comments re: code style, organization, etc.

The mapping is done in `#resolve_models`. `#process` is a preprocessing step that merges rows into model placeholders. (I suppose the former can be done from the latter.)

JSON generation for consumption by the field client is a separate task, but should fall out pretty easily from this code. To associate events with contacts, for example, one could do this:

```ruby

report.contacts.each do |c|
events_for_contact = report.events.select { |e| e.contact == c }

doc = {}

doc['contact_id'] = c.model.public_id
...
doc['events'] = events_for_contact.map do |e|
{ ... }
end
end
```

A similar idea applies to event -> instrument association.

This technically has quadratic behavior wrt the number of iterations through `report.events`, but in practice I haven't noticed it being the bottleneck -- database activity tends to be the problem. If it becomes a problem, we can preprocess the event lists for faster access.