Extra Data Stream [DRAFT] - fli-iam/shanoir-ng GitHub Wiki

Context

A dicentric study, funded by ARSEP, collects data about walking disorders from multiple sclerosis patients. The researchers plan to collect MRI files and hip/leg movement measures. The later measures are acquired with a motion captor and send to a smartphone (1 or 2 in this case). The smartphone is provided by the clinic and to be used only by a clinical expert.

Shanoir is perfectly suited for storing and organizing those files, but importing those walking measures could be fastidious. A clinical expert would require to connect the smartphone after each usage, download the measures on his local machine, connect to the server of Shanoir and using the web interface to upload the CSV files. Here we seek a way to automate the transfer of the walking data from the recording device to Shanoir via a smartphone application.

Constraints

  • first measures with patients : starting in february 2022
  • data format : csv with floats, timestamp, patient id (different from Shanoir's)
  • date for the measure : date of the clinical examination (not the same date as the MRI scan/exam)
  • 2 measures per patient per clinical examination
  • study hosted on the Neurinfo Shanoir instance: https://shanoir.irisa.fr

The uploaded CSV files will not contain any patient identifying information or personal health information (PHI). The expert in the clinical center will do the mapping between the subjects in Shanoir and the CSV files uploaded.

Solution

The solution is to provide a buffer storage on the Shanoir server where the walk recording devices will upload csv files. After that, an authorized Shanoir user will be able to select file(s) among those when importing "extra data", directly from the Shanoir user interface.

Buffer storage (Pre-Archive Folder), per study

To clearly separate the data between different studies, each study will have its own buffer storage (pre-archive folder). The studyId is used to separate between studies on the server.

Shanoir will extend its REST API to upload csv files (HTTP Post). Shanoir will not modify the file name at any time, so the uploader has to assure the correct format of the file name.

  • studyId (integer number)

  • The csv file name should be formatted so the Shanoir operator can identify them. The file names should contain :

    • date
    • patient id (different from Shanoir's)
  • After being attached to an examination, a csv file is deleted from the buffer storage

  • The REST API will require an authentication : Working example in Java with below code:

      String keycloakURL = "https://shanoir.irisa.fr/auth/realms/shanoir-ng/protocol/openid-connect/token";
      try {
      	final StringBuilder postBody = new StringBuilder();
      	postBody.append("client_id=mobile_application_name");
      	postBody.append("&grant_type=password");
      	postBody.append("&username=").append(URLEncoder.encode(username, "UTF-8"));
      	postBody.append("&password=").append(URLEncoder.encode(password, "UTF-8"));
      	postBody.append("&scope=offline_access");
    
      	HttpResponse response = httpService.post(keycloakURL, postBody.toString(), true);
      	if(response == null) {
      		logger.error("Error while asking authentification token from: " + keycloakURL);
      		return null;
      	}
      	String responseEntityString = EntityUtils.toString(response.getEntity());
      	final int statusCode = response.getStatusLine().getStatusCode();
      	if (HttpStatus.SC_OK == statusCode) {
      		JSONObject responseEntityJson = new JSONObject(responseEntityString);
      		String refreshToken = responseEntityJson.getString("refresh_token");
      		refreshToken(keycloakURL, refreshToken);
      		return responseEntityJson.getString("access_token");
      	}
    

Attention: please be aware that the smartphone application is in charge of asking the user for its username+password and - if desired to avoid re-login all 5 minutes - has to maintain a token refresh all 4 minutes.

Shanoir User Interface

Examination create/edit page

Currently, it is possible to attach extra data when creating or editing an examination. Creating a new examination is already an option of the import process. If necessary, we could provide an easy way to edit an examination during the import process.

  • the authorized user is showed a list of the buffered csv files, ordered by name or by the date included in the file name.
  • the user selects a file from the csv list and click "attach to examination"
  • the file is removed from the csv list and added to the attached files list
  • the user saves the examination
  • if a mistake is made, one can still download the file from this examination, then delete it and reattach it "manually" to the right examination

Shanoir tree

We could also add new features to the Shanoir tree that is displayed, for instance, on a study details page. From the tree, a user could :

  • create a new subject below an existing study
  • create a new examination below an existing subject
  • add extra data files below an existing examination