# Path: collectors/pubmed/record.py
# class Record(base.Record):
# 
#     # Config
# 
#     table = 'pubmed'
# 
#     # Medline
# 
#     pmid = Text(primary_key=True)
#     date_created = Date('%Y-%m-%d')
#     date_completed = Date('%Y-%m-%d')
#     date_revised = Date('%Y-%m-%d')
#     country = Text()
#     medline_ta = Text()
#     nlm_unique_id = Text()
#     issn_linking = Text()
#     mesh_headings = Json()
# 
#     # Journal
# 
#     journal_issn = Text()
#     journal_title = Text()
#     journal_iso = Text()
# 
#     # Article
# 
#     article_title = Text()
#     article_abstract = Text()
#     article_authors = Array()
#     article_language = Text()
#     article_publication_type_list = Array()
#     article_vernacular_title = Text()
#     article_date = Date('%Y-%m-%d')
# 
#     # Pubmed
# 
#     publication_status = Text()
#     article_ids = Json()
#     registry_ids = Json()


import xmltodict
from dateutil.parser import parse as date_parse
from .record import Record
        data['article_publication_type_list'] = []
        elem = article['PublicationTypeList']['PublicationType']
        if not isinstance(elem, list):
            elem = [elem]
        for sumelem in elem:
            data['article_publication_type_list'].append(sumelem['#text'])
    if article.get('VernacularTitle'):
        data['article_vernacular_title'] = article['VernacularTitle']['#text']
    if 'ArticleDate' in article:
        article_date = '{year}-{month}-{day}'.format(
            year=article['ArticleDate']['Year']['#text'],
            month=article['ArticleDate']['Month']['#text'],
            day=article['ArticleDate']['Day']['#text'])
        article_date = date_parse(article_date)
        data['article_date'] = article_date.strftime('%Y-%m-%d')

    # Pubmed

    if 'PublicationStatus' in pubmed:
        data['publication_status'] = pubmed['PublicationStatus']['#text']
    if 'ArticleIdList' in pubmed:
        data['article_ids'] = {}
        items = pubmed['ArticleIdList']['ArticleId']
        if not isinstance(items, list):
            items = [items]
        for item in items:
            data['article_ids'][item['@IdType']] = item['#text']

    # Create record
    url = 'http://www.ncbi.nlm.nih.gov/pubmed/%s' % data['pmid']

# Path: collectors/pubmed/record.py
# class Record(base.Record):
# 
#     # Config
# 
#     table = 'pubmed'
# 
#     # Medline
# 
#     pmid = Text(primary_key=True)
#     date_created = Date('%Y-%m-%d')
#     date_completed = Date('%Y-%m-%d')
#     date_revised = Date('%Y-%m-%d')
#     country = Text()
#     medline_ta = Text()
#     nlm_unique_id = Text()
#     issn_linking = Text()
#     mesh_headings = Json()
# 
#     # Journal
# 
#     journal_issn = Text()
#     journal_title = Text()
#     journal_iso = Text()
# 
#     # Article
# 
#     article_title = Text()
#     article_abstract = Text()
#     article_authors = Array()
#     article_language = Text()
#     article_publication_type_list = Array()
#     article_vernacular_title = Text()
#     article_date = Date('%Y-%m-%d')
# 
#     # Pubmed
# 
#     publication_status = Text()
#     article_ids = Json()
#     registry_ids = Json()


# Path: collectors/pubmed/parser.py
import xmltodict
from dateutil.parser import parse as date_parse
from .record import Record

        data['article_publication_type_list'] = []
        elem = article['PublicationTypeList']['PublicationType']
        if not isinstance(elem, list):
            elem = [elem]
        for sumelem in elem:
            data['article_publication_type_list'].append(sumelem['#text'])
    if article.get('VernacularTitle'):
        data['article_vernacular_title'] = article['VernacularTitle']['#text']
    if 'ArticleDate' in article:
        article_date = '{year}-{month}-{day}'.format(
            year=article['ArticleDate']['Year']['#text'],
            month=article['ArticleDate']['Month']['#text'],
            day=article['ArticleDate']['Day']['#text'])
        article_date = date_parse(article_date)
        data['article_date'] = article_date.strftime('%Y-%m-%d')

    # Pubmed

    if 'PublicationStatus' in pubmed:
        data['publication_status'] = pubmed['PublicationStatus']['#text']
    if 'ArticleIdList' in pubmed:
        data['article_ids'] = {}
        items = pubmed['ArticleIdList']['ArticleId']
        if not isinstance(items, list):
            items = [items]
        for item in items:
            data['article_ids'][item['@IdType']] = item['#text']

    # Create record
    url = 'http://www.ncbi.nlm.nih.gov/pubmed/%s' % data['pmid']

    record = Record.create(url, data)