Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@emilevictor
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilevictor/6e01e9c30ce38e9e8a3f to your computer and use it in GitHub Desktop.
Save emilevictor/6e01e9c30ce38e9e8a3f to your computer and use it in GitHub Desktop.
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSInteger adjustedIndex = 0;
if (!_laserEnabled) {
adjustedIndex++;
if (!_pasiEnabled)
adjustedIndex++;
}
else if (!_pasiEnabled && buttonIndex > 0) {
adjustedIndex++;
}
// if (!_laserEnabled && adjustedIndex > 2)
// adjustedIndex++;
// }
switch (buttonIndex + adjustedIndex) {
case 0:
{
TreatmentLaser *newTreatment = [NSEntityDescription insertNewObjectForEntityForName:@"TreatmentLaser" inManagedObjectContext:SCDataManager.app.managedObjectContext];
newTreatment.date = [NSDate date];
newTreatment.patient = _patient;
NSError *error = nil;
// Save the object to persistent store
if (![SCDataManager.app.managedObjectContext save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
return;
}
break;
}
case 1:
{
TreatmentPASI *newTreatment = [NSEntityDescription insertNewObjectForEntityForName:@"TreatmentPASI" inManagedObjectContext:SCDataManager.app.managedObjectContext];
newTreatment.date = [NSDate date];
newTreatment.patient = _patient;
NSError *error = nil;
// Save the object to persistent store
if (![SCDataManager.app.managedObjectContext save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
return;
}
break;
}
case 2:
{
TreatmentSurgery *newTreatment = [NSEntityDescription insertNewObjectForEntityForName:@"TreatmentSurgery" inManagedObjectContext:SCDataManager.app.managedObjectContext];
newTreatment.date = [NSDate date];
newTreatment.patient = _patient;
SurgerySites *surgerySite = [NSEntityDescription insertNewObjectForEntityForName:@"SurgerySites" inManagedObjectContext:SCDataManager.app.managedObjectContext];
surgerySite.treatmentSurgery = newTreatment;
NSError *error = nil;
// Save the object to persistent store
if (![SCDataManager.app.managedObjectContext save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
return;
}
break;
}
default:
break;
}
}
<<<<<<<< snip >>>>>>>>>>
- (IBAction)onClickNewConsultation:(UIButton *)sender {
Consult *newConsult = [NSEntityDescription insertNewObjectForEntityForName:@"Consult" inManagedObjectContext:SCDataManager.app.managedObjectContext];
newConsult.date = [NSDate date];
newConsult.patient = _patient;
ClinicalExam *clinicalExam = [NSEntityDescription insertNewObjectForEntityForName:@"ClinicalExam" inManagedObjectContext:SCDataManager.app.managedObjectContext];
clinicalExam.consult = newConsult;
NSError *error = nil;
// Save the object to persistent store
if (![SCDataManager.app.managedObjectContext save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
return;
}
// [self update];
}
<<<<<<<<<< snip >>>>>>>>>>
#pragma mark - NSFetchedResultsControllerDelegate
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath
{
if (_consultsFRC == controller) {
if (type == NSFetchedResultsChangeInsert) {
[_consultTable insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:newIndexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
[_consultTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:newIndexPath.row inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
[self performSegueWithIdentifier:@"toConsult" sender:self];
}
else if (type == NSFetchedResultsChangeDelete) {
//[_consultTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
else if (_treatmentLasersFRC == controller) {
if (type == NSFetchedResultsChangeInsert) {
[_consultTable insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:newIndexPath.row inSection:1]] withRowAnimation:UITableViewRowAnimationAutomatic];
[_consultTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:newIndexPath.row inSection:1] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
[self performSegueWithIdentifier:@"toTreatmentLaser" sender:self];
}
else if (type == NSFetchedResultsChangeDelete) {
//[_consultTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:1]] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
else if (_treatmentPASIsFRC == controller) {
if (type == NSFetchedResultsChangeInsert) {
[_consultTable insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:newIndexPath.row inSection:2]] withRowAnimation:UITableViewRowAnimationAutomatic];
[_consultTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:newIndexPath.row inSection:2] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
[self performSegueWithIdentifier:@"toTreatmentPASI" sender:self];
}
else if (type == NSFetchedResultsChangeDelete) {
//[_consultTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:2]] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
else if (_treatmentProFormasFRC == controller) {
if (type == NSFetchedResultsChangeInsert) {
[_consultTable insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:newIndexPath.row inSection:3]] withRowAnimation:UITableViewRowAnimationAutomatic];
[_consultTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:newIndexPath.row inSection:3] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
[self performSegueWithIdentifier:@"toTreatmentProForma" sender:self];
}
else if (type == NSFetchedResultsChangeDelete) {
[_consultTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:3]] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
// [self performSegueWithIdentifier:@"toTreatmentLaser" sender:self];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment