Source code for research_client.consent

"""Informed consent from user."""
import eel
import uuid
from datetime import datetime
from pathlib import Path
from typing import Any
from .. import booteel
from ..config import config
import os
import json

#Define paths used is functions below
data_path: Path = config.paths.data / "Consent"
if not data_path.exists():
    data_path.mkdir(parents=True, exist_ok=True)

dir = os.path.dirname(os.path.realpath(__file__))
versions_dir = os.path.join(dir, "versions")
versionsDirList = os.listdir(versions_dir)


[docs]def fetch_file_info(file: str): """takes a json file and returns info from inside the file as a list in the form of [version_name, version_ID, version_data]""" file_info = [] with open(file, encoding='utf-8') as f: #print("WORKING FILE is: " + file) data = json.load(f) versionId = data["meta"]["versionId"] versionType = data["meta"]["versionType"] versionLanguages = data["meta"]["versionLanguages"] versionName = data["meta"]["versionName"] file_info.extend([versionId, versionType, versionLanguages, versionName]) #print(f"\nFile fetched: {file}. \nFile info is: {file_info}") return file_info
[docs]@eel.expose def set_options(selected_version: str): """Takes a language version as arg and finds all consent forms available for that version. Returns a list in the form of [version_name, version_ID, version_data]""" options = [] print("Informed Consent: working DIR = ", versions_dir) for file_name in versionsDirList: bare_file_name = file_name.split(".", 1)[0] bare_version = selected_version.split(".", 1)[0] #print("bare version: " + bare_version) #print("bare file name: " + bare_file_name) if bare_file_name == bare_version: file_info = fetch_file_info(os.path.join(versions_dir, file_name)) optionID = file_info[0] optionName = file_info[3] print("\n Option found:") print("\t option name: " + optionName) print("\t option ID: " + optionID) option = [optionID, optionName] options.append(option) #print("\nList of consent files available: ") #print(options) return options
[docs]@eel.expose def fetch_study_info(filename: str): """takes a filename and returns the json data from that file""" file = os.path.join(versions_dir, filename) with open(file, "r", encoding='utf-8') as f: version_data = json.load(f) return version_data