# Path: collectors/pfizer/record.py
# class Record(base.Record):
# 
#     # Config
# 
#     table = 'pfizer'
# 
#     # General
# 
#     nct_id = Text(primary_key=True)
#     title = Text()
# 
#     # Description
# 
#     study_type = Text()
#     organization_id = Text()
#     status = Text()
#     study_start_date = Date('%B, %Y')
#     study_end_date = Date('%B, %Y')
# 
#     # Eligibility
# 
#     eligibility_criteria = Text()
#     gender = Text()
#     age_range = Text()
#     healthy_volunteers_allowed = Boolean('Accepts Healthy Volunteers')


from .record import Record
    data[key] = value

    key = 'study_end_date'
    path = '.field-name-field-study-end-date .field-item span::text'
    value = res.css(path).extract_first()
    data[key] = value

    # Eligibility

    key = 'eligibility_criteria'
    path = '.field-name-field-criteria .field-item *::text'
    value = ''.join(res.css(path).extract())
    data[key] = value

    key = 'gender'
    path = '.field-name-field-gender .field-item::text'
    value = res.css(path).extract_first()
    data[key] = value

    key = 'age_range'
    path = '//label[text() = "Age Range:"]/../text()'
    value = ''.join(res.xpath(path).extract()).strip()
    data[key] = value

    key = 'healthy_volunteers_allowed'
    path = '.field-name-field-healthy-volunteers-allowed .field-item::text'
    value = res.css(path).extract_first()
    data[key] = value

    # Create record

# Path: collectors/pfizer/record.py
# class Record(base.Record):
# 
#     # Config
# 
#     table = 'pfizer'
# 
#     # General
# 
#     nct_id = Text(primary_key=True)
#     title = Text()
# 
#     # Description
# 
#     study_type = Text()
#     organization_id = Text()
#     status = Text()
#     study_start_date = Date('%B, %Y')
#     study_end_date = Date('%B, %Y')
# 
#     # Eligibility
# 
#     eligibility_criteria = Text()
#     gender = Text()
#     age_range = Text()
#     healthy_volunteers_allowed = Boolean('Accepts Healthy Volunteers')


# Path: collectors/pfizer/parser.py
from .record import Record

    data[key] = value

    key = 'study_end_date'
    path = '.field-name-field-study-end-date .field-item span::text'
    value = res.css(path).extract_first()
    data[key] = value

    # Eligibility

    key = 'eligibility_criteria'
    path = '.field-name-field-criteria .field-item *::text'
    value = ''.join(res.css(path).extract())
    data[key] = value

    key = 'gender'
    path = '.field-name-field-gender .field-item::text'
    value = res.css(path).extract_first()
    data[key] = value

    key = 'age_range'
    path = '//label[text() = "Age Range:"]/../text()'
    value = ''.join(res.xpath(path).extract()).strip()
    data[key] = value

    key = 'healthy_volunteers_allowed'
    path = '.field-name-field-healthy-volunteers-allowed .field-item::text'
    value = res.css(path).extract_first()
    data[key] = value

    # Create record

    record = Record.create(res.url, data)