addStudyFromProtocol method
Future<SmartphoneStudy>
addStudyFromProtocol(
- StudyProtocol protocol, [
- String? studyDeploymentId
Create and add a study based on the protocol which needs to be executed on
this client.
This is similar to the addStudy method, but the study is created from the
protocol. If studyDeploymentId is specifies this id is used as the study
deployment id. If not specified, an UUID v1 id is generated.
Returns the newly added study.
Implementation
Future<SmartphoneStudy> addStudyFromProtocol(
StudyProtocol protocol, [
String? studyDeploymentId,
]) async {
assert(deploymentService != null,
'Deployment Service has not been configured. Call configure() first.');
final status = await deploymentService!.createStudyDeployment(
protocol,
[],
studyDeploymentId,
);
// no participant is specified in a protocol so look up the local user id
var userId = await Settings().userId;
final study = SmartphoneStudy(
studyDeploymentId: status.studyDeploymentId,
deviceRoleName: status.primaryDeviceStatus!.device.roleName,
// we expect that this is a "local" protocol where we use the user id as
// participant id and with just one participant
participantId: userId,
participantRoleName: protocol.participantRoles == null ||
protocol.participantRoles!.isEmpty
? 'Participant'
: protocol.participantRoles?.first.role,
);
return await addStudy(study);
}