//
//  SymCheckerTreatmentViewController.m
//  MedicalHelp
//
//  Created by mac on 7/2/14.
//  Copyright (c) 2014 mac. All rights reserved.
//

#import "SymCheckerTreatmentViewController.h"

@implementation SymCheckerTreatmentViewController

@synthesize webViewTAO,htmlString,arrayIndexfkSymptomid,arraypkPCid,arrayTAO,arrayTblTAO,indexpkPCid,taoDiagnosedby,taoOverview,taoRiskfactor,taoTreatment,taoWhattoexcept;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    RequestHandler *req = [[RequestHandler alloc]init];
    
    //Fire query and
    //Recieve Whole table in Array -->Dictonary
    arrayTblTAO = [[NSMutableArray alloc]initWithArray:[req getList: [NSString stringWithFormat:@"select * from TblTreatmentAndOverview inner join tblpossibleconditionforsymptom on TblTreatmentAndOverview.fkpcid = tblpossibleconditionforsymptom.fkpcid inner join tblpossiblecondition on tblpossiblecondition.pkpcid = TblTreatmentAndOverview.fkpcid where tblpossiblecondition.pkpcid = %d",indexpkPCid]]];//indexpkPCid
    
    //Convert Individual Array.Each String Resepresented First Column of Table
    for (NSDictionary *dict in arrayTblTAO) {
        taoOverview = [dict objectForKey:@"Overview"];
        taoWhattoexcept = [dict objectForKey:@"WhatToExcept"];
        taoRiskfactor = [dict objectForKey:@"RiskFactor"];
        taoTreatment = [dict objectForKey:@"TreatMent"];
        taoDiagnosedby = [dict objectForKey:@"DiagnosedBy"];
    }
    
    ////Generate Dynamic WebPage
    NSString *htmlFilePath = [[NSBundle mainBundle]pathForResource:@"htmlFile" ofType:@"html"];
    
    htmlString = [NSMutableString stringWithString:[[NSString alloc]initWithContentsOfFile:htmlFilePath encoding:NSUTF8StringEncoding error:nil]];
    
    htmlString =[NSMutableString stringWithString:[htmlString stringByReplacingOccurrencesOfString:@"overview_hereInsertData" withString:taoOverview]];
    htmlString =[NSMutableString stringWithString:[htmlString stringByReplacingOccurrencesOfString:@"whattoexcept_hereInsertData" withString:taoWhattoexcept]];
    htmlString =[NSMutableString stringWithString:[htmlString stringByReplacingOccurrencesOfString:@"riskfactor_hereInsertData" withString:taoRiskfactor]];
    htmlString =[NSMutableString stringWithString:[htmlString stringByReplacingOccurrencesOfString:@"treatment_hereInsertData" withString:taoTreatment]];
    htmlString =[NSMutableString stringWithString:[htmlString stringByReplacingOccurrencesOfString:@"diagnosedby_hereInsertData" withString:taoDiagnosedby]];
    [webViewTAO loadHTMLString:htmlString baseURL:nil];
    
    //Add bar button item to top
    UIBarButtonItem *btnHome = [[UIBarButtonItem alloc]initWithTitle:@"Home" style:UIBarButtonItemStyleBordered target:self action:@selector(goHome)];
    
    [self.navigationItem setRightBarButtonItem:btnHome];
    
    //and set title
    [self.navigationItem setTitle:@"Report"];
    
    //Add Background
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"wallpaper1.png"]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)goHome
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
@end
