Wednesday, 12 September 2012

Sample Webservice Implementation

.h File

@interface DetailViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>
{
    
    
    IBOutlet UIDatePicker *datepicker;
    IBOutlet UIDatePicker *datepicker1;
    
    IBOutlet UIButton *btn;
    
    IBOutlet UIButton *date1;
    IBOutlet UIButton *date2;
    
    IBOutlet UITextField *schedule;
    IBOutlet UITextField *reason;
    IBOutlet UITextField *approxdate2;
    IBOutlet UITextField *PhyType;
    IBOutlet UITextField *PhyName;
    
    NSString *schedule1;
    NSString *reason1;
    NSString *approxdate1;
    NSString *PhyType1;
    NSString *PhyName1;
    
    IBOutlet UIAlertView *alert;
    
    NSMutableData *webData;
    NSMutableString *soapResults;
    NSXMLParser *xmlParser;
    BOOL *recordResults;
    
    IBOutlet UIButton *PhysicianTypeList;
    IBOutlet UIButton *PhysicianNameList;
    
    NSString *string;
    
    NSString *PatID;
    
    NSMutableString *capturedCharacters ;
    
    NSURLConnection *conn;
    NSString * qelementName;
    NSString * RequestStep;
    
    NSMutableArray *ArrayTypeList;
    NSMutableArray *NameList;
    NSMutableArray *IDList;
    NSMutableArray *ClinicList;
    
    IBOutlet UITableView *table1;
    IBOutlet UITableView *table2;
}

@property(nonatomic,retain)IBOutlet UIAlertView *alert;

@property(nonatomic,retain)IBOutlet NSString *parsedString;

@property(nonatomic,retain)NSString *string;

@property(nonatomic,retain)IBOutlet UITableView *table1;
@property(nonatomic,retain)IBOutlet UITableView *table2;

@property(nonatomic,retain)IBOutlet UIButton *PhysicianTypeList;
@property(nonatomic,retain)IBOutlet UIButton *PhysicianNameList;

@property(nonatomic,retain)NSString *PatID;
@property(nonatomic,retain)NSString *schedule1;
@property(nonatomic,retain)NSString *reason1;
@property(nonatomic,retain)NSString *approxdate1;
@property(nonatomic,retain)NSString *PhyType1;
@property(nonatomic,retain)NSString *PhyName1;

@property (retain, nonatomic) id detailItem;

@property(nonatomic,retain) IBOutlet UIDatePicker *datepicker;

@property(nonatomic,retain) IBOutlet UIDatePicker *datepicker1;

@property(nonatomic,retain) IBOutlet UITextField *schedule;

@property(nonatomic,retain) IBOutlet UITextField *reason;

@property(nonatomic,retain) IBOutlet UITextField *approxdate2;

@property(nonatomic,retain) IBOutlet UITextField *PhyType;

@property(nonatomic,retain) IBOutlet UITextField *PhyName;


@property (retain, nonatomic) IBOutlet UILabel *detailDescriptionLabel;

-(IBAction)btn:(id)sender;
-(IBAction)displaydate:(id)sender;
-(IBAction)displaydate1:(id)sender;
-(IBAction)pickerdate:(id)sender;
-(IBAction)pickerdate1:(id)sender;

-(IBAction)PhysicianType:(id)sender;
-(IBAction)PhysicianName:(id)sender;

@end


.m File

#import "DetailViewController.h"
#import "patientdetails.h"
#import "GANTracker.h"

@interface DetailViewController ()
- (void)configureView;
@end

@implementation DetailViewController

@synthesize detailItem ;
@synthesize detailDescriptionLabel,datepicker,datepicker1;
@synthesize schedule,reason,PhyName,PhyType,approxdate2;
@synthesize schedule1,reason1,PhyType1,PhyName1,approxdate1;
@synthesize alert,PatID;
@synthesize PhysicianNameList,PhysicianTypeList;
@synthesize string;
@synthesize parsedString;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        self = [super initWithNibName:@"DetailViewController_iPad" bundle:nibBundleOrNil];
        if (self
        {
            self.title = NSLocalizedString(@"Admission", @"Admission");
        }
    }
    else
    {
        self = [super initWithNibName:@"DetailViewController_iPhone" bundle:nibBundleOrNil];
        self.title = NSLocalizedString(@"Admission", @"Admission");
        
    }
    return self;
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField 
{
    [schedule resignFirstResponder];
    [reason resignFirstResponder];
    [PhyType resignFirstResponder];
    [PhyName resignFirstResponder];
    [approxdate2 resignFirstResponder];
return YES;
}

- (void)dealloc
{
    [detailItem release];
    [detailDescriptionLabel release];
    [super dealloc];
}

#pragma mark - Managing the detail item

- (void)setDetailItem:(id)newDetailItem
{
    if (detailItem != newDetailItem) {
        [detailItem release]; 
        detailItem = [newDetailItem retain]; 
        [self configureView];
    }

          
}

- (void)configureView
{
        if (self.detailItem) {
        self.detailDescriptionLabel.text = [self.detailItem description];
    }
}



-(IBAction)pickerdate:(id)sender
{
    datepicker.hidden=NO;
    [datepicker becomeFirstResponder];
}


-(IBAction)pickerdate1:(id)sender
{
    datepicker1.hidden=NO;
    [datepicker1 becomeFirstResponder];
}


-(IBAction)displaydate:(id)sender;
{
    NSDateFormatter *dt1=[[NSDateFormatter alloc]init];
    [dt1 setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dt1 setDateStyle:NSDateFormatterMediumStyle];
    [dt1 setDateFormat:@"yyyy-MM-dd"];
    schedule.text=[NSString stringWithFormat:@"%@",[dt1 stringFromDate:datepicker.date]];
    datepicker.hidden=YES;
}


-(IBAction)displaydate1:(id)sender;
{
    NSDateFormatter *dt2=[[NSDateFormatter alloc]init];
    [dt2 setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dt2 setDateStyle:NSDateFormatterMediumStyle];
    [dt2 setDateFormat:@"yyyy-MM-dd"];
    approxdate2.text=[NSString stringWithFormat:@"%@",[dt2 stringFromDate:datepicker1.date]];
    datepicker1.hidden=YES;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
   
}


-(IBAction)PhysicianType:(id)sender
{
    string=@"TypeList";
    
    NSString *soapMessage = [NSString stringWithFormat:
                             @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                             "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                             "<soap:Body>\n"
                             "<MedApp_PhyType xmlns=\"http://www.iwedplanner.com/\"/>\n"
                             "</soap:Body>\n"
                             "</soap:Envelope>\n"];
    
    NSLog(soapMessage);
    
    NSURL *url = [NSURL URLWithString:@"http://www.iwedplanner.com/MedicalRecords/MedApp_Physician.asmx?op=MedApp_PhyType"];
    
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
    
    
    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue: @"http://www.iwedplanner.com/MedApp_PhyType" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    
    if( theConnection )
    {
        webData = [[NSMutableData data] retain];
    }
    else
    {
        NSLog(@"theConnection is NULL");
    }
}


-(IBAction)PhysicianName:(id)sender
{
    string=@"NameList";
    
    PhyType1=PhyType.text;
    NSLog(PhyType1);
    if([PhyType.text length]==0)
    {
        
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"First Enter Physician Type"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
        
    }
    else
    {
        NSString *soapMessage = [NSString stringWithFormat:
                                 @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                                 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                                 "<soap:Body>\n"
                                 "<MedApp_PhysTypeDetails xmlns=\"http://www.iwedplanner.com/\">\n"
                                 "<PhyType>%@</PhyType>\n"
                                 "</MedApp_PhysTypeDetails>\n"
                                 "</soap:Body>\n"
                                 "</soap:Envelope>\n",PhyType1];
        
        NSLog(soapMessage);
        
        NSURL *url = [NSURL URLWithString:@"http://www.iwedplanner.com/MedicalRecords/MedApp_Physician.asmx?op=MedApp_PhysTypeDetails"];
        
        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
        
        NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
        
        
        [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
        [theRequest addValue: @"http://www.iwedplanner.com/MedApp_PhysTypeDetails" forHTTPHeaderField:@"SOAPAction"];
        [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
        [theRequest setHTTPMethod:@"POST"];
        [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
        
        NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
        
        if( theConnection )
        {
            webData = [[NSMutableData data] retain];
        }
        else
        {
            NSLog(@"theConnection is NULL");
        }

    }
}


#pragma mark - View lifecycle

- (void)viewDidLoad
{
    ArrayTypeList =[[NSMutableArray alloc]init];
    NameList =[[NSMutableArray alloc]init];
    IDList =[[NSMutableArray alloc]init];
    ClinicList =[[NSMutableArray alloc]init];
    
    
    string=@"Default";
    
    table1.hidden=YES;
    table2.hidden=YES;
    
    NSLog(PatID);
    
    
    self.title=@"PatientDetails";
    schedule.text=@"";
    reason.text=@"";
    approxdate2.text=@"";
    PhyType.text=@"";
    PhyName.text=@"";
   
    
    NSError *error;
    [[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-10190539-28"
  dispatchPeriod:10
delegate:nil];
//NSError *error;
    if (![[GANTracker sharedTracker] trackPageview:@"/MedApp_ApptmtDetails" withError:&error]) {
// Handle error here
}  
    
    UIBarButtonItem *add=[[UIBarButtonItem alloc]initWithTitle:@"Home" style:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(home)];                          self.navigationItem.rightBarButtonItem=add;
    
    
    schedule.placeholder=@"Enter Date";
    datepicker.transform=CGAffineTransformMakeScale(1.0, 1.0);
    datepicker.hidden=YES;
    [datepicker setDatePickerMode:UIDatePickerModeDate];
    approxdate2.placeholder=@"Enter Date";
    datepicker1.transform=CGAffineTransformMakeScale(1.0, 1.0);
    datepicker1.hidden=YES;
    [datepicker1 setDatePickerMode:UIDatePickerModeDate];
    
    schedule.delegate=self;
    reason.delegate=self;
    approxdate2.delegate=self;
    PhyType.delegate=self;
    PhyName.delegate=self;
    
    [super viewDidLoad];
    
    
}

-(void)home
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(IBAction)btn:(id)sender
{
    string=@"Default";

    schedule1=schedule.text;
    reason1=reason.text;
    approxdate1=approxdate2.text;
    PhyType1=PhyType.text;
    PhyName1=PhyName.text;
    
    if([approxdate1 isEqual:@""])
    {
        approxdate1=@"";
    }
    
    NSLog(PatID);
    NSLog(schedule1);
    NSLog(reason1);
    NSLog(approxdate1);
    NSLog(PhyType1);
    NSLog(PhyName1);
    
    if (([schedule.text length]==0) && ([reason.text length]==0) && ([approxdate2.text length]==0) && ([PhyType.text length]==0) && ([PhyName.text length]==0)) 
    {
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Fill Empty Fields"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    else if([schedule.text length]==0)
    {
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Enter Schedule Date"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    
    else if([reason.text length]==0)
    {
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Enter Reason"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    
    else if([approxdate2.text length]==0)
    {
        
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Enter Approximate date on Symptom"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];

    }
    
    else if([PhyType.text length]==0)
    {
        
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Enter Physician Type"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
        
    }
    
    else if([PhyName.text length]==0)
    {
        
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Enter Physician Name"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
        
    }
    
    else
    {
        NSString *soapMessage = [NSString stringWithFormat:
                                 @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                                 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                                 "<soap:Body>\n"
                                 "<MedApp_AdmissionInsert xmlns=\"http://www.iwedplanner.com/\">\n"
                                 "<PatID>%@</PatID>\n"
                                 "<AdmDate>%@</AdmDate>\n"
                                 "<ReasonAdm>%@</ReasonAdm>\n"
                                 "<SymptonsDate>%@</SymptonsDate>\n"
                                 "<PhyID>%@</PhyID>\n"
                                 "</MedApp_AdmissionInsert>\n"
                                 "</soap:Body>\n"
                                 "</soap:Envelope>\n",PatID,schedule1,reason1,approxdate1,PhyName1];
        
        NSLog(soapMessage);
        
        NSURL *url = [NSURL URLWithString:@"http://www.iwedplanner.com/MedicalRecords/MedApp_Admission.asmx?op=MedApp_AdmissionInsert"];
        
        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    
        NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

        
        [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
        [theRequest addValue: @"http://www.iwedplanner.com/MedApp_AdmissionInsert" forHTTPHeaderField:@"SOAPAction"];
        [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
        [theRequest setHTTPMethod:@"POST"];
        [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
        
        NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
        
        if( theConnection )
        {
            webData = [[NSMutableData data] retain];
        }
        else
        {
            NSLog(@"theConnection is NULL");
        }
    }    
}


-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}


-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}


-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
[connection release];
[webData release];
    
}


-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if ([string isEqualToString:@"TypeList"]) 
    {
        NSLog(@" webdate%@",webData);
        NSLog(@"DONE. Received Bytes: %d", [webData length]);
        NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
        NSLog(theXML);
        
        [theXML release];
        
        if( xmlParser )
        {
            [xmlParser release];
        }
        
        xmlParser = [[NSXMLParser alloc] initWithData: webData];
        [xmlParser setDelegate: self];
        [xmlParser setShouldResolveExternalEntities: YES];
        [xmlParser parse];
        
        [connection release];
        [webData release];
    }
    else if ([string isEqualToString:@"NameList"])
    {
        NSLog(@" webdate%@",webData);
        NSLog(@"DONE. Received Bytes: %d", [webData length]);
        NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
        NSLog(theXML);
        
        [theXML release];
        
        if( xmlParser )
        {
            [xmlParser release];
        }
        
        xmlParser = [[NSXMLParser alloc] initWithData: webData];
        [xmlParser setDelegate: self];
        [xmlParser setShouldResolveExternalEntities: YES];
        [xmlParser parse];
        
        [connection release];
        [webData release];
    }
    else
    {
        NSLog(@"DONE. Received Bytes: %d", [webData length]);
        NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
        NSLog(theXML);
        
        NSArray *components1 = [theXML componentsSeparatedByString:@"|"];
        NSString *name1 = [components1 objectAtIndex:1];
        NSLog(name1);
        
        NSArray *components2 = [theXML componentsSeparatedByString:@"|"];
        PatID = [components2 objectAtIndex:2];
        NSLog(PatID);
        
        NSString *name3=[NSString stringWithFormat:@"Details are Sucessfully Saved.Your Patient ID : %@",PatID];
        
        
        
        if ([name1 hasPrefix:@"Pa"]) 
        {
            alert=[[UIAlertView alloc]
                   initWithTitle:@"Message!"
                   message:name3
                   delegate:self
                   cancelButtonTitle:nil
                   otherButtonTitles:@"OK",nil];
            [alert setTag:1];
            [alert show];
            [alert release];
        }
        else
        {
            alert=[[UIAlertView alloc]
                   initWithTitle:@"Message!"
                   message:@"Details are Not Saved"
                   delegate:self
                   cancelButtonTitle:@"OK"
                   otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
        
        [theXML release];
        
        if( xmlParser )
        {
            [xmlParser release];
        }
        
        xmlParser = [[NSXMLParser alloc] initWithData: webData];
        [xmlParser setDelegate: self];
        [xmlParser setShouldResolveExternalEntities: YES];
        [xmlParser parse];
        
        [connection release];
        [webData release];
    }
}

-(void)alertView:(UIAlertView *)objAlert didDismissWithButtonIndex:(NSInteger)buttonIndex 
{
    if([alert tag]==1)
    {
        if (buttonIndex==0)
        {
            /*NSLog(PatID);
            patientdetails *pat=[[patientdetails alloc]init];
            pat.MaternityPatient1=MaternityPatient;
            NSLog([compose objectAtIndex:0]);
            pat.PatID=[compose objectAtIndex:0];
            [self.navigationController pushViewController:pat animated:YES];*/
            
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}


- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict 
{
    if ([elementName isEqualToString:@"Phy_Type"]) 
    {
    
    }
    capturedCharacters = [[NSMutableString alloc] initWithCapacity:50];
    capturedCharacters = [[NSMutableString alloc] initWithCapacity:250];
    
    if ([elementName isEqualToString:@"Name"]) 
    {
        
    }
    capturedCharacters = [[NSMutableString alloc] initWithCapacity:50];
    capturedCharacters = [[NSMutableString alloc] initWithCapacity:250];
    
    if ([elementName isEqualToString:@"ClinicName"]) 
    {
        
    }
    capturedCharacters = [[NSMutableString alloc] initWithCapacity:50];
    capturedCharacters = [[NSMutableString alloc] initWithCapacity:250];
    
    if ([elementName isEqualToString:@"PhyID"]) 
    {
        
    }
    capturedCharacters = [[NSMutableString alloc] initWithCapacity:50];
    capturedCharacters = [[NSMutableString alloc] initWithCapacity:250];
}




- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
{
    
    
    
    if ([elementName isEqualToString:@"Phy_Type"])
    {
        parsedString = capturedCharacters;
        NSLog(@" decription:%@", capturedCharacters);
        [ArrayTypeList addObject:capturedCharacters];
        //PhyType.text=capturedCharacters;
        table1.hidden=NO;
        [table1 reloadData];
    }
    
    if ([elementName isEqualToString:@"Name"])
    {
        parsedString = capturedCharacters;
        NSLog(@" decription:%@", capturedCharacters);
        [NameList addObject:capturedCharacters];
        //PhyType.text=capturedCharacters;
        table2.hidden=NO;
        [table2 reloadData];
    }

    if ([elementName isEqualToString:@"ClinicName"])
    {
        parsedString = capturedCharacters;
        NSLog(@" decription:%@", capturedCharacters);
        [ClinicList addObject:capturedCharacters];
    }

    if ([elementName isEqualToString:@"PhyID"])
    {
        parsedString = capturedCharacters;
        NSLog(@" decription:%@", capturedCharacters);
        [IDList addObject:capturedCharacters];
    }

    
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSMutableString *)string 
{
    if (capturedCharacters != nil
    {
        [capturedCharacters appendString:string];
        
    }
    else 
    {
        [capturedCharacters isEqual:string];
    }
    
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    datepicker.hidden=YES;
    datepicker1.hidden=YES;
    table1.hidden=YES;
    table2.hidden=YES;
    [schedule resignFirstResponder];
    [reason resignFirstResponder];
    [approxdate2 resignFirstResponder];
    [PhyType resignFirstResponder];
    [PhyName resignFirstResponder];
}


-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    datepicker.hidden=YES;
    datepicker1.hidden=YES;
    table1.hidden=YES;
    table2.hidden=YES;
    [schedule resignFirstResponder];
    [reason resignFirstResponder];
    [approxdate2 resignFirstResponder];
    [PhyType resignFirstResponder];
    [PhyName resignFirstResponder];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if(tableView == table1
    {
        return 1;
    }
    else if(tableView == table2
    {
        return 1;
    }    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    #warning Incomplete method implementation.
    // Return the number of rows in the section.
    if (tableView == table1
    {
        return [ArrayTypeList count];
    }
    
    else if (tableView == table2
    {
        return [NameList count];
    }
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Configure the cell.
    
    if(tableView == table1
    {
        cell.textLabel.text = [ArrayTypeList objectAtIndex:indexPath.row];
        
        return cell;
    }
    else if(tableView == table2)
    {
        cell.textLabel.text = [NameList objectAtIndex:indexPath.row];
        
        return cell;
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == table1
    {
        NSString *PhyTypes = [ArrayTypeList objectAtIndex:indexPath.row];
        PhyType.text=PhyTypes;
        table1.hidden=YES;
    }
    
    else if (tableView == table2
    {
        NSString *PhyNames = [NameList objectAtIndex:indexPath.row];
        PhyName.text=PhyNames;
        NSLog([IDList objectAtIndex:indexPath.row]);
        PatID=[IDList objectAtIndex:indexPath.row];
        table2.hidden=YES;
    }
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    
         return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

@end



Build and Run the Application:

Click the PhysicianType ---> PhysicianTypeList is Loaded into Tableview --> table1

Click the PhysicianName ---> PhysicianNameList is Loaded into Tableview --> table2

Finnaly Click the Finish Button ---> save the all TextFields[except PhysicianTypeList,PhysicianName]              & PatID(Patient ID) is Saved.
                          The Field replaced in PhyID(Physician ID) is saved into url.

No comments: