import pandas as pd
from .models import drug, pharmacogenes, study, snp				

#populate the drug table
#Note that the id is not supplied for most of the tables since
#it is automatically generated by auto-increment
def populate_drug():
    df = pd.read_csv("/Users/macbook/Desktop/dummy_data/drug.csv")
    #print(df)
    for index, row in df.iterrows():
        drug.objects.update_or_create(drug_name=row['drug_name'],
            posology=row['posology'],
            chemical_structure=row['chemical_structure'],
            drug_bank_id=row['drug_bank_id'],
            state_id=row['state']
            )

def populate_genes():
    df = pd.read_csv("/Users/macbook/Desktop/dummy_data/pharmacogenes.csv")

    for index, row in df.iterrows():
        pharmacogenes.objects.update_or_create(
            id=row['id'],
            gene_name=row['gene_name'],
            protein=row['protein'],
            function=row['function']
            )

#for we are using current dates for the date field of study
def populate_study():
    df = pd.read_csv("/Users/macbook/Desktop/dummy_data/study.csv")
    for index, row in df.iterrows():
        study.objects.update_or_create(
            study_title=row['title'],
            external_id=row['external_id']
            )

#function to populate snp table   
# commented out fields have default values, 
# create fails for foreign key fields (need to figure this out)      
def populate_snp():
    df = pd.read_csv("/Users/macbook/Desktop/dummy_data/snp.csv")
    for index, row in df.iterrows():
        snp.objects.update_or_create(
            rs_id=row['rs_id'],
#            drug_id=row['drug_id'],
            allele=row['allele'],
 #           gene_id=row['gene_id'],
            description=row['description']
  #          reference_id=row['reference_id']
            )
