-
Notifications
You must be signed in to change notification settings - Fork 2
/
MLPatientSheetController.m
688 lines (594 loc) · 21.7 KB
/
MLPatientSheetController.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
/*
Copyright (c) 2017 Max Lungarella <cybrmx@gmail.com>
Created on 21/06/2017.
This file is part of AmiKo for OSX.
AmiKo for OSX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------ */
#import "MLPatientSheetController.h"
#import "MLPatientSheetController+smartCard.h"
#import "MLPersistenceManager.h"
#import "LegacyPatientDBAdapter.h"
#import "MLContacts.h"
#import "MLColors.h"
#import "MLUtilities.h"
@interface MLPatientSheetController () <NSFetchedResultsControllerDelegate>
@property (nonatomic, strong) NSFetchedResultsController *resultsController;
@end
@implementation MLPatientSheetController
{
@private
MLPatient *mSelectedPatient;
NSModalSession mModalSession;
NSArray *mArrayOfPatients;
NSMutableArray *mFilteredArrayOfPatients;
NSString *mPatientUUID;
BOOL mABContactsVisible; // These are the contacts in the address book
BOOL mSearchFiltered;
BOOL mFemale;
}
@synthesize mPanel;
- (id) init
{
if (self = [super init]) {
mArrayOfPatients = [[NSArray alloc] init];;
mFilteredArrayOfPatients = [[NSMutableArray alloc] init];
mSearchFiltered = FALSE;
mPatientUUID = nil;
mABContactsVisible = FALSE;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(controlTextDidChange:)
name:NSControlTextDidChangeNotification
object:nil];
self.resultsController = [[MLPersistenceManager shared] resultsControllerForAllPatients];
self.resultsController.delegate = self;
[self.resultsController performFetch:nil];
}
return self;
}
- (void) show:(NSWindow *)window
{
if (!mPanel) {
[NSBundle loadNibNamed:@"MLAmiKoPatientSheet" owner:self];
// Set formatters
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[mWeight_kg setFormatter:formatter];
[mHeight_cm setFormatter:formatter];
}
[NSApp beginSheet:mPanel modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
// Show the dialog
[mPanel makeKeyAndOrderFront:self];
// Start modal session
mModalSession = [NSApp beginModalSessionForWindow:mPanel];
[NSApp runModalSession:mModalSession];
// Retrieves contacts from local patient database
[self updateAmiKoAddressBookTableView];
[mNotification setStringValue:@""];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(newHealthCardData:)
name:@"smartCardDataAcquired"
object:nil];
}
- (void) remove
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:@"smartCardDataAcquired"
object:nil];
[NSApp endModalSession:mModalSession];
[NSApp endSheet:mPanel];
[mPanel orderOut:nil];
[mPanel close];
}
#pragma mark -
- (BOOL) stringIsNilOrEmpty:(NSString*)str
{
return !(str && str.length);
}
- (void) resetFieldsColors
{
mFamilyName.backgroundColor = [NSColor clearColor];
mGivenName.backgroundColor = [NSColor clearColor];
mBirthDate.backgroundColor = [NSColor clearColor];
mPostalAddress.backgroundColor = [NSColor clearColor];
mCity.backgroundColor = [NSColor clearColor];
mZipCode.backgroundColor = [NSColor clearColor];
mInsuranceGLN.backgroundColor = [NSColor clearColor];
}
- (void) checkFields
{
[self resetFieldsColors];
if ([self stringIsNilOrEmpty:[mFamilyName stringValue]]) {
mFamilyName.backgroundColor = [NSColor lightRed];
}
if ([self stringIsNilOrEmpty:[mGivenName stringValue]]) {
mGivenName.backgroundColor = [NSColor lightRed];
}
if ([self stringIsNilOrEmpty:[mBirthDate stringValue]] || ![self validateBirthdayString:[mBirthDate stringValue]]) {
mBirthDate.backgroundColor = [NSColor lightRed];
}
if ([self stringIsNilOrEmpty:[mPostalAddress stringValue]]) {
mPostalAddress.backgroundColor = [NSColor lightRed];
}
if ([self stringIsNilOrEmpty:[mCity stringValue]]) {
mCity.backgroundColor = [NSColor lightRed];
}
if ([self stringIsNilOrEmpty:[mZipCode stringValue]]) {
mZipCode.backgroundColor = [NSColor lightRed];
}
if (![self stringIsNilOrEmpty:[mInsuranceGLN stringValue]] && [[mInsuranceGLN stringValue] length] != 13) {
mInsuranceGLN.backgroundColor = [NSColor lightRed];
}
}
- (void) resetAllFields
{
[self resetFieldsColors];
[mFamilyName setStringValue:@""];
[mGivenName setStringValue:@""];
[mBirthDate setStringValue:@""];
[mCity setStringValue:@""];
[mZipCode setStringValue:@""];
[mWeight_kg setStringValue:@""];
[mHeight_cm setStringValue:@""];
[mPostalAddress setStringValue:@""];
[mZipCode setStringValue:@""];
[mCity setStringValue:@""];
[mCountry setStringValue:@""];
[mPhone setStringValue:@""];
[mEmail setStringValue:@""];
[mFemaleButton setState:NSOnState];
[mMaleButton setState:NSOffState];
[mBagNumber setStringValue:@""];
[mCardNumber setStringValue:@""];
[mInsuranceGLN setStringValue:@""];
mPatientUUID = nil;
[mNotification setStringValue:@""];
}
- (void) setAllFields:(MLPatient *)p
{
if (p.familyName!=nil)
[mFamilyName setStringValue:p.familyName];
if (p.givenName!=nil)
[mGivenName setStringValue:p.givenName];
if (p.birthDate!=nil)
[mBirthDate setStringValue:p.birthDate];
if (p.city!=nil)
[mCity setStringValue:p.city];
if (p.zipCode!=nil)
[mZipCode setStringValue:p.zipCode];
if (p.weightKg>0)
[mWeight_kg setStringValue:[NSString stringWithFormat:@"%d", p.weightKg]];
if (p.heightCm>0)
[mHeight_cm setStringValue:[NSString stringWithFormat:@"%d", p.heightCm]];
if (p.phoneNumber!=nil)
[mPhone setStringValue:p.phoneNumber];
if (p.country!=nil)
[mCity setStringValue:p.city];
if (p.country!=nil)
[mCountry setStringValue:p.country];
if (p.postalAddress!=nil)
[mPostalAddress setStringValue:p.postalAddress];
if (p.emailAddress!=nil)
[mEmail setStringValue:p.emailAddress];
if (p.phoneNumber!=nil)
[mPhone setStringValue:p.phoneNumber];
if (p.uniqueId!=nil)
mPatientUUID = p.uniqueId;
if (p.gender!=nil) {
if ([p.gender isEqualToString:@"woman"]) {
mFemale = TRUE;
[mFemaleButton setState:NSOnState];
[mMaleButton setState:NSOffState];
} else {
mFemale = FALSE;
[mFemaleButton setState:NSOffState];
[mMaleButton setState:NSOnState];
}
}
if (p.bagNumber != nil) {
[mBagNumber setStringValue:p.bagNumber];
}
if (p.healthCardNumber != nil) {
[mCardNumber setStringValue:p.healthCardNumber];
}
if (p.healthCardExpiry != nil) {
[mCardExpiry setStringValue:p.healthCardExpiry];
}
NSString *gln = [p findParticipantGLN];
if ([gln length]) {
[mInsuranceGLN setStringValue:gln];
}
}
- (MLPatient *) getAllFields
{
MLPatient *patient = [[MLPatient alloc] init];
patient.familyName = [mFamilyName stringValue];
patient.givenName = [mGivenName stringValue];
patient.birthDate = [mBirthDate stringValue];
patient.city = [mCity stringValue];
patient.zipCode = [mZipCode stringValue];
patient.postalAddress = [mPostalAddress stringValue];
patient.weightKg = [mWeight_kg intValue];
patient.heightCm = [mHeight_cm intValue];
patient.country = [mCountry stringValue];
patient.phoneNumber = [mPhone stringValue];
patient.emailAddress = [mEmail stringValue];
patient.gender = [mFemaleButton state]==NSOnState ? @"woman" : @"man";
patient.bagNumber = [mBagNumber stringValue];
patient.healthCardNumber = [mCardNumber stringValue];
patient.healthCardExpiry = [mCardExpiry stringValue];
patient.insuranceGLN = [mInsuranceGLN stringValue];
return patient;
}
- (void) friendlyNote
{
[mNotification setStringValue:[NSString stringWithFormat:NSLocalizedString(@"The contact was saved in the %@ address book", nil), [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]]];
}
- (void) addPatient:(MLPatient *)patient
{
mSelectedPatient = patient;
mPatientUUID = [[MLPersistenceManager shared] addPatient:patient];
mSearchFiltered = FALSE;
[mSearchKey setStringValue:@""];
[self updateAmiKoAddressBookTableView];
[self friendlyNote];
}
- (void) setSelectedPatient:(MLPatient *)patient
{
mSelectedPatient = patient;
}
- (MLPatient *) retrievePatient
{
return mSelectedPatient;
}
- (MLPatient *) retrievePatientWithUniqueID:(NSString *)uniqueID
{
return [[MLPersistenceManager shared] getPatientWithUniqueID:uniqueID];
}
- (BOOL) patientExistsWithID:(NSString *)uniqueID
{
MLPatient *p = [self retrievePatientWithUniqueID:uniqueID];
return p!=nil;
}
- (NSString *) retrievePatientAsString
{
if (mSelectedPatient)
return [mSelectedPatient asString];
return @"";
}
- (NSString *) retrievePatientAsString:(NSString *)searchKey
{
NSString *p = @"";
// Retrieves first best match from patient sqlite database
mArrayOfPatients = [[MLPersistenceManager shared] searchPatientsWithKeyword:searchKey];
if ([mArrayOfPatients count]>0) {
MLPatient *r = [mArrayOfPatients objectAtIndex:0];
return [r asString];
}
return p;
}
- (BOOL) validateFields:(MLPatient *)patient
{
BOOL valid = TRUE;
[self resetFieldsColors];
if ([self stringIsNilOrEmpty:patient.familyName]) {
mFamilyName.backgroundColor = [NSColor lightRed];
valid = FALSE;
}
if ([self stringIsNilOrEmpty:patient.givenName]) {
mGivenName.backgroundColor = [NSColor lightRed];
valid = FALSE;
}
if ([self stringIsNilOrEmpty:patient.birthDate] || ![self validateBirthdayString:patient.birthDate]) {
mBirthDate.backgroundColor = [NSColor lightRed];
valid = FALSE;
}
if ([self stringIsNilOrEmpty:patient.postalAddress]) {
mPostalAddress.backgroundColor = [NSColor lightRed];
valid = FALSE;
}
if ([self stringIsNilOrEmpty:patient.city]) {
mCity.backgroundColor = [NSColor lightRed];
valid = FALSE;
}
if ([self stringIsNilOrEmpty:patient.zipCode]) {
mZipCode.backgroundColor = [NSColor lightRed];
valid = FALSE;
}
return valid;
}
- (BOOL)validateBirthdayString:(NSString*)string {
if ([string containsString:@" "]) {
return NO;
}
NSArray<NSString*> *parts = [string componentsSeparatedByString:@"."];
if ([parts count] != 3) {
return NO;
}
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSString *dayString = parts[0];
NSString *monthString = parts[1];
NSString *yearString = parts[2];
NSNumber *dayNum = [formatter numberFromString:dayString];
if (dayNum == nil || [dayNum intValue] <= 0 || [dayNum intValue] > 31) {
return NO;
}
NSNumber *monthNum = [formatter numberFromString:monthString];
if (monthNum == nil || [monthNum intValue] <= 0 || [monthNum intValue] > 12) {
return NO;
}
NSNumber *yearNum = [formatter numberFromString:yearString];
if (yearNum == nil || [yearString length] != 4) {
return NO;
}
return YES;
}
- (void) updateAmiKoAddressBookTableView
{
mArrayOfPatients = [[MLPersistenceManager shared] getAllPatients];
mABContactsVisible=NO;
[mTableView reloadData];
[self setNumPatients:[mArrayOfPatients count]];
}
#pragma mark - Notifications
// NSControlTextDidChangeNotification
- (void) controlTextDidChange:(NSNotification *)notification {
/*
NSTextField *textField = [notification object];
if (textField==mFamilyName)
NSLog(@"%@", [textField stringValue]);
*/
[self checkFields];
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
dispatch_async(dispatch_get_main_queue(), ^{
[self updateAmiKoAddressBookTableView];
MLPatient *p = [[MLPersistenceManager shared] getPatientWithUniqueID:mPatientUUID];
[self resetAllFields];
[self setAllFields:p];
});
}
#pragma mark - Actions
- (IBAction) onSearchDatabase:(id)sender
{
NSString *searchKey = [mSearchKey stringValue];
[mFilteredArrayOfPatients removeAllObjects];
if (![self stringIsNilOrEmpty:searchKey]) {
for (MLPatient *p in mArrayOfPatients) {
NSString *searchKeyLower = [searchKey lowercaseString];
if ([[p.familyName lowercaseString] hasPrefix:searchKeyLower] || [[p.givenName lowercaseString] hasPrefix:searchKeyLower] ||
[[p.postalAddress lowercaseString] hasPrefix:searchKeyLower] || [p.zipCode hasPrefix:searchKeyLower]) {
[mFilteredArrayOfPatients addObject:p];
}
}
}
if (mFilteredArrayOfPatients!=nil) {
if ([mFilteredArrayOfPatients count]>0) {
[self setNumPatients:[mFilteredArrayOfPatients count]];
mSearchFiltered = TRUE;
} else {
if ([searchKey length]>0) {
[self setNumPatients:0];
mSearchFiltered = TRUE;
} else {
[self setNumPatients:[mArrayOfPatients count]];
mSearchFiltered = FALSE;
}
}
} else {
[self setNumPatients:[mArrayOfPatients count]];
mSearchFiltered = FALSE;
}
[mTableView reloadData];
}
- (IBAction) onSelectFemale:(id)sender
{
if ([sender isKindOfClass:[NSButton class]]) {
mFemale = TRUE;
[mFemaleButton setState:NSOnState];
[mMaleButton setState:NSOffState];
}
}
- (IBAction) onSelectMale:(id)sender
{
if ([sender isKindOfClass:[NSButton class]]) {
mFemale = FALSE;
[mFemaleButton setState:NSOffState];
[mMaleButton setState:NSOnState];
}
}
- (IBAction) onCancel:(id)sender
{
[self remove];
}
- (IBAction) onSavePatient:(id)sender
{
MLPatient *patient = [self getAllFields];
if (![self validateFields:patient]) {
return;
}
if (mPatientUUID!=nil && [mPatientUUID length]>0) {
patient.uniqueId = mPatientUUID;
}
if ([[MLPersistenceManager shared] getPatientWithUniqueID:mPatientUUID]==nil) {
mPatientUUID = [[MLPersistenceManager shared] addPatient:patient];
}
else {
mPatientUUID = [[MLPersistenceManager shared] upsertPatient:patient];
}
mSearchFiltered = FALSE;
[mSearchKey setStringValue:@""];
[self updateAmiKoAddressBookTableView];
[self friendlyNote];
}
- (IBAction) onNewPatient:(id)sender
{
[self resetAllFields];
[self updateAmiKoAddressBookTableView];
}
- (IBAction) onDeletePatient:(id)sender
{
NSInteger row = [mTableView selectedRow];
if (row == -1) return;
if (mABContactsVisible==NO) {
MLPatient *p = nil;
if (mSearchFiltered) {
p = mFilteredArrayOfPatients[row];
}
else {
p = mArrayOfPatients[row];
}
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Cancel"];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:NSLocalizedString(@"Delete contact?", nil)];
[alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to delete this contact from the %@ Address Book?", nil), [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]]];
[alert setAlertStyle:NSAlertStyleInformational];
__weak typeof(self) _self = self;
[alert beginSheetModalForWindow:[self window] completionHandler:^(NSModalResponse returnCode) {
[_self alertDidEnd:alert returnCode:returnCode contextInfo:p];
}];
}
}
- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(MLPatient *)contextInfo
{
if (returnCode==NSAlertSecondButtonReturn) {
MLPatient *p = contextInfo;
if ([[MLPersistenceManager shared] deletePatient:p]) {
[self resetAllFields];
[self updateAmiKoAddressBookTableView];
[mNotification setStringValue:[NSString stringWithFormat:NSLocalizedString(@"The contact has been removed from the %@ Address Book", nil), [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"MLPrescriptionPatientDeleted" object:self];
}
}
}
- (IBAction) onShowContacts:(id)sender
{
[self resetAllFields];
mSearchFiltered = FALSE;
[mSearchKey setStringValue:@""];
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
if (![CNContactStore class]) {
return;
}
if (mABContactsVisible==NO) {
CNContactStore *addressBook = [[CNContactStore alloc] init];
if (status != CNAuthorizationStatusAuthorized) {
[addressBook requestAccessForEntityType:CNEntityTypeContacts
completionHandler:^(BOOL granted, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
[[NSAlert alertWithError:error] runModal];
}
if (granted) {
[self onShowContacts:sender];
}
});
}];
} else {
// Need to be in background queue because it may be slow to takes contacts
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0) , ^{
MLContacts *contacts = [[MLContacts alloc] init];
// Retrieves contacts from address book
mArrayOfPatients = [contacts getAllContacts];
dispatch_async(dispatch_get_main_queue(), ^{
[mTableView reloadData];
mABContactsVisible = YES;
[self setNumPatients:[mArrayOfPatients count]];
});
});
}
}
else {
// Retrieves contacts from local patient database
[self updateAmiKoAddressBookTableView];
}
}
// Double clicked a patient in the table view
- (IBAction) onSelectPatient:(id)sender
{
NSInteger row = [mTableView selectedRow];
mSelectedPatient = nil;
if (mSearchFiltered) {
mSelectedPatient = mFilteredArrayOfPatients[row];
}
else {
mSelectedPatient = mArrayOfPatients[row];
}
if (mSelectedPatient) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"MLPrescriptionPatientChanged" object:self];
}
[self remove];
}
- (void) setNumPatients:(NSInteger)numPatients
{
if (mABContactsVisible) {
[mNumPatients setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Address Book Mac (%ld)", nil), numPatients]];
}
else {
[mNumPatients setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Address Book App", nil),
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"],
numPatients]];
}
}
- (MLPatient *) getContactAtRow:(NSInteger)row
{
if (mSearchFiltered)
return mFilteredArrayOfPatients[row];
if (mArrayOfPatients!=nil)
return mArrayOfPatients[row];
return nil;
}
/**
- NSTableViewDataSource -
*/
- (NSInteger) numberOfRowsInTableView: (NSTableView *)tableView
{
if (mSearchFiltered)
return [mFilteredArrayOfPatients count];
if (mArrayOfPatients!=nil)
return [mArrayOfPatients count];
return 0;
}
/**
- NSTableViewDataDelegate -
*/
- (NSView *) tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSTableCellView *cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
MLPatient *p = [self getContactAtRow:row];
if (p!=nil) {
NSString *cellStr = [NSString stringWithFormat:@"%@ %@", p.familyName, p.givenName];
cellView.textField.stringValue = cellStr;
if (p.databaseType==eAddressBook) {
cellView.textField.textColor = [NSColor grayColor];
} else {
cellView.textField.textColor = [NSColor textColor];
}
return cellView;
}
return nil;
}
- (void) tableViewSelectionDidChange: (NSNotification *)notification
{
if ([notification object] == mTableView) {
NSInteger row = [[notification object] selectedRow];
if (row < 0) return;
NSTableRowView *rowView = [mTableView rowViewAtRow:row makeIfNecessary:NO];
MLPatient *p = [self getContactAtRow:row];
mPatientUUID = p.uniqueId;
[self resetAllFields];
[self setAllFields:p];
[rowView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleRegular];
[mNotification setStringValue:@""];
}
}
@end