Skip to content

Commit

Permalink
new mock system
Browse files Browse the repository at this point in the history
  • Loading branch information
dariosalvi78 committed Jan 14, 2025
1 parent fb95da4 commit 4fe63f8
Show file tree
Hide file tree
Showing 30 changed files with 1,145 additions and 1,011 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ The app is developed as an Apache Cordova app using the [quasar framework](https

You need to install the following on your system:

- python (because nodejs requires python)
- nodejs
- Apache Cordova
- (optional) the [quasar command line tool](https://quasar.dev/quasar-cli/installation)
Expand Down
2 changes: 1 addition & 1 deletion project.config.template.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// USE THESE TO TWEAK THE COMPILATION OPTIONS
module.exports = {
// use 'MOCK' for mock api, 'OFFICIAL' for official server, anything else for testing, for example '/api' for local server
// use 'MOCK' for mock api, 'OFFICIAL' for official servers, anything else for testing, for example '/api' for local server
API_ENDPOINT: 'OFFICIAL',

// use 'MOCK' for mock healthstore or 'cordova' for the cordova health plugin
Expand Down
35 changes: 8 additions & 27 deletions quasar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,6 @@ module.exports = configure(function (ctx) {
},

extendWebpack (cfg) {
if (config.API_ENDPOINT.toLowerCase() === 'mock') cfg.resolve.alias['@shared/API'] = path.resolve(__dirname, './src/shared/API/API.mock')

if (config.HEALTHSTORE.toLowerCase() === 'mock') cfg.resolve.alias['@shared/healthstore'] = path.resolve(__dirname, './src/shared/healthstore/healthstore.mock')

if (config.NOTIFICATIONS.toLowerCase() === 'web') cfg.resolve.alias['@shared/notifications'] = path.resolve(__dirname, './src/shared/notifications/notifications.web')
if (config.NOTIFICATIONS.toLowerCase() === 'mock') cfg.resolve.alias['@shared/notifications'] = path.resolve(__dirname, './src/shared/notifications/notifications.mock')

if (config.PHONE.toLowerCase() === 'mock') cfg.resolve.alias['@shared/phone/phone'] = path.resolve(__dirname, './src/shared/phone/phone.mock')

if (config.BLE.toLowerCase() === 'mock') {
cfg.resolve.alias['@shared/devices/bledevice'] = path.resolve(__dirname, './src/shared/devices/bledevice/BLEDevice.mock')
// all BLE devices are mocked
cfg.resolve.alias['@shared/devices/miband3/miband3ActivityTypeEnum.js'] = path.resolve(__dirname, './src/shared/devices/miband3/miband3ActivityTypeEnum.js')
cfg.resolve.alias['@shared/devices/miband3'] = path.resolve(__dirname, './src/shared/devices/miband3/miband3.mock')
cfg.resolve.alias['@shared/devices/po60/IPulseOxDevice'] = path.resolve(__dirname, './src/shared/devices/po60/IPulseOxDevice.mock')
}
if (config.BLE.toLowerCase() === 'web') cfg.resolve.alias['@shared/devices/bledevice'] = path.resolve(__dirname, './src/shared/devices/bledevice/BLEDevice.web')

if (config.PEAKFLOW.toLowerCase() === 'mock') cfg.resolve.alias['@shared/peakflow/peakflow'] = path.resolve(__dirname, './src/shared/peakflow/peakflow.mock')

if (config.STORAGE.toLowerCase() === 'local') cfg.resolve.alias['@shared/storage/storage'] = path.resolve(__dirname, './src/shared/storage/storage.local')
if (config.STORAGE.toLowerCase() === 'mock') cfg.resolve.alias['@shared/storage/storage'] = path.resolve(__dirname, './src/shared/storage/storage.mock')
if (config.STORAGE.toLowerCase() === 'encrypted') cfg.resolve.alias['@shared/storage/storage'] = path.resolve(__dirname, './src/shared/storage/storage.encrypted')

if (config.FILES.toLowerCase() === 'mock') cfg.resolve.alias['@shared/files/files'] = path.resolve(__dirname, './src/shared/files/files.mock')

cfg.resolve.alias = {
...cfg.resolve.alias,
'@components': path.resolve(__dirname, './src/components'),
Expand All @@ -116,7 +90,14 @@ module.exports = configure(function (ctx) {
env: {
// environmental variables passed to the rest of the code
APP_VERSION: require('./package.json').version,
API_ENDPOINT: config.API_ENDPOINT
API_ENDPOINT: config.API_ENDPOINT,
STORAGE: config.STORAGE,
PHONE: config.PHONE,
FILES: config.FILES,
NOTIFICATIONS: config.NOTIFICATIONS,
HEALTHSTORE: config.HEALTHSTORE,
PEAKFLOW: config.PEAKFLOW,
BLE: config.BLE
}

},
Expand Down
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import i18nCommon from '@i18n/common'
import { defineComponent } from 'vue'
import session from '@shared/session'
import phone from '@shared/phone/phone'
import phone from '@shared/phone'
import DB from '@shared/db'
import API from '@shared/API'
Expand Down
167 changes: 167 additions & 0 deletions src/shared/API/API.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import axios from 'axios'

let axiosConfig = {}

export default {
baseURL: '',
getServersList: () => {
return [
{
id: 'malmo',
url: process.env.API_ENDPOINT === 'OFFICIAL' ? 'https://app.mobistudy.org/api' : process.env.API_ENDPOINT,
names: {
en: 'Malmo University',
sv: 'Malmö Universitet',
es: 'Universidad de Malmo',
it: 'Università di Malmo'
}
},
{
id: 'ucbm',
url: process.env.API_ENDPOINT === 'OFFICIAL' ? 'https://mobistudy.ucbm.it/api' : process.env.API_ENDPOINT,
names: {
en: 'Campus Bio Medico University of Rome',
sv: 'Campus Bio Medico universitetet i Rom',
es: 'Universidad Campus Bio-Medico de Roma',
it: 'Università Campus Bio-Medico di Roma'
}
}
]
},
setBaseUrl (url) {
this.baseURL = url
},
setToken (newtoken) {
axiosConfig = {
headers: {
Authorization: 'Bearer ' + newtoken
}
}
},
unsetToken () {
axiosConfig = {}
},
// Log in
async login (email, password) {
const resp = await axios.post(this.baseURL + '/login', { email, password })
return resp.data
},
// Registration
async registerUser (email, password) {
return axios.post(this.baseURL + '/users', {
email,
password,
role: 'participant'
})
},
// Password reset
async resetPW (email) {
return axios.post(this.baseURL + '/sendResetPasswordEmail', { email })
},
// Change password
async changePW (token, newpw) {
return axios.post(this.baseURL + '/resetPassword', { token, password: newpw })
},
async searchDiseaseConcept (disease, lang) {
const resp = await axios.get(this.baseURL + '/vocabulary/' + lang + '/disorder/search?term=' + disease + '&limit=10')
return resp.data
},
async searchMedicationConcept (med, lang) {
const resp = await axios.get(this.baseURL + '/vocabulary/' + lang + '/substance/search?term=' + med + '&limit=10')
return resp.data
},
/// ////////////////////////////////////
// from here on, we need to use tokens
/// ////////////////////////////////////

// token renewal
async renewToken () {
const resp = await axios.get(this.baseURL + '/users/renewToken', axiosConfig)
return resp.data
},

// Create the participant profile
async createProfile (profile) {
const resp = axios.post(this.baseURL + '/participants', profile, axiosConfig)
return resp.data
},

// Get the participant profile
async getProfile (userKey) {
const resp = await axios.get(this.baseURL + '/participants/byuserkey/' + userKey, axiosConfig)
return resp.data
},

// Updating details
async updateProfile (profile) {
return axios.patch(this.baseURL + '/participants/byuserkey/' + profile.userKey, profile, axiosConfig)
},

// Permanently delete the user
async deleteUser (userKey) {
return axios.delete(this.baseURL + '/participants/byuserkey/' + userKey, axiosConfig)
},

// update status of a study
async updateStudyStatus (userKey, studyKey, studyParticipation) {
return axios.patch(this.baseURL + `/participants/byuserkey/${userKey}/studies/${studyKey}`, studyParticipation, axiosConfig)
},

// update status of a task item consent
async updateTaskItemConsent (userKey, studyKey, taskId, taskItemConsent) {
return axios.patch(this.baseURL + `/participants/byuserkey/${userKey}/studies/${studyKey}/taskItemsConsent/${taskId}`, taskItemConsent, axiosConfig)
},

// retrieves study descritpion
async getStudyDescription (studyKey) {
const resp = await axios.get(this.baseURL + '/studies/' + studyKey, axiosConfig)
return resp.data
},

// retrieves the keys of the new studies already filtered out by inclusion criteria
async getNewStudiesKeys () {
const resp = await axios.get(this.baseURL + '/studies/newStudies/', axiosConfig)
return resp.data
},

// retrieves an invitational study based on a code
async getInvitationalStudy (invitationalCode) {
const resp = await axios.get(this.baseURL + `/studies/invitational/${invitationalCode}`, axiosConfig)
return resp.data
},

// gets a form given its key
async getForm (formKey) {
const resp = await axios.get(this.baseURL + '/forms/' + formKey, axiosConfig)
return resp.data
},

// sends an attachment file, returns the file name chosen by the server
async sendAttachment (studyKey, taskId, filename, fileData) {
const config = {
method: 'post',
url: this.baseURL + '/attachments/' + studyKey + '/' + taskId,
params: { filename },
headers: {
Authorization: axiosConfig.headers.Authorization,
'Content-Type': 'application/octet-stream'
},
data: fileData
}

const resp = await axios(config)
return resp.data
},

// get environment data from position
async getEnvironmentFromPosition (lat, long) {
const resp = await axios.get(this.baseURL + '/environment?lat=' + lat + '&long=' + long, axiosConfig)
return resp.data
},

// send tasks results data
async sendTasksResults (data) {
return axios.post(this.baseURL + '/tasksResults', data, axiosConfig)
}

}
Loading

0 comments on commit 4fe63f8

Please sign in to comment.