Code4HR / open-health-inspection-scraper

Scraper for the open-health-inspector app.
Apache License 2.0
7 stars 9 forks source link

Make sure 'inspections' is an array #47

Closed ttavenner closed 8 years ago

ttavenner commented 8 years ago

Normally each vendor document contains an array of inspection objects. There is a small bug right now where occasionally instead of an array, this will be a single inspection object. I believe this happens when a vendor has only one inspection on file. Similarly, if a vendor has zero inspections on file the inspections array doesn't exist on the vendor record. These two items can cause problems downstream for the scoring functionality and the API.

The fix, I believe, is to make sure that an empty inspections array is added when the vendor record is first created. This might mean separating the vendor update from the vendor create steps in the pipeline rather than using an upsert method to avoid overwriting the existing inspections array.

ttavenner commented 8 years ago

Discovered that this bug was actually caused by the use of TakeFirst() in the vendor and inspection loaders. It was converting the inspection and violation arrays into single objects. THe solution is to apply TakeFirst() individually to each field where I want it to apply and not apply it to arrays.