コード例 #1
0
def parse_subject(row, source=None):
    """Parse a row into a Subject.

    Parameters
    ----------
    row : dict-like
        Object whose keys are column headings and values are the row values.
    source : model.Source
        Source for the returned subject.

    Returns
    -------
    Subject
    """
    subject = Subject()
    subject.sex = get_sex(row)
    subject.country = get_country(row)
    subject.race = get_race(row)
    subject.csection = get_csection(row)
    subject.disease = get_disease(row)
    subject.dob = get_dob(row)

    # Initialize equality attrs
    if not source:
        subject.source = parse_source(row)
    elif isinstance(source, Source):
        subject.source = source
    else:
        raise TypeError(f'Given source was not of type {type(Source())!r}.')
    subject.orig_study_id = get_study_id(row)
    subject.orig_subject_id = get_subject_id(row)
    return subject