addStudyFromProtocol method
Future<SmartphoneStudy>
addStudyFromProtocol(
- StudyProtocol protocol, [
- String? studyDeploymentId
Creates a study deployment from protocol and adds it as a study.
Same as addStudy, but first creates the deployment in the
deploymentService. If studyDeploymentId is specified, it is used as
the study deployment id. Otherwise the deployment service generates one.
Meant for local protocols with one participant: the local user id from Settings.userId is used as participant id, and the first participant role in the protocol (or 'Participant') as participant role name.
Implementation
Future<SmartphoneStudy> addStudyFromProtocol(StudyProtocol protocol, [String? studyDeploymentId]) async {
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: protocol.primaryDevice.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);
}