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

LocationService

Extends:

AbstractServiceJsonApiService → LocationService

Service handling Location calls.

Clinical6 has a couple of built-in methods that make it easy to get a user's current location, and update the location to the server.

Constructor Summary

Public Constructor
public

Update type to be locations

Method Summary

Public Methods
public

delete(object: Object, cacheMode: String): Promise

public

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

public

Gets the current location using the browser navigator.geolocation.getCurrentPosition method

public

getTimezones(params: Object, cacheMode: String): Promise<Timezone[]>

public

insert(location: Object, cacheMode: String): Promise<Location>

public

Calls insertV2 method with the current location latitude and longitude.

public

insertV2(location: Object): Promise

Update user location

public

async update(location: Location, options: Object): Promise

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 locations

Override:

JsonApiService#constructor

Public Methods

public delete(object: Object, cacheMode: String): Promise source

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

Override:

JsonApiService#delete

Params:

NameTypeAttributeDescription
object Object

Object in which to delete

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Message

Test:

public get(params: Object, cacheMode: String): Promise<Location[]|Location> 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)

params.id Number
  • optional

Id of the location

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Location[]|Location>

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

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { locationService } from 'clinical6';

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

Test:

public getCurrent(): Promise source

Gets the current location using the browser navigator.geolocation.getCurrentPosition method

Return:

Promise

Promise object that returns success or failure

Example:

import { locationService } from 'clinical6';

// gets a Promise the current location with the specific latitude or longitude
var location;
locationService.getCurrent().then((location) => location = data );

public getTimezones(params: Object, cacheMode: String): Promise<Timezone[]> source

Params:

NameTypeAttributeDescription
params Object
  • optional

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

params.sort Object
  • optional

Param passed to sort timezones. Can either be 'offset' or '-offset'

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Timezone[]>

Promise object that returns a key:timezone hashtable

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { locationService } from 'clinical6';

// You will be able to access these timezones using the `getTimezones` method.
locationService.getTimezones().then(timezones => console.log(timezones));

// Additionally, you can pass params.offset to sort the returned timezones
locationService.getTimezones({ sort: '-offset' }).then(timezones => console.log(timezones));

Test:

public insert(location: Object, cacheMode: String): Promise<Location> source

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

Override:

JsonApiService#insert

Params:

NameTypeAttributeDescription
location Object
  • optional

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

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Location>

Inserted location

Example:

import { Location, locationService } from 'clinical6';
const location = new Location({...});

// you can insert a location using the `insert` method.
locationService.insert(location).then(location => console.log(location));

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

public insertCurrent(): Promise source

Calls insertV2 method with the current location latitude and longitude.

Return:

Promise

Promise object that returns success or failure

Example:

import { locationService } from 'clinical6';

// gets a Promise that posts the current location to the server
locationService.updateCurrentLocation();

public insertV2(location: Object): Promise source

Update user location

Params:

NameTypeAttributeDescription
location Object

Object including the following location-based fields:

location.latitude Float

Latitude

location.longitude Float

Longitude

location.country String

Country

location.state String

State

location.city String

City

location.street String

Street

location.zip_code String

Zip Code

Return:

Promise

Promise object that returns success or failure

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { locationService } from 'clinical6';

// gets a Promise the current location with the specific latitude or longitude
var location;
locationService.getCurrent().then((location) => location = data );

// gets a Promise that posts a location to the server
locationService.updateLocation(location);

public async update(location: Location, options: Object): Promise source

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

Override:

JsonApiService#update

Params:

NameTypeAttributeDescription
location Location

Location object in which to update

options Object
  • optional

Override the caching method for this call

options.cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Message

Example:

import { Location, locationService } from 'clinical6';
const location = new Location({...});

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

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