예제 #1
0
    def test_is_booking_active(self):
        inactive_booking = county_entities.Booking.new_with_defaults(
            booking_id='1', custody_status=CustodyStatus.RELEASED)
        active_booking = county_entities.Booking.new_with_defaults(
            booking_id='2')

        self.assertFalse(is_booking_active(inactive_booking))
        self.assertTrue((is_booking_active(active_booking)))
예제 #2
0
def is_booking_match(*, db_entity: entities.Booking,
                     ingested_entity: entities.Booking) -> bool:
    """
    Given a database booking and an ingested booking, determine if they should
    be considered the same booking. Should only be used to compare bookings for
    the same person.
    Args:
        db_entity: (entities.Booking)
        ingested_entity: (entities.Booking)
    Returns: (bool)
    """
    if db_entity.external_id or ingested_entity.external_id:
        return db_entity.external_id == ingested_entity.external_id

    # If the db booking's admission date was scraped (not inferred), the
    # ingested booking must have the same admission date to be a match.
    if not db_entity.admission_date_inferred:
        return db_entity.admission_date == ingested_entity.admission_date
    return is_booking_active(db_entity) and is_booking_active(ingested_entity)
예제 #3
0
def _infer_release_date_for_bookings(bookings: List[county_entities.Booking],
                                     last_ingest_time: datetime.datetime,
                                     custody_status: CustodyStatus):
    """Marks the provided bookings with an inferred release date equal to the
    provided date. Updates the custody_status to the provided custody
    status. Also updates all children of the updated booking to have status
    'REMOVED_WITHOUT_INFO"""

    for booking in bookings:
        if persistence_utils.is_booking_active(booking):
            logging.info("Marking booking [%s] as inferred release",
                         booking.booking_id)
            booking.release_date = last_ingest_time.date()
            booking.release_date_inferred = True
            booking.custody_status = custody_status
            booking.custody_status_raw_text = None
            _mark_children_removed_from_source(booking)
예제 #4
0
def _db_open_booking_matches_ingested_booking(
        *, db_entity: entities.Person,
        ingested_entity: entities.Person) -> bool:
    """Returns True if the external id on the open booking in the database
    matches any of the external ids of the bookings on the ingested person.
    If there is no open booking in the db, return True as well.

    Note: if the same person has been rebooked on subsequent scrapes, and the
    ingested person doesn't have historical bookings, we will not match the
    person entities. This is the same behavior as if the person is rebooked on
    non-consecutive days.
    """
    db_open_bookings = [b for b in db_entity.bookings if is_booking_active(b)]
    if not db_open_bookings:
        return True
    return any(db_open_booking.external_id == ingested_booking.external_id
               for ingested_booking in ingested_entity.bookings
               for db_open_booking in db_open_bookings)