Module: query-controller

This module collects all the queries that are dealing with the core data.
Version:
  • 1.0
Author:
  • Mateusz Nowak, Luka Kralj

Methods


<async, inner> addCarer(json, actionUsername)

Add new carer to the database
Parameters:
Name Type Description
json JSON entry to add
actionUsername string The user who issued the request. Obligatory properties within JSON
Properties:
Name Type Description
carer_email
Returns:
result of the query - {success:Boolean}
Type
JSON

<async, inner> addHospital(json, actionUsername)

Add new Hospital to the database
Parameters:
Name Type Description
json JSON entry to add
actionUsername string The user who issued the request. Obligatory properties within JSON
Properties:
Name Type Description
hospital_email
Returns:
result of the query - {success:Boolean}
Type
JSON

<async, inner> addPatient(json, actionUsername)

Add new patient to the database
Parameters:
Name Type Description
json JSON entry to add
actionUsername string The user who issued the request. Obligatory properties within JSON
Properties:
Name Type Description
patient_no
Returns:
result of the query - {success:Boolean}
Type
JSON

<async, inner> addPatientExtended(patientInfo, actionUsername)

Add new patient entry to the database with optional carer/hospital
Parameters:
Name Type Description
patientInfo JSON entry to add
actionUsername string The user who issued the request.
Returns:
result of the query - {success:Boolean response:{insertedId/problem (+ optional fields)}}
Type
JSON

<async, inner> addTest(json, actionUsername)

Add new test to the database
Parameters:
Name Type Description
json JSON entry to add
actionUsername string The user who issued the request. Obligatory properties within JSON
Properties:
Name Type Description
patient_no
due_date
Returns:
result of the query - {success:Boolean}
Type
JSON

<async, inner> addUser(json, actionUsername)

Add new user to the database
Parameters:
Name Type Description
json JSON user
actionUsername string The user who issued the request. Obligatory properties within JSON
Properties:
Name Type Description
username String
hashed_password String
email String
isAdmin string "yes" | "no"
Returns:
result of the query - {success:Boolean}
Type
JSON

<async, inner> changePatientColour(patientNo, newColour)

Edit patient colour - quick update.
Parameters:
Name Type Description
patientNo String Number of the patient to update
newColour string New colour to be stored.
Returns:

<async, inner> changeTestColour(testId, newColour)

Edit test colour - quick update.
Parameters:
Name Type Description
testId String Id of the test to update
newColour string New colour to be stored.
Returns:

<async, inner> changeTestDueDate(testId, newDate)

Edit test due date - drag & drop method
Parameters:
Name Type Description
testId String Id of the test to update
newDate Date new due date
Returns:

<async, inner> changeTestStatus(test, actionUsername)

Change the status of the test in the database
Parameters:
Name Type Description
test JSON
actionUsername string The user who issued the request.
Properties:
Name Type Description
testId String id of a test to change
Returns:
result of the query - {success:true/false response:Array/Error}
Type
JSON

<async, inner> checkIfPatientsTestsAreEdited()

Check if test are edited within the EditTokens database
Returns:
  • {false - If no tests are edited (no tokens)}
    Type
    Boolean
  • {true - If tests are edited (tokens in table)}
    Type
    Boolean
  • {Error response}
    Type
    JSON

<async, inner> deleteCarer(carerid, actionUsername)

Delete Carer entry from database
Parameters:
Name Type Description
carerid String id of a carer to be deleted
actionUsername string The user who issued the request.
Returns:
result of the query - {success:Boolean response:"Entry deleted"/Error}
Type
JSON

<async, inner> deleteHospital(hospitalid, actionUsername)

Delete hospital entry from database
Parameters:
Name Type Description
hospitalid String id of a hospital to be deleted
actionUsername string The user who issued the request.
Returns:
result of the query - {success:Boolean response:"Entry deleted"/Error}
Type
JSON

<async, inner> deletePatient(patientid, token, actionUsername)

Delete Patient and cancel the patient edit token
Parameters:
Name Type Description
patientid String patient_no of a patient
token String token to be returned with query
actionUsername string The user who issued the request.
Returns:
result of the query - {success:Boolean response:"Entry deleted"/Error}
Type
JSON

<async, inner> deleteTest(testid, actionUsername)

Delete test entry from database
Parameters:
Name Type Description
testid String id of a test to be deleted
actionUsername string The user who issued the request.
Returns:
result of the query - {success:Boolean response:"Entry deleted"/Error}
Type
JSON

<async, inner> editCarer(newInfo, token, actionUsername)

Edit carer query
Parameters:
Name Type Description
newInfo JSON All the information of the carer to update
token The token that grants edit privileges
actionUsername string The user who issued the request.
Properties:
Name Type Description
carer_id String

<async, inner> editHospital(newInfo, token, actionUsername)

Edit hospital query
Parameters:
Name Type Description
newInfo JSON All the information of the hospital to update Obligatory fields in JSON
token The token that grants edit privileges
actionUsername string The user who issued the request.
Properties:
Name Type Description
hospital_id String

<async, inner> editPatient(newInfo, token, actionUsername)

Edit patient query
Parameters:
Name Type Description
newInfo JSON All the information of the patient to update Obligatory fields in JSON
token The token that grants edit privileges
actionUsername string The user who issued the request.
Properties:
Name Type Description
patient_no String

<async, inner> editPatientExtended(newInfo, token)

Edit patient with hospital and carer query
Parameters:
Name Type Description
newInfo JSON All the information of the patient/hospital/carer to update
token The token that grants edit privileges
Returns:
query result {success:Boolean response:{Response of each query as {success:Boolean response:Array/Error/String} or {} }}
Type
JSON

<async, inner> editTest(testId, newInfo, token, actionUsername)

Edit test query
Parameters:
Name Type Description
testId The id of the test to be updated
newInfo JSON All the information of the test (new and old)
token The token that grants edit privileges
actionUsername string The user who issued the request.

<async, inner> editUser(json, actionUsername)

Update User in database
Parameters:
Name Type Description
json JSON user
actionUsername string The user who issued the request. Obligatory properties:
Properties:
Name Type Description
username String , One of optional properties Optional properties:
recovery_email String
hashed_password String
Returns:
- {success:Boolean response:Array or Error}
Type
JSON

<async, inner> getAllPatients(isAdult)

Get all the patients from the database
Parameters:
Name Type Description
isAdult Boolean If the records should be displayed for adult users
Returns:
result of the query - {success:true/false response:Array/Error}
Type
JSON

<async, inner> getAllUsers()

Get all users from database
Returns:
result of the query - {success:true/false response:Array/Error}
Type
JSON

<async, inner> getCarer(carerID)

Get the carer given its carer id
Parameters:
Name Type Description
carerID string the carer id
Returns:
- {success:Boolean response:Array or Error}
Type
JSON

<async, inner> getFullPatientInfo(patient_no)

Get the info of the patient together with the info of eventual carers and hospitals
Parameters:
Name Type Description
patient_no string the patient number
Returns:
- {success:Boolean response:Array or Error}
Type
JSON

<async, inner> getHospital(hospital_id)

Get the hospital given its hospital id
Parameters:
Name Type Description
hospital_id string the hospital id
Returns:
- {success:Boolean response:Array or Error}
Type
JSON

<inner> getNextDueDate(frequency)

Get next due date of a test in "YYYY-MM-DD" format; relative to today
Parameters:
Name Type Description
frequency String frequency of the test as stored in database
Returns:
- next due date in "YYYY-MM-DD" format
Type
String

<async, inner> getNextTestsOfPatient(patientId)

Get not completed tests from patient
Parameters:
Name Type Description
patientId String id of patient
Returns:
result of the query - {success:true/false response:Array/Error}
Type
JSON

<async, inner> getOverdueReminderGroups(isAdult)

Returns overdue tests that are separated into two groups. One group are the tests that haven't been sent a reminder. The other group are the tests that have already been sent a reminder. Response includes some basic info about the test.
Parameters:
Name Type Description
isAdult Boolean If the records should be displayed for adult users
Returns:
{ success: true|false, response: { notReminded: [{ test_id: due_date: patient_no: patient_name: patient_surname: }, ...] reminded: [{ test_id: due_date: patient_no: patient_name: patient_surname: last_reminder: reminders_sent: }, ...] } }
Type
JSON

<async, inner> getPatient(patient_no)

Get the patient given its patient number
Parameters:
Name Type Description
patient_no string the patient number
Returns:
- {success:Boolean response:Array or Error}
Type
JSON

<async, inner> getReport(date)

Collects data from selector queries and returns them.
Parameters:
Name Type Description
date date
Returns:
{success:Boolean, response:JSON}
Type
JSON

<async, inner> getTest(test_id)

Get test from the database
Parameters:
Name Type Description
test_id String id of test
Returns:
result of the query - {success:true/false response:Array/Error}
Type
JSON

<async, inner> getTestInfo(test_id)

Get test info with patient info from the database
Parameters:
Name Type Description
test_id String id of test
Returns:
result of the query - {success:true/false response:Array/Error}
Type
JSON

<async, inner> getTestWithinWeek(date, isAdult)

Get all tests within the week from the database
Parameters:
Name Type Description
date String any date (from Monday to Friday) within the week to retrieve (format: "YYYY-MM-DD")
isAdult Boolean If the records should be displayed for adult users
Returns:
result of the query - {success:true/false response:Array/Error}
Type
JSON

<async, inner> getUser(username)

Get user from database
Parameters:
Name Type Description
username String username to retrieve
Returns:
result of the query - {success:true/false response:Array/Error}
Type
JSON

<async, inner> requestEditing(table, id, actionUsername)

Request editing of an entry in table
Parameters:
Name Type Description
table String Table to edit
id String id to edit
actionUsername string The user who issued the request.
Returns:
token
Type
String

<async, inner> returnToken(table, id, token, actionUsername)

Cancel editing on an entry
Parameters:
Name Type Description
table String Table of an entry
id String id value of an entry
token String token to return
actionUsername string The user who issued the request.
Returns:
result - {success:Boolean response:"Token cancelled"/Error}
Type
JSON

<async, inner> scheduleNextTest(testId, actionUsername, newInfo)

Schedule next blood test based on information in database and/or new information provided New information have priority over stored in database (new info > database info)
Parameters:
Name Type Description
testId String id of a string from which to take the info
actionUsername string The user who issued the request.
newInfo JSON (optional) new info to add into database with new test
Returns:
- result of query {success:true/false reply:(optional;when no new entry inserted due to finished range of tests)}
Type
JSON

<inner> sortPatinetProperties(patientInfo)

Sort patient properties into patient,carer and hospital information
Parameters:
Name Type Description
patientInfo JSON information to be sorted
Returns:
Sorted information: {patient: hospital: carer:}
Type
JSON

<async, inner> unscheduleTest(testid, token, actionUsername)

Unschedule test
Parameters:
Name Type Description
testid String id of the test to delete
token String token to realease with the unscheduling
actionUsername String username that triggered the action

<async, inner> updateLastReminder(testId, token, actionUsername)

Update when the last reminder for this test was sent.
Parameters:
Name Type Description
testId string id of a test to change
token string The token that grants edit privileges.
actionUsername string The user who issued the request.
Returns:
result of the query - {success:true/false response:Array/Error}
Type
JSON

Type Definitions


getSortedOverdueWeeks

Get all the overdue tests from the database plus additional info about time difference
Type:
  • SortedWeek
Properties:
Name Type Description
class String monday of the week, format: 'Mon Mar 04 2019 00:00:00 GMT+0000 (GMT)'