getAllStudyDeployments method

Future<List<SmartphoneStudy>> getAllStudyDeployments()

Get the list of all study deployments previously stored on this phone.

Returns an empty list, if not study deployments are stored.

Implementation

Future<List<SmartphoneStudy>> getAllStudyDeployments() async {
  info("$runtimeType - Getting all study deployments stored on this device.");
  List<SmartphoneStudy> list = [];
  try {
    final List<Map<String, Object?>> maps = await database?.query(
          DEPLOYMENT_TABLE_NAME,
          columns: [
            STUDY_ID_COLUMN,
            STUDY_DEPLOYMENT_ID_COLUMN,
            DEVICE_ROLE_NAME_COLUMN,
            PARTICIPANT_ID_COLUMN,
            PARTICIPANT_ROLE_NAME_COLUMN,
            DEPLOYMENT_STATUS_COLUMN,
          ],
        ) ??
        [];
    if (maps.isNotEmpty) {
      for (var map in maps) {
        final study = SmartphoneStudy(
          studyId: map[STUDY_ID_COLUMN] as String,
          studyDeploymentId: map[STUDY_DEPLOYMENT_ID_COLUMN] as String,
          deviceRoleName: map[DEVICE_ROLE_NAME_COLUMN] as String,
          participantId: map[PARTICIPANT_ID_COLUMN] as String,
          participantRoleName: map[PARTICIPANT_ROLE_NAME_COLUMN] as String,
        );
        final status = map[DEPLOYMENT_STATUS_COLUMN] as int;
        study.status = StudyStatus.values[status];
        list.add(study);
      }
    }
  } catch (exception) {
    warning('$runtimeType - Failed to load deployments - $exception');
  }

  return list;
}