Esempio n. 1
0
def copy_fields_to_builder(state_person_builder: entities.StatePerson.Builder,
                           proto: StatePerson,
                           metadata: IngestMetadata):
    """Mutates the provided |state_person_builder| by converting an
    ingest_info proto StatePerson.

    Note: This will not copy children into the Builder!
    """
    enum_fields = {
        'gender': Gender,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    new = state_person_builder

    # Enum mappings
    new.gender = enum_mappings.get(Gender)
    new.gender_raw_text = fn(normalize, 'gender', proto)

    # 1-to-1 mappings
    new.full_name = parse_name(proto)
    new.birthdate, new.birthdate_inferred_from_age = parse_birthdate(
        proto, 'birthdate', 'age')
    new.current_address = fn(normalize, 'current_address', proto)
    new.residency_status = fn(
        parse_residency_status, 'current_address', proto)
    new.state_code = parse_region_code_with_override(
        proto, 'state_code', metadata)
Esempio n. 2
0
def convert(proto: StateAlias, metadata: IngestMetadata) \
        -> entities.StatePersonAlias:
    """Converts an ingest_info proto StateAlias to a persistence entity."""
    new = entities.StatePersonAlias.builder()

    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)
    new.full_name = parse_name(proto)

    return new.build()
Esempio n. 3
0
def convert(proto: StateAlias, metadata: IngestMetadata) \
        -> entities.StatePersonAlias:
    """Converts an ingest_info proto StateAlias to a persistence entity."""
    new = entities.StatePersonAlias.builder()

    enum_fields = {
        'alias_type': StatePersonAliasType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.alias_type = enum_mappings.get(StatePersonAliasType)
    new.alias_type_raw_text = fn(normalize, 'alias_type', proto)

    # 1-to-1 mappings
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)
    new.full_name = parse_name(proto)

    return new.build()
Esempio n. 4
0
def convert(proto: StateAgent, metadata: IngestMetadata) -> entities.StateAgent:
    """Converts an ingest_info proto StateAgent to a persistence entity."""
    new = entities.StateAgent.builder()

    enum_fields = {
        "agent_type": StateAgentType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.agent_type = enum_mappings.get(
        StateAgentType, default=StateAgentType.PRESENT_WITHOUT_INFO
    )
    new.agent_type_raw_text = fn(normalize, "agent_type", proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, "state_agent_id", proto)
    new.state_code = parse_region_code_with_override(proto, "state_code", metadata)
    new.full_name = parse_name(proto)

    return new.build()
Esempio n. 5
0
def copy_fields_to_builder(person_builder, proto, metadata):
    """Mutates the provided |person_builder| by converting an ingest_info proto
    Person.

    Note: This will not copy children into the Builder!
    """
    enum_fields = {
        "gender": Gender,
        "race": Race,
        "ethnicity": Ethnicity,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    new = person_builder

    # Enum mappings
    new.race = enum_mappings.get(Race)
    new.race_raw_text = fn(normalize, "race", proto)
    new.ethnicity = enum_mappings.get(Ethnicity)
    new.ethnicity_raw_text = fn(normalize, "ethnicity", proto)
    new.gender = enum_mappings.get(Gender)
    new.gender_raw_text = fn(normalize, "gender", proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, "person_id", proto)
    new.full_name = parse_name(proto)
    new.birthdate, new.birthdate_inferred_from_age = parse_birthdate(
        proto, "birthdate", "age")
    new.residency_status = fn(parse_residency_status, "place_of_residence",
                              proto)
    new.resident_of_region = fn(_parse_is_resident, "place_of_residence",
                                proto, metadata.region)

    new.jurisdiction_id = fn(normalize,
                             "jurisdiction_id",
                             proto,
                             default=metadata.jurisdiction_id)

    new.region = metadata.region
Esempio n. 6
0
def copy_fields_to_builder(
    state_person_builder: entities.StatePerson.Builder,
    proto: StatePerson,
    metadata: IngestMetadata,
) -> None:
    """Mutates the provided |state_person_builder| by converting an
    ingest_info proto StatePerson.

    Note: This will not copy children into the Builder!
    """
    new = state_person_builder

    # Enum mappings
    new.gender = EnumParser(getattr(proto, "gender"), Gender,
                            metadata.enum_overrides)
    new.gender_raw_text = getattr(proto, "gender")

    # 1-to-1 mappings
    new.full_name = parse_name(proto)
    new.birthdate = getattr(proto, "birthdate")
    new.birthdate_inferred_from_age = "False" if new.birthdate else None
    new.current_address = getattr(proto, "current_address")
    new.residency_status = getattr(proto, "current_address")
    new.state_code = metadata.region