def copy_fields_to_builder(supervision_violation_builder: entities.
                           StateSupervisionViolation.Builder,
                           proto: StateSupervisionViolation,
                           metadata: IngestMetadata) -> None:
    """Converts an ingest_info proto StateSupervisionViolation to a
    persistence entity."""
    new = supervision_violation_builder

    enum_fields = {
        'violation_type': StateSupervisionViolationType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.violation_type = enum_mappings.get(StateSupervisionViolationType)
    new.violation_type_raw_text = fn(normalize, 'violation_type', proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, 'state_supervision_violation_id',
                         proto)
    new.violation_date = fn(parse_date, 'violation_date', proto)
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)
    new.is_violent = fn(parse_bool, 'is_violent', proto)
    if proto.violated_conditions:
        new.violated_conditions = create_comma_separated_list(
            proto, 'violated_conditions')
Example #2
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)
Example #3
0
def copy_fields_to_builder(
        early_discharge_builder: entities.StateEarlyDischarge.Builder,
        proto: StateEarlyDischarge, metadata: IngestMetadata) -> None:
    """Converts an ingest_info proto StateEarlyDischarge to a early discharge entity."""
    new = early_discharge_builder

    enum_fields = {
        'decision': StateEarlyDischargeDecision,
        'deciding_body_type': StateActingBodyType,
        'requesting_body_type': StateActingBodyType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.decision = enum_mappings.get(StateEarlyDischargeDecision)
    new.decision_raw_text = fn(normalize, 'decision', proto)
    new.deciding_body_type = enum_mappings.get(StateActingBodyType,
                                               field_name='deciding_body_type')
    new.deciding_body_type_raw_text = fn(normalize, 'deciding_body_type',
                                         proto)
    new.requesting_body_type = enum_mappings.get(
        StateActingBodyType, field_name='requesting_body_type')
    new.requesting_body_type_raw_text = fn(normalize, 'requesting_body_type',
                                           proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, 'state_early_discharge_id', proto)
    new.request_date = fn(parse_date, 'request_date', proto)
    new.decision_date = fn(parse_date, 'decision_date', proto)
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)
    new.county_code = fn(normalize, 'county_code', proto)
Example #4
0
def copy_fields_to_builder(
        sentence_group_builder: entities.StateSentenceGroup.Builder,
        proto: StateSentenceGroup,
        metadata: IngestMetadata) -> None:
    """Mutates the provided |sentence_group_builder| by converting an
    ingest_info proto StateSentenceGroup.

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

    enum_fields = {
        'status': StateSentenceStatus,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # Enum mappings
    new.status = enum_mappings.get(
        StateSentenceStatus,
        default=StateSentenceStatus.PRESENT_WITHOUT_INFO)
    new.status_raw_text = fn(normalize, 'status', proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, 'state_sentence_group_id', proto)
    new.date_imposed = fn(parse_date, 'date_imposed', proto)
    new.state_code = parse_region_code_with_override(
        proto, 'state_code', metadata)
    new.county_code = fn(normalize, 'county_code', proto)
    new.min_length_days = fn(parse_days, 'min_length', proto)
    new.max_length_days = fn(parse_days, 'max_length', proto)
    new.is_life = fn(parse_bool, 'is_life', proto)
def copy_fields_to_builder(
        state_parole_decision_builder: entities.StateParoleDecision.Builder,
        proto: StateParoleDecision, metadata: IngestMetadata) -> None:
    """Mutates the provided |state_parole_decision_builder| by converting an
    ingest_info proto StateParoleDecision.

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

    enum_fields = {
        'decision_outcome': StateParoleDecisionOutcome,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # Enum mappings
    new.decision_outcome = enum_mappings.get(StateParoleDecisionOutcome)
    new.decision_outcome_raw_text = fn(normalize, 'decision_outcome', proto)

    new.external_id = fn(parse_external_id, 'state_parole_decision_id', proto)
    new.decision_date = fn(parse_date, 'decision_date', proto)
    new.corrective_action_deadline = fn(parse_date,
                                        'corrective_action_deadline', proto)
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)
    new.county_code = fn(normalize, 'county_code', proto)
    new.decision_reasoning = fn(normalize, 'decision_reasoning', proto)
    new.corrective_action = fn(normalize, 'corrective_action', proto)
Example #6
0
def copy_fields_to_builder(
    supervision_violation_builder: entities.StateSupervisionViolation.Builder,
    proto: StateSupervisionViolation,
    metadata: IngestMetadata,
) -> None:
    """Converts an ingest_info proto StateSupervisionViolation to a
    persistence entity."""
    new = supervision_violation_builder

    enum_fields = {
        "violation_type": StateSupervisionViolationType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.violation_type = enum_mappings.get(StateSupervisionViolationType)
    new.violation_type_raw_text = fn(normalize, "violation_type", proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, "state_supervision_violation_id",
                         proto)
    new.violation_date = fn(parse_date, "violation_date", proto)
    new.state_code = parse_region_code_with_override(proto, "state_code",
                                                     metadata)
    new.is_violent = fn(parse_bool, "is_violent", proto)
    new.is_sex_offense = fn(parse_bool, "is_sex_offense", proto)
    new.violated_conditions = fn(normalize, "violated_conditions", proto)
Example #7
0
def copy_fields_to_builder(
        state_assessment_builder: entities.StateAssessment.Builder,
        proto: StateAssessment, metadata: IngestMetadata) -> None:
    """Mutates the provided |state_assessment_builder| by converting an
    ingest_info proto StateAssessment.

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

    new = state_assessment_builder

    enum_fields = {
        'assessment_class': StateAssessmentClass,
        'assessment_type': StateAssessmentType,
        'assessment_level': StateAssessmentLevel,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # Enum mappings
    new.assessment_class = enum_mappings.get(StateAssessmentClass)
    new.assessment_class_raw_text = fn(normalize, 'assessment_class', proto)
    new.assessment_type = enum_mappings.get(StateAssessmentType)
    new.assessment_type_raw_text = fn(normalize, 'assessment_type', proto)
    new.assessment_level = enum_mappings.get(StateAssessmentLevel)
    new.assessment_level_raw_text = fn(normalize, 'assessment_level', proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, 'state_assessment_id', proto)
    new.assessment_date = fn(parse_date, 'assessment_date', proto)
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)
    new.assessment_score = fn(parse_int, 'assessment_score', proto)
    new.assessment_metadata = fn(normalize, 'assessment_metadata', proto)
Example #8
0
def convert(proto: StateBond, metadata: IngestMetadata) -> entities.StateBond:
    """Converts an ingest_info proto StateBond to a persistence entity."""
    new = entities.StateBond.builder()

    enum_fields = {
        "status": BondStatus,
        "bond_type": BondType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.status = enum_mappings.get(BondStatus)
    new.status_raw_text = fn(normalize, "status", proto)
    new.bond_type = enum_mappings.get(BondType)
    new.bond_type_raw_text = fn(normalize, "bond_type", proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, "state_bond_id", proto)
    new.date_paid = fn(parse_date, "date_paid", proto)
    new.state_code = parse_region_code_with_override(proto, "state_code",
                                                     metadata)
    new.county_code = fn(normalize, "county_code", proto)
    new.bond_agent = fn(normalize, "bond_agent", proto)

    (
        new.amount_dollars,
        new.bond_type,
        new.status,
    ) = converter_utils.parse_bond_amount_type_and_status(
        fn(normalize, "amount", proto),
        provided_bond_type=cast(Optional[BondType], new.bond_type),
        provided_status=cast(Optional[BondStatus], new.status),
    )

    return new.build()
Example #9
0
def convert(
    proto: StateSupervisionViolationResponseDecisionEntry,
    metadata: IngestMetadata
) -> entities.StateSupervisionViolationResponseDecisionEntry:
    """Converts an ingest_info proto
    StateSupervisionViolationResponseDecisionEntry to a persistence entity.
    """
    new = entities.StateSupervisionViolationResponseDecisionEntry.builder()

    enum_fields = {
        "decision": StateSupervisionViolationResponseDecision,
        "revocation_type": StateSupervisionViolationResponseRevocationType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # Enum mappings
    new.decision = enum_mappings.get(StateSupervisionViolationResponseDecision)
    new.decision_raw_text = fn(normalize, "decision", proto)

    new.revocation_type = enum_mappings.get(
        StateSupervisionViolationResponseRevocationType)
    new.revocation_type_raw_text = fn(normalize, "revocation_type", proto)

    # 1-to-1 mappings
    new.state_code = parse_region_code_with_override(proto, "state_code",
                                                     metadata)

    return new.build()
def copy_fields_to_builder(
    state_incarceration_incident_builder: entities.StateIncarcerationIncident.
    Builder,
    proto: StateIncarcerationIncident,
    metadata: IngestMetadata,
) -> None:
    """Mutates the provided |state_incarceration_incident_builder| by converting
    an ingest_info proto StateIncarcerationIncident.

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

    enum_fields = {
        "incident_type": StateIncarcerationIncidentType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.incident_type = enum_mappings.get(StateIncarcerationIncidentType)
    new.incident_type_raw_text = fn(normalize, "incident_type", proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, "state_incarceration_incident_id",
                         proto)
    new.incident_date = fn(parse_date, "incident_date", proto)
    new.state_code = parse_region_code_with_override(proto, "state_code",
                                                     metadata)
    new.facility = fn(normalize, "facility", proto)
    new.location_within_facility = fn(normalize, "location_within_facility",
                                      proto)
    new.incident_details = fn(normalize, "incident_details", proto)
Example #11
0
def copy_fields_to_builder(court_case_builder: entities.StateCourtCase.Builder,
                           proto: StateCourtCase,
                           metadata: IngestMetadata) -> None:
    """Mutates the provided |court_case_builder| by converting an ingest_info
    proto StateCourtCase.

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

    enum_fields = {
        'status': StateCourtCaseStatus,
        'court_type': StateCourtType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.status = enum_mappings.get(
        StateCourtCaseStatus,
        default=StateCourtCaseStatus.PRESENT_WITHOUT_INFO)
    new.status_raw_text = fn(normalize, 'status', proto)

    new.court_type = enum_mappings.get(
        StateCourtType, default=StateCourtType.PRESENT_WITHOUT_INFO)
    new.court_type_raw_text = fn(normalize, 'court_type', proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, 'state_court_case_id', proto)
    new.date_convicted = fn(parse_date, 'date_convicted', proto)
    new.next_court_date = fn(parse_date, 'next_court_date', proto)
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)
    new.county_code = fn(normalize, 'county_code', proto)
    new.court_fee_dollars = fn(parse_dollars, 'court_fee_dollars', proto)
def convert(
        proto: StateIncarcerationIncidentOutcome, metadata: IngestMetadata
) -> entities.StateIncarcerationIncidentOutcome:
    """Converts an ingest_info proto StateIncarcerationIncidentOutcome to a
    persistence entity.
    """
    new = entities.StateIncarcerationIncidentOutcome.builder()

    enum_fields = {
        'outcome_type': StateIncarcerationIncidentOutcomeType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.outcome_type = enum_mappings.get(StateIncarcerationIncidentOutcomeType)
    new.outcome_type_raw_text = fn(normalize, 'outcome_type', proto)

    # 1-to-1 mappings
    new.external_id = \
        fn(parse_external_id, 'state_incarceration_incident_outcome_id', proto)
    new.date_effective = fn(parse_date, 'date_effective', proto)
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)
    new.outcome_description = fn(normalize, 'outcome_description', proto)
    new.punishment_length_days = fn(parse_int, 'punishment_length_days', proto)

    return new.build()
Example #13
0
def copy_fields_to_builder(
    supervision_period_builder: entities.StateSupervisionPeriod.Builder,
    proto: StateSupervisionPeriod,
    metadata: IngestMetadata,
) -> None:
    """Mutates the provided |supervision_period_builder| by converting an ingest_info proto StateSupervisionPeriod.

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

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, "state_supervision_period_id", proto)

    new.start_date = fn(parse_date, "start_date", proto)
    new.termination_date = fn(parse_date, "termination_date", proto)
    new.state_code = parse_region_code_with_override(proto, "state_code", metadata)
    new.county_code = fn(normalize, "county_code", proto)
    new.supervision_site = fn(normalize, "supervision_site", proto)
    if proto.conditions:
        new.conditions = create_comma_separated_list(proto, "conditions")

    enum_fields = {
        "status": StateSupervisionPeriodStatus,
        "supervision_type": StateSupervisionType,
        "supervision_period_supervision_type": StateSupervisionPeriodSupervisionType,
        "admission_reason": StateSupervisionPeriodAdmissionReason,
        "termination_reason": StateSupervisionPeriodTerminationReason,
        "supervision_level": StateSupervisionLevel,
        "custodial_authority": StateCustodialAuthority,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    # Status default based on presence of admission/release dates
    if new.termination_date:
        status_default = StateSupervisionPeriodStatus.TERMINATED
    elif new.start_date and not new.termination_date:
        status_default = StateSupervisionPeriodStatus.UNDER_SUPERVISION
    else:
        status_default = StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO
    new.status = enum_mappings.get(StateSupervisionPeriodStatus, default=status_default)

    new.status_raw_text = fn(normalize, "status", proto)
    new.supervision_type = enum_mappings.get(StateSupervisionType)
    new.supervision_type_raw_text = fn(normalize, "supervision_type", proto)
    new.supervision_period_supervision_type = enum_mappings.get(
        StateSupervisionPeriodSupervisionType
    )
    new.supervision_period_supervision_type_raw_text = fn(
        normalize, "supervision_period_supervision_type", proto
    )
    new.admission_reason = enum_mappings.get(StateSupervisionPeriodAdmissionReason)
    new.admission_reason_raw_text = fn(normalize, "admission_reason", proto)
    new.termination_reason = enum_mappings.get(StateSupervisionPeriodTerminationReason)
    new.termination_reason_raw_text = fn(normalize, "termination_reason", proto)
    new.supervision_level = enum_mappings.get(StateSupervisionLevel)
    new.supervision_level_raw_text = fn(normalize, "supervision_level", proto)
    new.custodial_authority = enum_mappings.get(StateCustodialAuthority)
    new.custodial_authority_raw_text = fn(normalize, "custodial_authority", proto)
Example #14
0
def copy_fields_to_builder(
    fine_builder: entities.StateFine.Builder, proto: StateFine, metadata: IngestMetadata
) -> None:
    """Mutates the provided |fine_builder| by converting an ingest_info proto
    StateFine.

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

    enum_fields = {
        "status": StateFineStatus,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.status = enum_mappings.get(
        StateFineStatus, default=StateFineStatus.PRESENT_WITHOUT_INFO
    )
    new.status_raw_text = fn(normalize, "status", proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, "state_fine_id", proto)
    new.date_paid = fn(parse_date, "date_paid", proto)
    new.state_code = parse_region_code_with_override(proto, "state_code", metadata)
    new.county_code = fn(normalize, "county_code", proto)
    new.fine_dollars = fn(parse_dollars, "fine_dollars", proto)
def copy_fields_to_builder(incarceration_period_builder: entities.
                           StateIncarcerationPeriod.Builder,
                           proto: StateIncarcerationPeriod,
                           metadata: IngestMetadata) -> None:
    """Mutates the provided |incarceration_period_builder| by converting an
    ingest_info proto StateIncarcerationPeriod.

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

    enum_fields = {
        'status': StateIncarcerationPeriodStatus,
        'incarceration_type': StateIncarcerationType,
        'facility_security_level': StateIncarcerationFacilitySecurityLevel,
        'admission_reason': StateIncarcerationPeriodAdmissionReason,
        'projected_release_reason': StateIncarcerationPeriodReleaseReason,
        'release_reason': StateIncarcerationPeriodReleaseReason
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.status = enum_mappings.get(
        StateIncarcerationPeriodStatus,
        default=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO)
    new.status_raw_text = fn(normalize, 'status', proto)
    new.incarceration_type = enum_mappings.get(
        StateIncarcerationType, default=StateIncarcerationType.STATE_PRISON)
    new.incarceration_type_raw_text = fn(normalize, 'incarceration_type',
                                         proto)
    new.facility_security_level = enum_mappings.get(
        StateIncarcerationFacilitySecurityLevel)
    new.facility_security_level_raw_text = fn(normalize,
                                              'facility_security_level', proto)
    new.admission_reason = enum_mappings.get(
        StateIncarcerationPeriodAdmissionReason)
    new.admission_reason_raw_text = fn(normalize, 'admission_reason', proto)
    new.projected_release_reason = enum_mappings.get(
        StateIncarcerationPeriodReleaseReason,
        field_name='projected_release_reason')
    new.projected_release_reason_raw_text = fn(normalize,
                                               'projected_release_reason',
                                               proto)
    new.release_reason = enum_mappings.get(
        StateIncarcerationPeriodReleaseReason, field_name='release_reason')
    new.release_reason_raw_text = fn(normalize, 'release_reason', proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, 'state_incarceration_period_id',
                         proto)

    new.admission_date = fn(parse_date, 'admission_date', proto)
    new.release_date = fn(parse_date, 'release_date', proto)
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)
    new.county_code = fn(normalize, 'county_code', proto)
    new.facility = fn(normalize, 'facility', proto)
    new.housing_unit = fn(normalize, 'housing_unit', proto)
Example #16
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()
def convert(proto: StatePersonExternalId,
            metadata: IngestMetadata) -> entities.StatePersonExternalId:
    """Converts an ingest_info proto Hold to a persistence entity."""
    new = entities.StatePersonExternalId.builder()

    new.external_id = \
        fn(_parse_state_external_id, 'state_person_external_id_id', proto)
    new.id_type = fn(normalize, 'id_type', proto)
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)

    return new.build()
def copy_fields_to_builder(
    incarceration_sentence_builder: entities.StateIncarcerationSentence.
    Builder,
    proto: StateIncarcerationSentence,
    metadata: IngestMetadata,
) -> None:
    """Mutates the provided |incarceration_sentence_builder| by converting an
    ingest_info proto StateIncarcerationSentence.

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

    enum_fields = {
        "status": StateSentenceStatus,
        "incarceration_type": StateIncarcerationType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # Enum mappings
    new.status = enum_mappings.get(
        StateSentenceStatus, default=StateSentenceStatus.PRESENT_WITHOUT_INFO)
    new.status_raw_text = fn(normalize, "status", proto)

    new.incarceration_type = enum_mappings.get(
        StateIncarcerationType, default=StateIncarcerationType.STATE_PRISON)
    new.incarceration_type_raw_text = fn(normalize, "incarceration_type",
                                         proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, "state_incarceration_sentence_id",
                         proto)
    new.date_imposed = fn(parse_date, "date_imposed", proto)
    new.start_date = fn(parse_date, "start_date", proto)
    new.projected_min_release_date = fn(parse_date,
                                        "projected_min_release_date", proto)
    new.projected_max_release_date = fn(parse_date,
                                        "projected_max_release_date", proto)
    new.completion_date = fn(parse_date, "completion_date", proto)
    new.parole_eligibility_date = fn(parse_date, "parole_eligibility_date",
                                     proto)
    new.state_code = parse_region_code_with_override(proto, "state_code",
                                                     metadata)
    new.county_code = fn(normalize, "county_code", proto)
    new.min_length_days = fn(parse_days, "min_length", proto)
    new.max_length_days = fn(parse_days, "max_length", proto)
    new.is_life = fn(parse_bool, "is_life", proto)
    new.is_capital_punishment = fn(parse_bool, "is_capital_punishment", proto)
    new.parole_possible = fn(parse_bool, "parole_possible", proto)
    new.initial_time_served_days = fn(parse_days, "initial_time_served", proto)
    new.good_time_days = fn(parse_days, "good_time", proto)
    new.earned_time_days = fn(parse_days, "earned_time", proto)
def convert(
    proto: StateSupervisionViolatedConditionEntry, metadata: IngestMetadata
) -> entities.StateSupervisionViolatedConditionEntry:
    """Converts an ingest_info proto StateSupervisionViolatedConditionEntry to a
    persistence entity."""
    new = entities.StateSupervisionViolatedConditionEntry.builder()

    # 1-to-1 mappings
    new.condition = fn(normalize, "condition", proto)
    new.state_code = parse_region_code_with_override(proto, "state_code",
                                                     metadata)

    return new.build()
Example #20
0
def copy_fields_to_builder(
        new: entities.StateCharge.Builder,
        proto: StateCharge,
        metadata: IngestMetadata) -> None:
    """Mutates the provided |charge_builder| by converting an ingest_info proto
     StateCharge.

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

    enum_fields = {
        'status': ChargeStatus,
        'classification_type': StateChargeClassificationType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # Enum values
    new.status = enum_mappings.get(ChargeStatus,
                                   default=ChargeStatus.PRESENT_WITHOUT_INFO)
    new.status_raw_text = fn(normalize, 'status', proto)
    new.classification_type = \
        enum_mappings.get(StateChargeClassificationType)
    new.classification_type_raw_text = \
        fn(normalize, 'classification_type', proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, 'state_charge_id', proto)
    new.offense_date = fn(parse_date, 'offense_date', proto)
    new.date_charged = fn(parse_date, 'date_charged', proto)
    new.state_code = parse_region_code_with_override(
        proto, 'state_code', metadata)
    new.county_code = fn(normalize, 'county_code', proto)
    new.statute = fn(normalize, 'statute', proto)

    new.ncic_code = fn(normalize, 'ncic_code', proto)
    new.description = fn(normalize, 'description', proto)
    if new.description is None and new.ncic_code is not None:
        ncic_description = ncic.get_description(new.ncic_code)
        if ncic_description:
            new.description = normalize(ncic_description)

    new.attempted = fn(parse_bool, 'attempted', proto)
    if new.classification_type is None:
        new.classification_type = \
            StateChargeClassificationType.find_in_string(new.description)
    new.classification_subtype = \
        fn(normalize, 'classification_subtype', proto)
    new.counts = fn(parse_int, 'counts', proto)
    new.charge_notes = fn(normalize, 'charge_notes', proto)
    new.is_controlling = fn(parse_bool, 'is_controlling', proto)
    new.charging_entity = fn(normalize, 'charging_entity', proto)
Example #21
0
def copy_fields_to_builder(
        supervision_period_builder: entities.StateSupervisionPeriod.Builder,
        proto: StateSupervisionPeriod, metadata: IngestMetadata) -> None:
    """Mutates the provided |supervision_period_builder| by converting an
    ingest_info proto StateSupervisionPeriod.

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

    enum_fields = {
        'status': StateSupervisionPeriodStatus,
        'supervision_type': StateSupervisionType,
        'admission_reason': StateSupervisionPeriodAdmissionReason,
        'termination_reason': StateSupervisionPeriodTerminationReason,
        'supervision_level': StateSupervisionLevel
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.status = enum_mappings.get(
        StateSupervisionPeriodStatus,
        default=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO)
    new.status_raw_text = fn(normalize, 'status', proto)
    new.supervision_type = enum_mappings.get(StateSupervisionType)
    new.supervision_type_raw_text = fn(normalize, 'supervision_type', proto)
    new.admission_reason = enum_mappings.get(
        StateSupervisionPeriodAdmissionReason)
    new.admission_reason_raw_text = fn(normalize, 'admission_reason', proto)
    new.termination_reason = enum_mappings.get(
        StateSupervisionPeriodTerminationReason)
    new.termination_reason_raw_text = fn(normalize, 'termination_reason',
                                         proto)
    new.supervision_level = enum_mappings.get(StateSupervisionLevel)
    new.supervision_level_raw_text = fn(normalize, 'supervision_level', proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, 'state_supervision_period_id',
                         proto)

    new.start_date = fn(parse_date, 'start_date', proto)
    new.termination_date = fn(parse_date, 'termination_date', proto)
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)
    new.county_code = fn(normalize, 'county_code', proto)
    new.supervision_site = fn(normalize, 'supervision_site', proto)
    if proto.conditions:
        new.conditions = create_comma_separated_list(proto, 'conditions')
def convert(proto: StatePersonEthnicity,
            metadata: IngestMetadata) -> entities.StatePersonEthnicity:
    """Converts an ingest_info proto Hold to a persistence entity."""
    new = entities.StatePersonEthnicity.builder()

    enum_fields = {
        'ethnicity': Ethnicity,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # Enum mappings
    new.ethnicity = enum_mappings.get(Ethnicity)
    new.ethnicity_raw_text = fn(normalize, 'ethnicity', proto)

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

    return new.build()
Example #23
0
def copy_fields_to_builder(
        state_program_assignment_builder:
        entities.StateProgramAssignment.Builder,
        proto: StateProgramAssignment,
        metadata: IngestMetadata) -> None:
    """Mutates the provided |state_program_assignment_builder| by converting an
    ingest_info proto StateProgramAssignment.

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

    new = state_program_assignment_builder

    enum_fields = {
        'participation_status': StateProgramAssignmentParticipationStatus,
        'discharge_reason': StateProgramAssignmentDischargeReason,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # Enum mappings
    new.participation_status = \
        enum_mappings.get(
            StateProgramAssignmentParticipationStatus,
            default=
            StateProgramAssignmentParticipationStatus.PRESENT_WITHOUT_INFO)
    new.participation_status_raw_text = fn(
        normalize, 'participation_status', proto)
    new.discharge_reason = enum_mappings.get(
        StateProgramAssignmentDischargeReason)
    new.discharge_reason_raw_text = fn(normalize, 'discharge_reason', proto)

    # 1-to-1 mappings
    new.external_id = fn(
        parse_external_id, 'state_program_assignment_id', proto)
    new.referral_date = fn(parse_date, 'referral_date', proto)
    new.start_date = fn(parse_date, 'start_date', proto)
    new.discharge_date = fn(parse_date, 'discharge_date', proto)
    new.program_id = fn(normalize, 'program_id', proto)
    new.program_location_id = fn(normalize, 'program_location_id', proto)
    new.state_code = parse_region_code_with_override(
        proto, 'state_code', metadata)
    new.referral_metadata = fn(normalize, 'referral_metadata', proto)
Example #24
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()
def copy_fields_to_builder(
    supervision_violation_response_builder: entities.
    StateSupervisionViolationResponse.Builder,
    proto: StateSupervisionViolationResponse,
    metadata: IngestMetadata,
) -> None:
    """Converts an ingest_info proto StateSupervisionViolationResponse to a
    persistence entity."""
    new = supervision_violation_response_builder

    enum_fields = {
        "response_type": StateSupervisionViolationResponseType,
        "decision": StateSupervisionViolationResponseDecision,
        "revocation_type": StateSupervisionViolationResponseRevocationType,
        "deciding_body_type":
        StateSupervisionViolationResponseDecidingBodyType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.response_type = enum_mappings.get(
        StateSupervisionViolationResponseType)
    new.response_type_raw_text = fn(normalize, "response_type", proto)
    new.response_subtype = fn(normalize, "response_subtype", proto)
    new.decision = enum_mappings.get(StateSupervisionViolationResponseDecision)
    new.decision_raw_text = fn(normalize, "decision", proto)
    new.revocation_type = enum_mappings.get(
        StateSupervisionViolationResponseRevocationType)
    new.revocation_type_raw_text = fn(normalize, "revocation_type", proto)
    new.deciding_body_type = enum_mappings.get(
        StateSupervisionViolationResponseDecidingBodyType)
    new.deciding_body_type_raw_text = fn(normalize, "deciding_body_type",
                                         proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id,
                         "state_supervision_violation_response_id", proto)
    new.response_date = fn(parse_date, "response_date", proto)
    new.state_code = parse_region_code_with_override(proto, "state_code",
                                                     metadata)
    new.is_draft = fn(parse_bool, "is_draft", proto)
Example #26
0
def convert(
        proto: StateSupervisionViolationTypeEntry, metadata: IngestMetadata
) -> entities.StateSupervisionViolationTypeEntry:
    """Converts an ingest_info proto StateSupervisionViolationTypeEntry to a
    persistence entity."""
    new = entities.StateSupervisionViolationTypeEntry.builder()

    enum_fields = {
        'violation_type': StateSupervisionViolationType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # Enum mappings
    new.violation_type = enum_mappings.get(StateSupervisionViolationType)
    new.violation_type_raw_text = fn(normalize, 'violation_type', proto)

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

    return new.build()
Example #27
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()
def copy_fields_to_builder(supervision_sentence_builder: entities.
                           StateSupervisionSentence.Builder,
                           proto: StateSupervisionSentence,
                           metadata: IngestMetadata) -> None:
    """Mutates the provided |supervision_sentence_builder| by converting an
    ingest_info proto StateSupervisionSentence.

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

    enum_fields = {
        'status': StateSentenceStatus,
        'supervision_type': StateSupervisionType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # Enum mappings
    new.status = enum_mappings.get(
        StateSentenceStatus, default=StateSentenceStatus.PRESENT_WITHOUT_INFO)
    new.status_raw_text = fn(normalize, 'status', proto)
    new.supervision_type = enum_mappings.get(StateSupervisionType)
    new.supervision_type_raw_text = fn(normalize, 'supervision_type', proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, 'state_supervision_sentence_id',
                         proto)
    new.date_imposed = fn(parse_date, 'date_imposed', proto)
    new.start_date = fn(parse_date, 'start_date', proto)
    new.completion_date, new.projected_completion_date = parse_completion_date(
        proto, metadata)
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)
    new.county_code = fn(normalize, 'county_code', proto)
    new.min_length_days = fn(parse_days, 'min_length', proto)
    new.max_length_days = fn(parse_days, 'max_length', proto)

    set_status_if_needed(new)
def convert(
        proto: StateSupervisionCaseTypeEntry,
        metadata: IngestMetadata) -> entities.StateSupervisionCaseTypeEntry:
    """Converts an ingest_info proto StateSupervisionCaseTypeEntry to a
    persistence entity.
    """
    new = entities.StateSupervisionCaseTypeEntry.builder()

    enum_fields = {
        'case_type': StateSupervisionCaseType,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.state_code = parse_region_code_with_override(
        proto, 'state_code', metadata)
    new.case_type = enum_mappings.get(StateSupervisionCaseType)
    new.case_type_raw_text = fn(normalize, 'case_type', proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, 'state_supervision_case_type_entry_id', proto)

    return new.build()
def convert(proto: StateSupervisionViolationResponse,
            metadata: IngestMetadata) \
        -> entities.StateSupervisionViolationResponse:
    """Converts an ingest_info proto StateSupervisionViolationResponse to a
    persistence entity."""
    new = entities.StateSupervisionViolationResponse.builder()

    enum_fields = {
        'response_type': StateSupervisionViolationResponseType,
        'decision': StateSupervisionViolationResponseDecision,
        'revocation_type': StateSupervisionViolationResponseRevocationType,
        'deciding_body_type': StateSupervisionViolationResponseDecidingBodyType
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # enum values
    new.response_type = enum_mappings.get(
        StateSupervisionViolationResponseType)
    new.response_type_raw_text = fn(normalize, 'response_type', proto)
    new.decision = enum_mappings.get(StateSupervisionViolationResponseDecision)
    new.decision_raw_text = fn(normalize, 'decision', proto)
    new.revocation_type = \
        enum_mappings.get(StateSupervisionViolationResponseRevocationType)
    new.revocation_type_raw_text = fn(normalize, 'revocation_type', proto)
    new.deciding_body_type = \
        enum_mappings.get(StateSupervisionViolationResponseDecidingBodyType)
    new.deciding_body_type_raw_text = fn(normalize, 'deciding_body_type',
                                         proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id,
                         'state_supervision_violation_response_id', proto)
    new.response_date = fn(parse_date, 'response_date', proto)
    new.state_code = parse_region_code_with_override(proto, 'state_code',
                                                     metadata)

    return new.build()