Skip to content

Web API

awesomeyi edited this page Apr 13, 2016 · 17 revisions

API Usage Guide

General Protocol

Server data will always be sent down in JSON format in the following protocol:

Success
{
  "status": "success",
  "data": {
    //return data will appear here
  },
  "message": null //optional success message
}
Failure
{
  "status": "error",
  "data": null,
  "message": "Error message" //Custom error message
}

ND specifies that the action will have a NULL data payload back from the server

IMG specifies that the server will return a RAW image, not JSON data

Testing

Basic server tests. Destination: api/test/action

get (GET, ND)

Get request test, server will always send back success

post (POST)

Send:

  • foo: test paramater, can be anything

Server will indicate success if foo parameter is set. Receive:

  • fooback: server will echo foo back

notify (POST)

Send:

  • uiud: device token (64 characters)
  • message: desired message

Server will always indicate success. Receive:

  • "Server response": node.js server response

Caretaker actions

Users are fundamentally divided into groups caretakers and patients. Caretaker actions are located at api/caretaker/action

register (POST, ND)

Send:

  • username: user username, must be above 5 characters in length
  • password: user password, must be above 8 characters in length

login (POST)

Send:

  • username: user username
  • password: user password

Recieve:

  • authcode: authentication code

After recieving the authentication code, all future API requests MUST have the authentication code attached as a GET parameter.

Example: /API/user/info?authcode=XxxxXxxxX

verify (GET, ND)

Verifies authcode is valid or invalid, returns success/failure.

info (GET)

Returns user info

Recieve:

  • username: username of user
  • more to come

device (POST, ND)

Register device token for user.

Send:

  • uiud: 64 character device token

Patient interaction

Caretaker and patient interaction. This is done through the following endpoint: /api/caretaker/action

patients (GET)

Fetches a list of patients for the given caretaker.

Recieve:

[
    {
         pid: 5 //patient id,
         name: "John Doe" //name of patient
         active: 1 //whether or not the patient has been successfully linked (0/1)
    },
    {
        //....
    }
]

patients (POST)

Caretaker creates a new patient.

Send:

  • name: full name of patient
  • usability: usability level of patient

Receive:

  • lcode: linking code needed to link with patient
  • pid: patient id of newly created patient

patients/{pid} (GET)

Retrieves patient info for an individual patient.

Recieve:

  • name: name of patient
  • usability: usability level
  • medstatus: boolean (1/0) indicating if they are up to date with their medication

patients/{pid}/relink (GET)

Caretaker resends the lcode for patient {pid}. This is useful if the patient gets a new phone.

Receive:

  • lcode: linking code

patients/{pid}/share (POST, ND)

A caretaker is able to "share" a patient, with another caretaker. This allows multiple caretakers to be connected to one patient.

Send:

  • username: username of person-to-share

Medication

Handles creating medication for the patient. Endpoint: api/caretaker/patients/{pid}/actions

medications (GET)

Get all medication information in a JSON array.

Receive:

[
    {
         medid: 5, //medication id
         name: "Lipitor", //name of medication
         dosage: 2, //medication dosage
         remain: 20, //amount left
         info: "Take with your meal" //additional instructions for taking medication
    },
    {
        //....
    }
]

medications (POST)

Create new medication for given patient

Send:

  • name: name of medication
  • dosage: dosage amount
  • remain: amount of medication left
  • picture: picture of medication
  • info: additional info in taking medication

Receive:

  • medid: medication id

medications/{medid} (GET, IMG)

Get picture for given medication. Returns a 404 not found on error.

Receive:

Raw picture of medication in .jpg format.

medications/{medid} (POST, ND)

Edit medication specified by medid. Only sent parameters you want to modify.

Send:

  • name: name of medication
  • dosage: dosage amount
  • remain: amount of medication left
  • picture: picture of medication
  • info: additional info in taking medication

Scheduling medication

Create schedules for when to take medication for a patient. Endpoint: api/caretaker/patients/{pid}/actions

schedules (GET)

List of schedules returned in JSON array.

Receive:

[
    {
         schid: 5, //schedule id
         hours: 4, //hour of medication (military time)
         minutes: 20 //minute of medication
    },
    {
        //....
    }
]

schedules (POST, ND)

Create a new schedule

Send:

  • hours: hour of medication (military time)
  • minutes: minute of medication
  • medication: attached medication, send comma separated medids. Example data: 1,5,18,20.

schedules/{schid} (GET)

Get medication info for a given schedule. Returns a JSON array.

Recieve:

[
    {
         medid: 5, //medicine id
         taken: 2016-04-20 04:20:69 //Last time medication was taken 
    },
    {
        //....
    }
]

schedules/{schid} (POST, ND)

Alters a given schedule. Allows you to change attached medication.

Send:

  • medication: attached altered medication, send comma separated medids. Example data: 1,5,18,20.

schedules/{schid} (DELETE, ND)

Deletes a given schedule.

Patient actions

Patient actions. Located at /api/patient/action

info (GET)

Gets patient info, same as caretaker endpoint.

link (POST)

Links to the caretaker from the patient device.

Send:

  • lcode: linking code

Receive:

  • authcode: like in the case of the caretaker, the authcode should be attached to all further requests as a GET parameter

device (POST, ND)

Register device token for user.

Send:

  • uiud: 64 character device token

medications (GET, ND)

Medication information for the patient. Same as caretaker medication fetch (check above).

medications/{medid} (GET, IMG)

Fetches picture of medication, also same as caretaker

schedules (GET, ND)

Schedule information, also the same as caretaker schedule fetch.

schedules/{schid} (GET, ND)

More detailed schedule information, same as caretakers.

schedules/{schid}/take (POST, ND)

Marks a given medication {medid} for schedule {schid} as taken and sets the last taken time.

Send:

  • medid: medication id