# Path: collectors/ictrp/record.py
# class Record(base.Record):
# 
#     # Config
# 
#     table = 'ictrp'
# 
#     # Main
# 
#     main_id = Text(primary_key=True)
#     register = Text()
#     last_refreshed_on = Date('%d %B %Y')
#     date_of_registration = Text()  # non regular format
#     primary_sponsor = Text()
#     public_title = Text()
#     scientific_title = Text()
#     date_of_first_enrollment = Text()  # non regular format
#     target_sample_size = Integer()
#     recruitment_status = Text()
#     url = Text()
#     study_type = Text()
#     study_design = Text()
#     study_phase = Text()
# 
#     # Additional
# 
#     countries_of_recruitment = Array()
#     contacts = Json()
#     key_inclusion_exclusion_criteria = Text()  # not presented on the site
#     health_conditions_or_problems_studied = Array()
#     interventions = Array()
#     primary_outcomes = Array()
#     secondary_outcomes = Array()
#     secondary_ids = Array()
#     sources_of_monetary_support = Array()
#     secondary_sponsors = Array()


import logging
from .record import Record
    path = '//*[re:test(@id, "DataList12_ctl\d+_Outcome_NameLabel")]/text()'
    value = res.xpath(path).extract()
    data[key] = value

    key = 'secondary_outcomes'
    path = '//*[re:test(@id, "DataList14_ctl\d+_Outcome_NameLabel")]/text()'
    value = res.xpath(path).extract()
    data[key] = value

    key = 'secondary_ids'
    path = '//*[re:test(@id, "DataList16_ctl\d+_SecondaryIDLabel")]/text()'
    value = res.xpath(path).extract()
    data[key] = value

    key = 'sources_of_monetary_support'
    path = '//*[re:test(@id, "DataList18_ctl\d+_Source_NameLabel")]/text()'
    value = res.xpath(path).extract()
    data[key] = value

    key = 'secondary_sponsors'
    path = '//*[re:test(@id, "DataList20_ctl\d+_Secondary_SponsorLabel")]/text()'
    value = res.xpath(path).extract()
    data[key] = value

    # Skip empty
    if not data['main_id']:
        logger.debug('No main_id: ICTRP - %s' % res.url)
        return None

    # Create record

# Path: collectors/ictrp/record.py
# class Record(base.Record):
# 
#     # Config
# 
#     table = 'ictrp'
# 
#     # Main
# 
#     main_id = Text(primary_key=True)
#     register = Text()
#     last_refreshed_on = Date('%d %B %Y')
#     date_of_registration = Text()  # non regular format
#     primary_sponsor = Text()
#     public_title = Text()
#     scientific_title = Text()
#     date_of_first_enrollment = Text()  # non regular format
#     target_sample_size = Integer()
#     recruitment_status = Text()
#     url = Text()
#     study_type = Text()
#     study_design = Text()
#     study_phase = Text()
# 
#     # Additional
# 
#     countries_of_recruitment = Array()
#     contacts = Json()
#     key_inclusion_exclusion_criteria = Text()  # not presented on the site
#     health_conditions_or_problems_studied = Array()
#     interventions = Array()
#     primary_outcomes = Array()
#     secondary_outcomes = Array()
#     secondary_ids = Array()
#     sources_of_monetary_support = Array()
#     secondary_sponsors = Array()


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

    path = '//*[re:test(@id, "DataList12_ctl\d+_Outcome_NameLabel")]/text()'
    value = res.xpath(path).extract()
    data[key] = value

    key = 'secondary_outcomes'
    path = '//*[re:test(@id, "DataList14_ctl\d+_Outcome_NameLabel")]/text()'
    value = res.xpath(path).extract()
    data[key] = value

    key = 'secondary_ids'
    path = '//*[re:test(@id, "DataList16_ctl\d+_SecondaryIDLabel")]/text()'
    value = res.xpath(path).extract()
    data[key] = value

    key = 'sources_of_monetary_support'
    path = '//*[re:test(@id, "DataList18_ctl\d+_Source_NameLabel")]/text()'
    value = res.xpath(path).extract()
    data[key] = value

    key = 'secondary_sponsors'
    path = '//*[re:test(@id, "DataList20_ctl\d+_Secondary_SponsorLabel")]/text()'
    value = res.xpath(path).extract()
    data[key] = value

    # Skip empty
    if not data['main_id']:
        logger.debug('No main_id: ICTRP - %s' % res.url)
        return None

    # Create record

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