Exemplo n.º 1
0
def convert(proto, metadata: IngestMetadata) -> entities.Bond:
    """Converts an ingest_info proto Bond to a persistence entity."""
    new = entities.Bond.builder()

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

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

    # parsed values
    new.external_id = fn(parse_external_id, 'bond_id', 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()
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def testEnumMultipleFieldShareEnumType(self):
        enum_fields = {
            "admission_reason": StateIncarcerationPeriodAdmissionReason,
            "projected_release_reason": StateIncarcerationPeriodReleaseReason,
            "release_reason": StateIncarcerationPeriodReleaseReason,
        }

        proto = StateIncarcerationPeriod(
            admission_reason="PAROLE_REVOCATION",
            projected_release_reason="CONDITIONAL_RELEASE",
            release_reason="SERVED",
        )

        enum_mappings = EnumMappings(proto, enum_fields,
                                     EnumOverrides.Builder().build())

        self.assertEqual(
            StateIncarcerationPeriodReleaseReason.CONDITIONAL_RELEASE,
            enum_mappings.get(
                StateIncarcerationPeriodReleaseReason,
                field_name="projected_release_reason",
            ),
        )

        self.assertEqual(
            StateIncarcerationPeriodReleaseReason.SENTENCE_SERVED,
            enum_mappings.get(StateIncarcerationPeriodReleaseReason,
                              field_name="release_reason"),
        )
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)
Exemplo n.º 7
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)
    if proto.violated_conditions:
        new.violated_conditions = create_comma_separated_list(
            proto, 'violated_conditions')
Exemplo n.º 8
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)
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()
Exemplo n.º 10
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)
Exemplo n.º 11
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()
Exemplo n.º 12
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()
Exemplo n.º 13
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 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)
Exemplo n.º 15
0
def copy_fields_to_builder(sentence_builder, proto, metadata) -> None:
    """Mutates the provided |sentence_builder| by converting an ingest_info
    proto Sentence.

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

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

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

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, "sentence_id", proto)
    new.sentencing_region = fn(normalize, "sentencing_region", 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_probation = fn(parse_bool, "is_probation", proto)
    new.is_suspended = fn(parse_bool, "is_suspended", proto)
    new.fine_dollars = fn(parse_dollars, "fine_dollars", proto)
    new.parole_possible = fn(parse_bool, "parole_possible", proto)
    new.post_release_supervision_length_days = fn(
        parse_days, "post_release_supervision_length", proto)
    new.date_imposed = fn(parse_date, "date_imposed", proto)
    new.completion_date, new.projected_completion_date = parse_completion_date(
        proto, metadata)

    set_status_if_needed(new)
Exemplo n.º 16
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)
Exemplo n.º 17
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)
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)
Exemplo n.º 19
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)
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
    def testEnumFromOriginalFieldIsPreferred(self):
        enum_fields = {
            "charge_class": ChargeClass,
            "status": ChargeStatus,
        }
        proto = Charge(charge_class="O", status="VIOLATION")

        overrides_builder = EnumOverrides.Builder()
        overrides_builder.add("O", ChargeClass.PROBATION_VIOLATION)
        overrides_builder.add("VIOLATION", ChargeClass.INFRACTION,
                              ChargeStatus)
        enum_mappings = EnumMappings(proto, enum_fields,
                                     overrides_builder.build())

        self.assertEqual(ChargeClass.PROBATION_VIOLATION,
                         enum_mappings.get(ChargeClass))
    def testMultipleMappingsFails(self):
        enum_fields = {
            'degree': ChargeDegree,
            'status': ChargeStatus,
        }
        proto = Charge(degree='O', status='VIOLATION')

        overrides_builder = EnumOverrides.Builder()
        overrides_builder.add('O', ChargeClass.PROBATION_VIOLATION,
                              ChargeDegree)
        overrides_builder.add('VIOLATION', ChargeClass.INFRACTION,
                              ChargeStatus)
        enum_mappings = EnumMappings(proto, enum_fields,
                                     overrides_builder.build())

        with self.assertRaises(ValueError):
            enum_mappings.get(ChargeClass)
Exemplo n.º 23
0
def convert(proto, metadata: IngestMetadata) -> entities.Hold:
    """Converts an ingest_info proto Hold to a persistence entity."""
    new = entities.Hold.builder()

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

    new.status = enum_mappings.get(HoldStatus,
                                   default=HoldStatus.PRESENT_WITHOUT_INFO)
    new.status_raw_text = fn(normalize, "status", proto)

    new.external_id = fn(parse_external_id, "hold_id", proto)
    new.jurisdiction_name = fn(normalize, "jurisdiction_name", proto)

    return new.build()
Exemplo n.º 24
0
    def testMultipleMappingsFails(self):
        enum_fields = {
            "degree": ChargeDegree,
            "status": ChargeStatus,
        }
        proto = Charge(degree="O", status="VIOLATION")

        overrides_builder = EnumOverrides.Builder()
        overrides_builder.add("O", ChargeClass.PROBATION_VIOLATION,
                              ChargeDegree)
        overrides_builder.add("VIOLATION", ChargeClass.INFRACTION,
                              ChargeStatus)
        enum_mappings = EnumMappings(proto, enum_fields,
                                     overrides_builder.build())

        with self.assertRaises(ValueError):
            enum_mappings.get(ChargeClass)
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()
Exemplo n.º 26
0
def copy_fields_to_builder(
    new: entities.Charge.Builder, proto, metadata: IngestMetadata
) -> None:
    """Mutates the provided |charge_builder| by converting an ingest_info proto
    Charge.

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

    enum_fields = {
        "degree": ChargeDegree,
        "charge_class": ChargeClass,
        "status": ChargeStatus,
    }
    enum_mappings = EnumMappings(proto, enum_fields, metadata.enum_overrides)

    # Enum values
    new.degree = enum_mappings.get(ChargeDegree)
    new.degree_raw_text = fn(normalize, "degree", proto)
    new.charge_class = enum_mappings.get(ChargeClass)
    new.class_raw_text = fn(normalize, "charge_class", proto)
    new.status = enum_mappings.get(
        ChargeStatus, default=ChargeStatus.PRESENT_WITHOUT_INFO
    )
    new.status_raw_text = fn(normalize, "status", proto)

    # 1-to-1 mappings
    new.external_id = fn(parse_external_id, "charge_id", proto)
    new.offense_date = fn(parse_date, "offense_date", proto)
    new.statute = fn(normalize, "statute", proto)
    new.name = fn(normalize, "name", proto)
    if new.charge_class is None:
        new.charge_class = ChargeClass.find_in_string(new.name)
    new.attempted = fn(parse_bool, "attempted", proto)
    new.level = fn(normalize, "level", proto)
    new.fee_dollars = fn(parse_dollars, "fee_dollars", proto)
    new.charging_entity = fn(normalize, "charging_entity", proto)
    new.case_number = fn(normalize, "case_number", proto)
    new.court_type = fn(normalize, "court_type", proto)
    new.next_court_date = fn(parse_date, "next_court_date", proto)
    new.judge_name = fn(normalize, "judge_name", proto)
    new.charge_notes = fn(normalize, "charge_notes", proto)
Exemplo n.º 27
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)
Exemplo n.º 28
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()
Exemplo n.º 29
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()
Exemplo n.º 30
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()