Skip to content

Commit

Permalink
Uploading informed consent as participant data + docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
bardram committed Sep 18, 2024
1 parent ea68da9 commit 970e0c7
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 212 deletions.
11 changes: 6 additions & 5 deletions lib/blocs/sensing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ part of carp_study_app;
/// added to the [client].
class Sensing {
static final Sensing _instance = Sensing._();
StudyDeploymentStatus? _status;
// StudyDeploymentStatus? _status;
SmartphoneDeploymentController? _controller;
DeploymentService? deploymentService;
Study? _study;
Expand All @@ -34,7 +34,7 @@ class Sensing {
SmartphoneDeployment? get deployment => _controller?.deployment;

/// The latest status of the study deployment.
StudyDeploymentStatus? get status => _status;
StudyDeploymentStatus? get status => _controller?.deploymentStatus;

/// The role name of this device in the deployed study.
String? get deviceRoleName => _study?.deviceRoleName;
Expand Down Expand Up @@ -113,15 +113,16 @@ class Sensing {

// Deploy this protocol using the on-phone deployment service.
// Reuse the study deployment id, if this is stored on the phone.
_status = await SmartphoneDeploymentService().createStudyDeployment(
final status =
await SmartphoneDeploymentService().createStudyDeployment(
protocol!,
[],
bloc.studyDeploymentId,
);

// Save the correct deployment id on the phone for later use.
bloc.studyDeploymentId = _status?.studyDeploymentId;
bloc.deviceRoleName = _status?.primaryDeviceStatus?.device.roleName;
bloc.studyDeploymentId = status.studyDeploymentId;
bloc.deviceRoleName = status.primaryDeviceStatus?.device.roleName;

break;
case DeploymentMode.production:
Expand Down
31 changes: 27 additions & 4 deletions lib/data/carp_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class CarpBackend {
// have a smartphone as a device in [ActiveParticipationInvitation.assignedDevices] list
// (i.e. the invitation is for a smartphone).
// This is done to avoid showing invitations for other devices (e.g. [WebBrowser]).
//
// TODO: Do we need to remove invitations which are not for this user?
// - see https://github.com/cph-cachet/carp.core-kotlin/issues/482
invitations.removeWhere((invitation) =>
invitation.assignedDevices
?.any((device) => device.device is! Smartphone) ??
Expand All @@ -152,11 +155,18 @@ class CarpBackend {
}

/// Upload the result of an informed consent flow. Returns the uploaded
/// consent document as retrieved from the server.
/// consent document.
///
/// Looks for the first instance of a [RPConsentSignatureResult] in [consent]
/// and uploads this.
Future<ConsentDocument?> uploadInformedConsent(RPTaskResult consent) async {
Future<InformedConsentInput?> uploadInformedConsent(
RPTaskResult consent,
) async {
if (user == null) {
warning('$runtimeType - No user authenticated.');
return null;
}

late RPConsentSignatureResult signedConsent;
try {
signedConsent = consent.results.values.firstWhere(
Expand All @@ -169,10 +179,23 @@ class CarpBackend {
}

signedConsent.userID = username;
Map<String, dynamic> json = signedConsent.toJson();
final json = toJsonString(signedConsent.toJson());

final uploadedConsent = InformedConsentInput(
userId: user!.id,
name: user!.username,
consent: json,
signatureImage: signedConsent.signature?.signatureImage ?? '',
);

ConsentDocument? uploadedConsent;
try {
final participation = CarpParticipationService().participation();

final data = await participation.setParticipantData(
{InformedConsentInput.type: uploadedConsent},
father,
);

uploadedConsent = await CarpService().createConsentDocument(json);
info(
'$runtimeType - Informed consent document uploaded successfully - id: ${uploadedConsent.id}');
Expand Down
7 changes: 4 additions & 3 deletions lib/data/local_settings.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
part of carp_study_app;

/// A local settings manager. Works as a singleton - use `LocalSettings()`
/// for accessing settings.
/// A local settings manager.
///
/// Works as a singleton - use `LocalSettings()` for accessing settings.
class LocalSettings {
// Keys for storing in shared preferences
static const String studyIdKey = 'study_id';
Expand Down Expand Up @@ -75,7 +76,7 @@ class LocalSettings {
set deviceRoleName(String? name) {
assert(
name != null,
'Cannot set the study deployment id to null in Settings. '
'Cannot set the device role name id to null in Settings. '
"Use the 'eraseStudyDeployment()' method to erase study deployment information.");
_deviceRoleName = name;
Settings().preferences?.setString(deviceRoleNameKey, name!);
Expand Down
10 changes: 5 additions & 5 deletions lib/main.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 970e0c7

Please sign in to comment.