-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatListViewController.m
119 lines (73 loc) · 3.32 KB
/
PatListViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// PatListViewController.m
// ProjectZero
//
// Created by Larkin on 12/31/12.
// Copyright (c) 2012 Larkin. All rights reserved.
//
#import "PatListViewController.h"
#import "UserTableCell.h"
#import "PatientProfileViewController.h"
@interface PatListViewController ()
@end
@implementation PatListViewController
@synthesize patList;
@synthesize accessURL;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.patList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *UserTableCellIdentifier = @"UserTableCell";
UserTableCell *cell = [tableView dequeueReusableCellWithIdentifier:UserTableCellIdentifier];
if (cell == nil) {
cell = [[UserTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:UserTableCellIdentifier];
NSLog(@"allocated cell");
}
if ( [[self.patList objectAtIndex:indexPath.row] objectForKey:@"first_name"] != [NSNull null] && [[self.patList objectAtIndex:indexPath.row] objectForKey:@"last_name"] != [NSNull null] ){
cell.name.text = [[[[self.patList objectAtIndex:indexPath.row] objectForKey:@"first_name"] stringByAppendingString:@" " ] stringByAppendingString:[[self.patList objectAtIndex:indexPath.row] objectForKey:@"last_name"]];
}
//cell.name.text = [[self.patList objectAtIndex:indexPath.row] objectForKey:@"first_name"]; //stringByAppendingString:[[self.patList objectAtIndex:indexPath.row] objectForKey:@"last_name"]];
[[self.patList objectAtIndex:indexPath.row] objectForKey:@"name"];
return cell;
}
- (void)viewDidLoad
{
self.accessURL = @"http://default-environment-ntmkc2r9ez.elasticbeanstalk.com/ProjectZero-server/index.php/QRCodeGen/fetchUsers";
NSLog(@"access URL %@", self.accessURL);
NSData* data = [NSData dataWithContentsOfURL: [NSURL URLWithString:self.accessURL]];
NSError* error;
self.patList = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"toProfileSegue"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
PatientProfileViewController *destViewController = (PatientProfileViewController*)segue.destinationViewController;
destViewController.firstName = [[self.patList objectAtIndex:indexPath.row] objectForKey:@"first_name"];
destViewController.lastName = [[self.patList objectAtIndex:indexPath.row] objectForKey:@"last_name"];
destViewController.userID = [[self.patList objectAtIndex:indexPath.row] objectForKey:@"id"];
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end