Manual Reference Source Test
import DeviceService from 'clinical6/src/services/DeviceService.js'
public class | source

DeviceService

Extends:

AbstractServiceJsonApiService → DeviceService

Service handling Device calls with specific endpoints.

Constructor Summary

Public Constructor
public

Update type to be devices

Member Summary

Public Members
public

Method Summary

Public Methods
public

delete(device: Device, cacheMode: String): Promise

public

get(params: Object, cacheMode: String): Promise<Device[]|Device>

public

insert(mobileApplicationKey: String, cacheMode: String): Promise<Device>

public

update(device: Device, cacheMode: String): Promise<Device>

Inherited Summary

From class AbstractService
public get
public set
public
private
From class JsonApiService
public

options: *

public

async delete(obj: Object, options: String): Promise

Call a DELETE request on the main obj.type expecting JSON API information.

public

async get(params: Object, options: String): Promise

Call a GET request expecting JSON API information.

public

async getChildren(parent: Object, child: Object, options: String): Promise

Call a GET request expecting JSON API information for children given a parent.

public

async insert(obj: Object, options: String): Promise

Call a POST request on the main obj.type expecting JSON API information.

public

async update(obj: Object, options: String): Promise

Call a PATCH request on the main obj.type expecting JSON API information.

Public Constructors

public constructor() source

Update type to be devices

Override:

JsonApiService#constructor

Public Members

public cacheMode: String source

Override:

AbstractService#cacheMode

Public Methods

public delete(device: Device, cacheMode: String): Promise source

Call a DELETE request on the main obj.type expecting JSON API information.

Override:

JsonApiService#delete

Params:

NameTypeAttributeDescription
device Device

Device object in which to update

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Message

Example:

import { deviceService } from 'clinical6';

// You will be able to delete a device using `delete`.
deviceService.delete({ id: 23 });
// This will also clear the local storage of this type and id

Test:

public get(params: Object, cacheMode: String): Promise<Device[]|Device> source

Call a GET request expecting JSON API information.

Override:

JsonApiService#get

Params:

NameTypeAttributeDescription
params Object
  • optional

Parameters used to get information from server (such as id)

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Device[]|Device>

Promise object that returns one device or a key:device hashtable

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { deviceService } from 'clinical6';

// You will be able to access these devices using the `get` method.
deviceService.get().then(devices => console.log(devices));

// Additionally, you can retrieve a specific device with the `get`
// method, using the ID of the desired device as a parameter.
deviceService.get(23).then(device => console.log(device));

Test:

public insert(mobileApplicationKey: String, cacheMode: String): Promise<Device> source

Call a POST request on the main obj.type expecting JSON API information.

Override:

JsonApiService#insert

Params:

NameTypeAttributeDescription
mobileApplicationKey String

Key from server

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Device>

Inserted device

Example:

import { Device, deviceService } from 'clinical6';
const device = new Device({...});

// you can insert a device using the `insert` method.
deviceService.insert(mobileApplicationKey).then(device => console.log(device));

// you could also just call `save` on the device if it doesn't have an id, which will also
// invoke the `insert` method
device.save();

Test:

public update(device: Device, cacheMode: String): Promise<Device> source

Call a PATCH request on the main obj.type expecting JSON API information.

Override:

JsonApiService#update

Params:

NameTypeAttributeDescription
device Device

Device object in which to update

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Device>

Updated device

Example:

import { Device, deviceService } from 'clinical6';
const device = new Device({...});

// you can update a device using the `update` method.
deviceService.update(device).then(device => console.log(device));

// you could also just call `save` on the device if it has an id, which will also
// invoke the `update` method
device.save();

Test: