Пример #1
0
    def run_match(self, session: Session, region_code: str,
                  ingested_people: List[entities.Person]) -> MatchedEntities:
        """
        Attempts to match all people from |ingested_people| with corresponding
        people in our database for the given |region_code|. Returns an
        MatchedEntities object that contains the results of matching.
        """
        with_external_ids = []
        without_external_ids = []
        for ingested_person in ingested_people:
            if bool(ingested_person.external_id):
                with_external_ids.append(ingested_person)
            else:
                without_external_ids.append(ingested_person)

        db_people_with_external_ids = dao.read_people_by_external_ids(
            session, region_code, with_external_ids)
        matches_with_external_id = match_people_and_return_error_count(
            db_people=db_people_with_external_ids,
            ingested_people=with_external_ids)

        db_people_without_external_ids = dao.read_people_with_open_bookings(
            session, region_code, without_external_ids)
        matches_without_external_ids = match_people_and_return_error_count(
            db_people=db_people_without_external_ids,
            ingested_people=without_external_ids,
        )

        return matches_with_external_id + matches_without_external_ids
Пример #2
0
    def test_readPeopleByExternalId(self):
        admission_date = datetime.datetime(2018, 6, 20)
        release_date = datetime.date(2018, 7, 20)
        closed_booking = Booking(
            custody_status=CustodyStatus.IN_CUSTODY.value,
            admission_date=admission_date,
            release_date=release_date,
            first_seen_time=admission_date,
            last_seen_time=admission_date)

        person_no_match = Person(person_id=1, region=_REGION,
                                 jurisdiction_id=_JURISDICTION_ID,
                                 bookings=[deepcopy(closed_booking)])
        person_match_external_id = Person(person_id=2, region=_REGION,
                                          jurisdiction_id=_JURISDICTION_ID,
                                          bookings=[closed_booking],
                                          external_id=_EXTERNAL_ID)

        session = SessionFactory.for_schema_base(JailsBase)
        session.add(person_no_match)
        session.add(person_match_external_id)
        session.commit()

        ingested_person = entities.Person.new_with_defaults(
            external_id=_EXTERNAL_ID)
        people = dao.read_people_by_external_ids(session, _REGION,
                                                 [ingested_person])

        expected_people = [
            converter.convert_schema_object_to_entity(person_match_external_id)]
        self.assertCountEqual(people, expected_people)