Skip to content

Commit

Permalink
Merge pull request ResearchKit#7 from EricSiegNW/feature/update_to_br…
Browse files Browse the repository at this point in the history
…idge_v3

Feature/update to bridge v3
  • Loading branch information
Erin-Mounts committed Jul 29, 2015
2 parents 46c6525 + 93ff2ed commit 82a590f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 28 deletions.
20 changes: 10 additions & 10 deletions APCAppCore/APCAppCore/DataSubstrate/Model/APCUser+Bridge.m
Expand Up @@ -91,7 +91,7 @@ - (void) updateProfileOnCompletion:(void (^)(NSError *))completionBlock

profile.firstName = self.name;

[SBBComponent(SBBProfileManager) updateUserProfileWithProfile: profile
[SBBComponent(SBBUserManager) updateUserProfileWithProfile: profile
completion: ^(id __unused responseObject,
NSError *error)
{
Expand Down Expand Up @@ -120,8 +120,8 @@ - (void) updateCustomProfile:(SBBUserProfile*)profile onCompletion:(void (^)(NSE
profile.username = self.email;
profile.firstName = self.name;

[SBBComponent(SBBProfileManager) updateUserProfileWithProfile: profile
completion: ^(id __unused responseObject,
[SBBComponent(SBBUserManager) updateUserProfileWithProfile: profile
completion: ^(id __unused responseObject,
NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^{
Expand All @@ -145,7 +145,7 @@ - (void) getProfileOnCompletion:(void (^)(NSError *))completionBlock
}
else
{
[SBBComponent(SBBProfileManager) getUserProfileWithCompletion:^(id userProfile, NSError *error) {
[SBBComponent(SBBUserManager) getUserProfileWithCompletion:^(id userProfile, NSError *error) {
SBBUserProfile *profile = (SBBUserProfile *)userProfile;
self.email = profile.email;
self.name = profile.firstName;
Expand All @@ -171,7 +171,7 @@ - (void) withdrawStudyOnCompletion:(void (^)(NSError *))completionBlock
}
else
{
[SBBComponent(SBBConsentManager) dataSharing:SBBConsentShareScopeNone completion:^(id __unused responseObject, NSError * __unused error) {
[SBBComponent(SBBUserManager) dataSharing:SBBUserDataSharingScopeNone completion:^(id __unused responseObject, NSError * __unused error) {
[self signOutOnCompletion:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if(!error) {
Expand Down Expand Up @@ -199,7 +199,7 @@ - (void) resumeStudyOnCompletion:(void (^)(NSError *))completionBlock
APCAppDelegate *delegate = (APCAppDelegate*) [UIApplication sharedApplication].delegate;
NSNumber *selected = delegate.dataSubstrate.currentUser.sharedOptionSelection;

[SBBComponent(SBBConsentManager) dataSharing:[selected integerValue] completion:^(id __unused responseObject, NSError *error) {
[SBBComponent(SBBUserManager) dataSharing:[selected integerValue] completion:^(id __unused responseObject, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (!error) {
APCLogEventWithData(kNetworkEvent, (@{@"event_detail":@"User Resumed Consent"}));
Expand Down Expand Up @@ -238,12 +238,12 @@ - (void)signInOnCompletion:(void (^)(NSError *))completionBlock
if (dataSharing.integerValue == 1) {
NSString *scope = responseDictionary[@"sharingScope"];
if ([scope isEqualToString:@"sponsors_and_partners"]) {
self.sharedOptionSelection = @(SBBConsentShareScopeStudy);
self.sharedOptionSelection = @(SBBUserDataSharingScopeStudy);
} else if ([scope isEqualToString:@"all_qualified_researchers"]) {
self.sharedOptionSelection = @(SBBConsentShareScopeAll);
self.sharedOptionSelection = @(SBBUserDataSharingScopeAll);
}
} else if (dataSharing.integerValue == 0) {
self.sharedOptionSelection = @(SBBConsentShareScopeNone);
self.sharedOptionSelection = @(SBBUserDataSharingScopeNone);
}
}
APCLogEventWithData(kNetworkEvent, (@{@"event_detail":@"User Signed In"}));
Expand Down Expand Up @@ -388,7 +388,7 @@ - (void)changeDataSharingTypeOnCompletion:(void (^)(NSError *))completionBlock
{
NSNumber *selected = self.sharedOptionSelection;

[SBBComponent(SBBConsentManager) dataSharing:[selected integerValue] completion:^(id __unused responseObject, NSError *error) {
[SBBComponent(SBBUserManager) dataSharing:[selected integerValue] completion:^(id __unused responseObject, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (!error) {
switch (selected.integerValue) {
Expand Down
Expand Up @@ -94,6 +94,10 @@ Controls whether we compute and show (very) detailed debugging
static NSString * const APCErrorSavingEverythingReason = @"Error Saving New Schedules";
static NSString * const APCErrorSavingEverythingSuggestion = @"There was an error attempting to save the new schedules.";

/**
JSON Mapping files
*/
static NSString * const kTaskIdToViewControllerMappingJSON = @"APHTaskIdToViewControllerMapping";

/**
Keys and special values in the JSON dictionaries representing
Expand Down Expand Up @@ -976,27 +980,61 @@ - (NSDictionary *) extractJsonDataFromIncomingSageSchedule: (SBBSchedule *) sage
scheduleData [kScheduleIntervalKey] = null; // [self nullIfNil: sageSchedule.interval];
scheduleData [kScheduleTimesOfDayKey] = null; // [self nullIfNil: sageSchedule.times];
scheduleData [kScheduleMaxCountKey] = null; // [self nullIfNil: sageSchedule.maxCount];


// Set up TaskId->TaskViewController dictionary
NSString *filePath = [[NSBundle mainBundle] pathForResource:kTaskIdToViewControllerMappingJSON ofType:@"json"];
NSString *JSONString = [[NSString alloc] initWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding
error:NULL];

NSError *parseError;
NSDictionary *mappingDictionary = [NSJSONSerialization JSONObjectWithData:[JSONString dataUsingEncoding:NSUTF8StringEncoding]
options:NSJSONReadingMutableContainers
error:&parseError];
NSAssert(mappingDictionary != nil, @"ERROR trouble parsing taskId -> view controller mapping file", parseError);

for (SBBActivity *activity in sageSchedule.activities)
{
NSMutableDictionary *activityData = [NSMutableDictionary new];

activityData [kTaskTitleKey] = [self nullIfNil: activity.label];
activityData [kTaskTypeKey] = [self nullIfNil: activity.activityType];
activityData [kTaskIDKey] = [self nullIfNil: activity.survey.guid];
activityData [kTaskVersionNumberKey] = [self nullIfNil: activity.survey.version];
activityData [kTaskUrlKey] = [self nullIfNil: activity.ref];
activityData [kTaskClassNameKey] = NSStringFromClass ([APCGenericSurveyTaskViewController class]);

// When we start getting these from Sage, we'll use them.
// In the mean time, noting them here, because we're using
// them from our local disk files.
activityData [kTaskCompletionTimeStringKey] = null;
activityData [kTaskFileNameKey] = null;
activityData [kTaskSortStringKey] = null;

[activities addObject: activityData];
if (activity.survey) {
NSMutableDictionary *activityData = [NSMutableDictionary new];

activityData [kTaskTitleKey] = [self nullIfNil: activity.label];
activityData [kTaskCompletionTimeStringKey] = [self nullIfNil: activity.labelDetail];
activityData [kTaskTypeKey] = [self nullIfNil: activity.activityType];
activityData [kTaskIDKey] = [self nullIfNil: activity.survey.identifier];
activityData [kTaskVersionNumberKey] = [self nullIfNil: activity.survey.createdOn.toStringInISO8601Format];
activityData [kTaskUrlKey] = [self nullIfNil: activity.survey.href];
activityData [kTaskClassNameKey] = NSStringFromClass ([APCGenericSurveyTaskViewController class]);

// When we start getting these from Sage, we'll use them.
// In the mean time, noting them here, because we're using
// them from our local disk files.

activityData [kTaskFileNameKey] = null;
activityData [kTaskSortStringKey] = null;

[activities addObject: activityData];
} else if (activity.task) {
NSMutableDictionary *activityData = [NSMutableDictionary new];

activityData [kTaskTitleKey] = [self nullIfNil: activity.label];
activityData [kTaskCompletionTimeStringKey] = [self nullIfNil: activity.labelDetail];
activityData [kTaskTypeKey] = [self nullIfNil: activity.activityType];
activityData [kTaskIDKey] = [self nullIfNil: activity.task.identifier];
activityData [kTaskClassNameKey] = mappingDictionary[activity.task.identifier];

// Not available for non survey tasks
activityData [kTaskVersionNumberKey] = null;
activityData [kTaskUrlKey] = null;

// When we start getting these from Sage, we'll use them.
// In the mean time, noting them here, because we're using
// them from our local disk files.
activityData [kTaskFileNameKey] = null;
activityData [kTaskSortStringKey] = null;

[activities addObject: activityData];
}
}

return scheduleData;
Expand Down

0 comments on commit 82a590f

Please sign in to comment.