UserService
Extends:
Service handling User calls with specific endpoints.
In order to manage user-specific data, access, and info, our SDK provides a user sign-in as well as a guest sign-in. With the plugin, as soon as a user launches your app, they will automatically be signed in as a guest. After you build a login page/UI, your users can enter their credentials to sign in to their own account.
Constructor Summary
Public Constructor | ||
public |
Update type to be mobile_users |
Method Summary
Public Methods | ||
public |
async acceptInvitation(token: String, options: String): Promise<User> Allows a user to accept an invitation given a device and token |
|
public |
acceptInvitationPinV2(json: Object): Promise this method was deprecated.
Sets the pin value for an invited user. |
|
public |
async addAwardedBadge(awardedBadge: Object): Promise<AwardedBadge> Add Awarded Badge |
|
public |
async addSchedule(schedule: Object): Promise<Schedule> Add Schedule |
|
public |
Confirms user with token |
|
public |
|
|
public |
this method was deprecated.
Removes the current user from the system. |
|
public |
async deleteProfileAttribute(id: Number): Promise this method was deprecated.
Deletes the profile attribute value with the given ID. |
|
public |
deleteRelated(id: Number): Promise this method was deprecated.
Removes a related mobile user. |
|
public |
this method was deprecated.
Disables a related mobile user. |
|
public |
this method was deprecated.
Disables the current user's account. This action will revoke the user's access to the system. |
|
public |
emailAccountName(emailAddress: String): Promise this method was deprecated.
Sends user's account name via email. This method does not require an access token. |
|
public |
emailPassword(emailAddress: String): Promise this method was deprecated.
Starts the reset password process and sends an email to the user with instructions. |
|
public |
this method was deprecated.
Enable a related mobile user. |
|
public |
|
|
public |
async getAllProfileAttributes(apiKey: String): Promise this method was deprecated.
Returns all the values for the given profile attribute. |
|
public |
async getAwardedBadges(awardee: Object, awardedBadge: Object, cacheMode: String): Promise<Badge[]|Badge> Get User Badges |
|
public |
async getDataGroup(user: Object, params: Object, cacheMode: String): Promise<FlowDataGroup> Get Flow Data Group for a user. |
|
public |
Get eDiary entries |
|
public |
Invite a user. |
|
public |
async getNotifications(user: Object, cacheMode: String): Promise<Notification[] Get Notifications |
|
public |
async getProfile(user: Object, cacheMode: String): Promise<Profile> Get the profile of a user (or current user if null). |
|
public |
getProfileAttributes(includeHidden: Boolean, includeValues: Boolean): Promise this method was deprecated.
Gets all the custom attributes for the profile along with its values. |
|
public |
async getRegistrationStatus(attributes: Object, meta: String): Promise<String> Returns the registration status of the user. |
|
public |
getRelatedMobileUsers(): Promise<{followed_users: User[], followers: User[]}>{followed_users:> this method was deprecated.
Retrieves all the related mobile users. |
|
public |
Get Schedules for a user based on an id. |
|
public |
async getSession(token: String, cacheMode: String): Promise Get the session of the logged in user. |
|
public |
Get User Sites |
|
public |
|
|
public |
async insertProfileAttribute(key: String, val: String | Number): Promise this method was deprecated.
Inserts a new value for the given profile attribute. |
|
public |
Invite a user. |
|
public |
Register a device for guest, a username, or email |
|
public |
async removeAwardedBadge(awardedBadge: Object, cacheMode: String): Promise<AwardedBadge> Remove Awarded Badge |
|
public |
async requestPasswordReset(attributes: Object): Promise Starts the reset password process and sends an email to the user with instructions. |
|
public |
resendInvite(id: Number, options: any): Promise this method was deprecated.
Resends an invite to a related mobile user. |
|
public |
async resetPassword(attributes: Object, device: Device): Promise<User> Allows users to complete the Password reset flow. |
|
public |
resetPasswordSimple(newPassword: String, newPasswordConf: String, oldPassword: String): Promise this method was deprecated.
Sends user's account name via email. This method does not require an access token. |
|
public |
async revokeConsent(user: User, cacheMode: String): Promise This method revokes the consent for a user. |
|
public |
async saveProfile(param: Object, options: String): Promise<Profile> Update Profile |
|
public |
async sendConfirmation(email: String): Promise Sends a confirmation email to an email address |
|
public |
this method was deprecated.
Sets the pin value for an invited user. |
|
public |
Sign in user with account name. |
|
public |
Detaches the device from the mobile_user. |
|
public |
this method was deprecated.
Sign up a user with a user profile. |
|
public |
async unlockUser(email: String, unlockToken: String): Promise Unlocks a user |
|
public |
|
|
public |
async updateAwardedBadge(awardedBadge: Object, cacheMode: String): Promise<AwardedBadge> Update Awarded Badge |
|
public |
async updateProfileAttribute(profile: Object, id: Number): Promise this method was deprecated.
Updates the profile information for the current, authenticated user. |
|
public |
async updateSchedule(schedule: Object, cacheMode: String): Promise<Schedule> Update Schedule |
Private Methods | ||
private |
_loginGetSession(response: Session | User, device: Device): Session Get and Login Session From Response |
|
private |
_loginGetUser(response: Session | User, device: Device): User Get and Login User From Response |
Inherited Summary
From class AbstractService | ||
public get |
|
|
public set |
|
|
public |
|
|
private |
|
From class JsonApiService | ||
public |
options: * |
|
public |
Call a DELETE request on the main obj.type expecting JSON API information. |
|
public |
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 |
Call a POST request on the main obj.type expecting JSON API information. |
|
public |
Call a PATCH request on the main obj.type expecting JSON API information. |
Public Constructors
Public Members
Public Methods
public async acceptInvitation(token: String, options: String): Promise<User> source
Allows a user to accept an invitation given a device and token
Params:
Name | Type | Attribute | Description |
token | String |
|
Token from request password reset email or accepting invitation email |
options | String |
|
Additional options for accepting invitations |
options.anti_spam_accepted | Boolean |
|
If the anti-spam policy was accepted by the user. |
options.device | Object |
|
Accept invitation with this device |
options.device.id | Number |
|
Must be the device id |
options.email | String |
|
Email, if it is set with the invitation acceptance page. |
options.password | String |
|
Password, if it is set with the invitation acceptance page. |
options.privacy_policy_accepted | Boolean |
|
If the privacy policy was accepted by the user. |
options.terms_of_use_accepted | Boolean |
|
If the terms of use accepted by the user. |
Return:
Promise<User> | Session object is returned. For Mobile Users, this is a local Session object with the authentication token and the user object inserted locally. |
Throw:
If missing required parameters |
Example:
import { mobileUserService } from 'clinical6';
mobileUserService.acceptInvitation('1afw00f...', {
password: 'myPassword!@',
terms_of_use_accepted: true,
privacy_policy_accepted: true,
anti_spam_accepted: true,
device: { id: 15 }
}).then(user => console.log(user));
import { userService } from 'clinical6';
userService.acceptInvitation('1afw00f...', {
password: 'myPassword!@',
terms_of_use_accepted: true,
privacy_policy_accepted: true,
anti_spam_accepted: true
}).then(session => console.log(session.user));
Test:
- [unit] UserService.acceptInvitation should exist
- [unit] UserService.acceptInvitation should throw errors for invalid parameters
- [unit] UserService.acceptInvitation should successfully accept an invitation for a mobile user
- [unit] UserService.acceptInvitation should successfully accept an invitation for a user
public acceptInvitationPinV2(json: Object): Promise source
Sets the pin value for an invited user.
Throw:
If missing token or missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.acceptInvitationPinV2({
"pin": "123456",
"pin_confirmation": "123456",
"invitation_token": "12345678910"
});
{
"status": "ok"
}
{
"error_detail": "Review the new_password and new_password_confirmation parameters",
"friendly_error": "Password and confirmation do not match",
"internal_code": 50362,
"more_info": "",
"status": "fail",
"message": "Password and confirmation do not match"
}
{
"error_detail": {
"invitation_token": [
"invalid_value"
]
},
"friendly_error": "No user found with the specified invitation_token",
"internal_code": 50364,
"more_info": "",
"status": "fail",
"message": "No user found with the specified invitation_token"
}
{
"error_detail": {
"password": [
"already_exists"
]
},
"friendly_error": "Pin already exists",
"internal_code": 50374,
"more_info": "",
"status": "fail",
"message": "Pin already exists"
}
public async addAwardedBadge(awardedBadge: Object): Promise<AwardedBadge> source
Add Awarded Badge
Params:
Name | Type | Attribute | Description |
awardedBadge | Object |
|
The user, must have id |
awardedBadge.attributes | Object |
|
Hashmap to add for award badge |
awardedBadge.user | User |
|
The user, must have id |
awardedBadge.user.id | Number |
|
The user id |
awardedBadge.badge | Badge |
|
The user, must have id |
awardedBadge.badge.id | Number |
|
The user id |
Throw:
If missing token or missing required parameters |
Example:
import { userService, AwardedBadge, Badge, User } from 'clinical6';
const awardedBadge = new AwardedBadge({ updatedAt: '2018-06-02' });
awardedBadge.awardee = new User({ id: 5, ... });
awardedBadge.badge = new Badge({ id: 5, ... });
// You can add an awarded badge using the `addAwardedBadge` method
userService.addAwardedBadge(awardedBadge).then(result => console.log(result));
// Additionally, you can do the same thing using `User.addAwardedBadge()`
user.addAwardedBadge(awardedBadge).then(result => console.log(result));
public async addSchedule(schedule: Object): Promise<Schedule> source
Add Schedule
Params:
Name | Type | Attribute | Description |
schedule | Object |
|
The user, must have id |
schedule.attributes | Object |
|
Hashmap to add for a schedule |
schedule.mobileUser | User |
|
The user, must have id |
schedule.mobileUser.id | Number |
|
The user id |
Throw:
If missing token or missing required parameters |
Example:
import { userService, Schedule, User } from 'clinical6';
const schedule = new Schedule({ updatedAt: '2018-06-02' });
// You can add a schedule using the `addSchedule` method
userService.addSchedule(schedule).then(result => console.log(result));
// Additionally, you can do the same thing using `User.addSchedule()`
user.addSchedule(schedule).then(result => console.log(result));
public async confirm(token: String, cacheMode: String): Promise source
Confirms user with token
Throw:
If missing required parameters |
Example:
import { userService.confirm('1afji13jiifjadif0ijadf');
public async delete(user: User, cacheMode: String): Promise source
Call a DELETE request on the main obj.type expecting JSON API information.
Override:
JsonApiService#deleteExample:
import { mobileUserService } from 'clinical6';
// You will be able to delete a User using `delete`.
mobileUserService.delete({ id: 23 });
// This will also clear the local storage of this type and id
public deleteCurrent(): Promise source
Removes the current user from the system. This action cannot be undone.
Throw:
If missing token |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.deleteCurrent(32);
public async deleteProfileAttribute(id: Number): Promise source
Deletes the profile attribute value with the given ID.
Params:
Name | Type | Attribute | Description |
id | Number | The ID value of the profile attribute |
Throw:
If missing token or missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.deleteProfileAttribute(3);
{
"status": "ok",
"message": "Profile value was successfully deleted"
}
{
"error_detail": {
"ProfileValue": [
"not_found"
]
},
"friendly_error": "Profile value not found using the value:-1",
"internal_code": 50364,
"more_info": "",
"status": "fail",
"message": "Profile value not found using the value:-1"
}
public deleteRelated(id: Number): Promise source
Removes a related mobile user.
Params:
Name | Type | Attribute | Description |
id | Number | The ID value of the related mobile user to remove. |
Throw:
If missing token or missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.deleteRelated(32);
{
"invited": []
}
{
"error_detail": {
"id": "invalid_value"
},
"friendly_error": "Mobile User not found using the value:id",
"internal_code": 50364,
"more_info": "",
"status": "fail",
"message": "Mobile User not found using the value:id"
}
public disable(id: Number): Promise source
Disables a related mobile user.
Params:
Name | Type | Attribute | Description |
id | Number | The ID value of the related mobile user to disable. |
Throw:
If missing token or missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.disable(32);
{
"error_detail": {
"id": "invalid_value"
},
"friendly_error": "Mobile User not found using the value:id",
"internal_code": 50364,
"more_info": "",
"status": "fail",
"message": "Mobile User not found using the value:id"
}
public disableCurrent(): Promise source
Disables the current user's account. This action will revoke the user's access to the system. The method does not delete any data related to the user.
Throw:
If missing token |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.disableCurrent(32);
public emailAccountName(emailAddress: String): Promise source
Sends user's account name via email. This method does not require an access token.
Params:
Name | Type | Attribute | Description |
emailAddress | String | The email address of the account. |
Throw:
If missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.emailAccountName();
public emailPassword(emailAddress: String): Promise source
Starts the reset password process and sends an email to the user with instructions.
Params:
Name | Type | Attribute | Description |
emailAddress | String | Email address to send the reset password email to. |
Throw:
If missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.emailPassword();
public enable(id: Number): Promise source
Enable a related mobile user.
Params:
Name | Type | Attribute | Description |
id | Number | The ID value of the related mobile user to enable. |
Throw:
If missing token or missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.enableUser(19);
{
"invited": []
}
{
"error_detail": {
"id": "invalid_value"
},
"friendly_error": "Mobile User not found using the value:id",
"internal_code": 50364,
"more_info": "",
"status": "fail",
"message": "Mobile User not found using the value:id"
}
public async get(params: Object, cacheMode: String): Promise<User[]|User> source
Call a GET request expecting JSON API information.
Override:
JsonApiService#getThrow:
If missing token or missing required parameters |
Example:
import { mobileUserService } from 'clinical6';
// You will be able to access these mobile users using the `get` method.
mobileUserService.get().then(users => console.log(users));
// Additionally, you can retrieve the subcategories for a specific mobile user with the `get`
// method, using the ID of the desired mobile user as a parameter.
mobileUserService.get({id: 23}).then(users => console.log(users));
// This method will also pull back the `user.profile` should it exist for the user or list of users
public async getAllProfileAttributes(apiKey: String): Promise source
Returns all the values for the given profile attribute.
Params:
Name | Type | Attribute | Description |
apiKey | String | The API key value for the profile attribute. |
Throw:
If missing token or missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.getAllProfileAttributes('fj103jaf08j23jfds').then(attr => console.log(attr));
public async getAwardedBadges(awardee: Object, awardedBadge: Object, cacheMode: String): Promise<Badge[]|Badge> source
Get User Badges
Params:
Name | Type | Attribute | Description |
awardee | Object |
|
The user, must have id |
awardee.id | Number |
|
The user id |
awardedBadge | Object |
|
Filters to modify result (date, entry_group_id) |
awardedBadge.id | Number |
|
Pulling back a specific badge via id from the user |
cacheMode | String |
|
Override the caching method for this call |
Throw:
If missing token or missing required parameters |
Example:
import { mobileUserService, User } from 'clinical6';
// You can get entries using the `getAwardedBadges` method
mobileUserService.getAwardedBadges(new User({ id: 5 })).then(entry => console.log(entry));
const filters = { entry_group_id: 7, date: '2018-06-02'};
mobileUserService.getAwardedBadges({ id: 5 }, filter).then(entry => console.log(entry));
// Additionally, you can do the same thing using `User.getAwardedBadges()`
const user = new User({ id: 5, ... });
user.getAwardedBadges().then(entry => console.log(entry));
user.getAwardedBadges(filter).then(entry => console.log(entry));
public async getDataGroup(user: Object, params: Object, cacheMode: String): Promise<FlowDataGroup> source
Get Flow Data Group for a user. This method can get back data with or without a Flow Data Group ID. This endpoint does not support filters and can only process the page URL params.
Params:
Name | Type | Attribute | Description |
user | Object |
|
User - if not defined, use logged in user |
user.id | Number |
|
User ID must exist |
user.type | String |
|
User type ('mobile_users' or 'users') must exist |
params | Object |
|
Parameters used to get information from server (such as id) |
params.page | Object |
|
Pagination information |
params.page.number | Number |
|
Number of pages of data to get back |
params.page.size | Number |
|
Number of results per page to get back |
cacheMode | String |
|
Override the caching method for this call |
Throw:
If missing token or missing required parameters |
Example:
import { userService, FlowDataGroup } from 'clinical6';
userService.getDataGroup({ id: 24 });
const capturedValueGroup = new FlowDataGroup( {id: 24 });
userService.getDataGroup(capturedValueGroup);
Test:
- [unit] UserService.getDataGroup should have a getDataGroup method
- [unit] UserService.getDataGroup should throw an error when id is not defined
- [unit] UserService.getDataGroup should make a properly formatted get request
- [unit] UserService.getDataGroup should receive a valid response for a get request with an id and without filtering parameters
- [unit] UserService.getDataGroup should receive a valid response for a get request without an id or filtering parameters
- [unit] UserService.getDataGroup should receive a valid response for a get request without an id and with the filtering parameters
public async getEntries(user: Object, filters: Object, cacheMode: String): Promise<Entry[]|Entry> source
Get eDiary entries
Throw:
If missing token or missing required parameters |
Example:
import { mobileUserService, User } from 'clinical6';
// You can get entries using the `getEntries` method
mobileUserService.getEntries({ id: 5 }).then(entry => console.log(entry));
const filters = { entry_group_id: 7, date: '2018-06-02'};
mobileUserService.getEntries({ id: 5 }, filter).then(entry => console.log(entry));
// Additionally, you can do the same thing using `User.getEntries()`
const user = new User({ id: 5, ... });
user.getEntries().then(entry => console.log(entry));
user.getEntries(filter).then(entry => console.log(entry));
public async getInvitationStatus(user: User, attributes: Object, relationships: Object): Promise<User> source
Invite a user.
Params:
Name | Type | Attribute | Description |
user | User | The user in which to invite (required) |
|
user.email | String |
|
The email address of the invited user. (required) |
attributes | Object | A list of optional attributes not found in user or profile. This can contain any key/value. |
|
attributes.invitation_token | String | The token used for accepting an invitation |
|
relationships | Object |
|
A list of optional relationships not found in user or profile. This can contain any key/value. |
Throw:
If missing token or missing required parameters |
Example:
import { userService, User } from 'clinical6';
const user = new User({ email: 'john.brown@parallel6.com' });
let status = await userService.getInvitationStatus(user, { invitation_token: 'asdf1234' });
import { userService } from 'clinical6';
// first param will default to clinical6.user
let status = await userService.getInvitationStatus(undefined, { invitation_token: 'asdf1234' });
public async getNotifications(user: Object, cacheMode: String): Promise<Notification[] source
Get Notifications
Return:
Promise<Notification[] | Promise object that returns a list of Notifications |
Throw:
If missing token or missing required parameters |
Example:
import { mobileUserService, User } from 'clinical6';
// You can get entries using the `getNotifications` method
mobileUserService.getNotifications().then(notification => console.log(notification));
const user = new User({ id: 5, ... });
mobileUserService.getNotifications(user).then(notification => console.log(notification));
// Additionally, you can do the same thing using `User.getNotifications()`
const user = new User({ id: 5, ... });
user.getNotifications().then(notification => console.log(notification));
Test:
- [unit] UserService.getNotifications should throw an error when there is no user
- [unit] UserService.getNotifications should throw an error when there is no user id
- [unit] UserService.getNotifications should throw an error when there is no user type
- [unit] UserService.getNotifications should receive a valid response for a get request
public async getProfile(user: Object, cacheMode: String): Promise<Profile> source
Get the profile of a user (or current user if null).
Throw:
If missing token or missing required parameters |
Example:
import { mobileUserService, User } from 'clinical6';
// You will be able to access these mobile users using the `getProfile` method.
mobileUserService.getProfile().then(users => console.log(users));
// Additionally, you can retrieve the profile for a specific mobile user with the `getProfile`
// method, using the ID of the desired mobile user as a parameter.
mobileUserService.getProfile(new User({id: 23})).then(users => console.log(users));
// using the default `type`
mobileUserService.getProfile({id: 23}).then(users => console.log(users));
public getProfileAttributes(includeHidden: Boolean, includeValues: Boolean): Promise source
Gets all the custom attributes for the profile along with its values. This is here for ordering and labeling profile attributes.
Params:
Name | Type | Attribute | Description |
includeHidden | Boolean |
|
Optional parameter which determines whether the response should include the hidden attributes (Encrypted Data). |
includeValues | Boolean |
|
Optional parameter which determiens whether the response should include the existing values of each attribute. |
Throw:
If missing token |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.getProfileAttributes();
{
"status": "ok",
"content": [
{
"id": 2,
"api_key": "dummy_774",
"name": "dummy_773",
"attribute_type": "list",
"options": null,
"created_at": "2016-10-07T00:54:37.000Z",
"updated_at": "2016-10-07T00:54:37.000Z",
"is_visible": true,
"allow_multiple_values": null,
"is_recurrent_capture": false
},
{
"id": 3,
"api_key": "dummy_776",
"name": "dummy_775",
"attribute_type": "list",
"options": null,
"created_at": "2016-10-07T00:54:37.000Z",
"updated_at": "2016-10-07T00:54:37.000Z",
"is_visible": true,
"allow_multiple_values": null,
"is_recurrent_capture": false
},
{
"id": 4,
"api_key": "dummy_778",
"name": "dummy_777",
"attribute_type": "list",
"options": null,
"created_at": "2016-10-07T00:54:37.000Z",
"updated_at": "2016-10-07T00:54:37.000Z",
"is_visible": true,
"allow_multiple_values": null,
"is_recurrent_capture": false
}
],
"total_pages": 1
}
{
"status": "ok",
"content": [
{
"id": 14,
"api_key": "dummy_798",
"name": "dummy_797",
"attribute_type": "list",
"options": null,
"created_at": "2016-10-07T00:54:38.000Z",
"updated_at": "2016-10-07T00:54:38.000Z",
"is_visible": true,
"allow_multiple_values": null,
"is_recurrent_capture": false
},
{
"id": 15,
"api_key": "dummy_800",
"name": "dummy_799",
"attribute_type": "list",
"options": null,
"created_at": "2016-10-07T00:54:38.000Z",
"updated_at": "2016-10-07T00:54:38.000Z",
"is_visible": true,
"allow_multiple_values": null,
"is_recurrent_capture": false
},
{
"id": 16,
"api_key": "dummy_802",
"name": "dummy_801",
"attribute_type": "list",
"options": null,
"created_at": "2016-10-07T00:54:38.000Z",
"updated_at": "2016-10-07T00:54:38.000Z",
"is_visible": true,
"allow_multiple_values": null,
"is_recurrent_capture": false
},
{
"id": 17,
"api_key": "dummy_804",
"name": "dummy_803",
"attribute_type": "list",
"options": null,
"created_at": "2016-10-07T00:54:38.000Z",
"updated_at": "2016-10-07T00:54:38.000Z",
"is_visible": false,
"allow_multiple_values": null,
"is_recurrent_capture": false
},
{
"id": 18,
"api_key": "dummy_806",
"name": "dummy_805",
"attribute_type": "list",
"options": null,
"created_at": "2016-10-07T00:54:38.000Z",
"updated_at": "2016-10-07T00:54:38.000Z",
"is_visible": false,
"allow_multiple_values": null,
"is_recurrent_capture": false
},
{
"id": 19,
"api_key": "dummy_808",
"name": "dummy_807",
"attribute_type": "list",
"options": null,
"created_at": "2016-10-07T00:54:38.000Z",
"updated_at": "2016-10-07T00:54:38.000Z",
"is_visible": false,
"allow_multiple_values": null,
"is_recurrent_capture": false
}
],
"total_pages": 1
}
Test:
- [unit] UserService.getProfileAttributes should make a properly formatted GET request
- [unit] UserService.getProfileAttributes should make a properly formatted GET request with includeHidden parameter defined
- [unit] UserService.getProfileAttributes should make a properly formatted GET request with includeValues parameter defined
- [unit] UserService.getProfileAttributes should make a properly formatted GET request with both includeHidden and includeValues parameters defined
- [unit] UserService.getProfileAttributes should receive valid response for a get request
- [unit] UserService.getProfileAttributes should receive valid response for get request with includeHidden parameter
- [unit] UserService.getProfileAttributes should receive valid response for get request with both includeHidden and includeValues parameter
public async getRegistrationStatus(attributes: Object, meta: String): Promise<String> source
Returns the registration status of the user.
Example:
import { mobileUserService } from 'clinical6';
mobileUserService.getRegistrationStatus({ account_name: 'asdf' });
mobileUserService.getRegistrationStatus({ email: 'asdf@asdf.com'});
public getRelatedMobileUsers(): Promise<{followed_users: User[], followers: User[]}>{followed_users:> source
Retrieves all the related mobile users.
Return:
Promise<{followed_users: User[], followers: User[]}>{followed_users:> | Promise object that returns success or failure |
Throw:
If missing token |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.getRelatedMobileUsers().then(related => {
console.log('followed_users', related.followed_users);
console.log('followers', related.followers);
});
public async getSchedules(user: Object, cacheMode: String): Promise<Schedule[]|Schedule> source
Get Schedules for a user based on an id.
Params:
Name | Type | Attribute | Description |
user | Object |
|
User - if not defined, use logged in user |
user.id | Number |
|
User ID must exist |
user.type | String |
|
User type ('mobile_users' or 'users') must exist |
cacheMode | String |
|
Override the caching method for this call |
Throw:
If missing token or missing required parameters |
Example:
import { userService } from 'clinical6';
userService.getSchedules(); // current user
userService.getSchedules({ id: 24, type: 'mobile_users' }); // user with id 24
public async getSession(token: String, cacheMode: String): Promise source
Get the session of the logged in user.
Throw:
If token is not a string |
Example:
import { mobileUserService } from 'clinical6';
mobileUserService.getSession();
public async getSites(user: Object, cacheMode: String): Promise<Site[]|Site> source
Get User Sites
Params:
Name | Type | Attribute | Description |
user | Object |
|
The user, must have id and type |
user.id | Number |
|
The user id |
user.type | String |
|
User type ('mobile_users' or 'users') must exist |
cacheMode | String |
|
Override the caching method for this call |
Throw:
If missing token or missing required parameters |
Example:
import { mobileUserService, User } from 'clinical6';
// You can get entries using the `getSites` method
mobileUserService.getSites({ id: 5, type: 'mobile_users' }).then(sites => console.log(sites));
mobileUserService.getSites({ id: 5, type: 'mobile_users' }, filter).then(sites => console.log(sites));
// Additionally, you can do the same thing using `User.getSites()`
const user = new User({ id: 5, type: 'mobile_user', ... });
user.getSites().then(sites => console.log(sites));
user.getSites(filter).then(sites => console.log(sites));
public async insert(user: User, cacheMode: String): Promise<User> source
Call a POST request on the main obj.type expecting JSON API information.
Override:
JsonApiService#insertExample:
import { User, mobileUserService } from 'clinical6';
const user = new User({...});
// you can insert a user using the `insert` method.
mobileUserService.insert(mobileUser).then(user => console.log(user));
// you could also just call `save` on the user if it doesn't have an id, which will also
// invoke the `insert` method
user.save();
public async insertProfileAttribute(key: String, val: String | Number): Promise source
Inserts a new value for the given profile attribute.
Throw:
If missing token or missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.insertProfileAttribute('make', 'Toyota');
{
"status": "ok",
"id": 6,
"content": {
"id": 6,
"value": "new_value",
"profile_attribute_id": 23,
"profile_id": 150,
"created_at": "2016-10-07T00:54:38.460Z",
"updated_at": "2016-10-07T00:54:38.460Z",
"recurrent_capture_id": null,
"recurrent_capture_type": null
}
}
{
"error_detail": "This attribute has an existing value, use update method to overwrite it'",
"friendly_error": null,
"internal_code": 50367,
"more_info": "",
"status": "fail",
"message": null
}
public async invite(user: User, attributes: Object, relationships: Object): Promise<User> source
Invite a user.
Params:
Name | Type | Attribute | Description |
user | User | The user in which to invite (required) |
|
user.email | String |
|
The email address of the invited user. (required) |
user.profile | Profile | The user's profile that contains information like first name, last name, and phone |
|
user.role | String |
|
The user's role |
attributes | Object |
|
A list of optional attributes not found in user or profile. This can contain any key/value. |
attributes.invitation_token | String |
|
The token used for accepting an invitation |
attributes.password | String |
|
A password chosen for the user |
attributes.relationship | String |
|
A relationship of the user to patient ('father', 'mother', 'uncle', 'aunt', etc) |
relationships | Object |
|
A list of optional relationships not found in user or profile. This can contain any key/value. |
relationships.site | Site |
|
The user's site |
relationships.user_role | Role |
|
The user's role (especially used if not defined in the user object) |
relationships.language | Language |
|
The user's language (especially used if not defined in the user profile) |
Throw:
If missing token or missing required parameters |
Example:
import { userService, User } from 'clinical6';
const user = new User({ email: 'john.brown@parallel6.com' });
user.profile.firstName = 'John';
user.profile.lastName = 'Brown';
userService.invite(user);
import { userService, Site, Role, Language, User } from 'clinical6';
const user = new User({ email: 'john.brown@parallel6.com' });
user.profile.firstName = 'John';
user.profile.lastName = 'Brown';
userService.invite(user, {
invitation_token: 'asdf12124',
password: 'mypassword@1'
}, {
followed: new User({ id: 283 }),
language: new Language({ id: 43 }),
site: new Site({ id: 5 }),
user_role: new Role({ id: 23 })
});
Test:
- [unit] UserService.invite should exist
- [unit] UserService.invite should throw errors for invalid parameters
- [unit] UserService.invite should successfully invite mobile user with a mobile user object
- [unit] UserService.invite should successfully invite mobile user with a mobile user object and a site
- [unit] UserService.invite should successfully invite mobile user with a mobile user object and a dynamic profile
- [unit] UserService.invite should successfully invite admin user with a admin user object
- [unit] UserService.invite should successfully invite admin user with a admin user object and a role as a relationship
- [unit] UserService.invite should successfully invite admin user with a admin user object and a role as a relationship (Platform UI Error)
public async register(attributes: Object, device: Device): Promise<User> source
Register a device for guest, a username, or email
Params:
Name | Type | Attribute | Description |
attributes | Object | User object in which to insert |
|
attributes.guest | String |
|
Guest must be true or false (null) |
attributes.account_name | String |
|
Either use account name or email |
attributes.email | String |
|
Either use account name or email |
attributes.password | String |
|
Password must exist if guest is false |
device | Device |
|
Device with id to register |
Example:
import { mobileUserService } from 'clinical6';
const user = new User({...});
// you can register a guest using the `register` method.
mobileUserService.register({ guest: true }, device)
.then(user => console.log(user));
// Register using an account name
mobileUserService.register({ account_name: 'abc', password: 'asdf' }, device)
.then(user => console.log(user));
// Register using an email address
mobileUserService.register({ email: 'test@test.com', password: 'asdf' }, device)
.then(user => console.log(user));
public async removeAwardedBadge(awardedBadge: Object, cacheMode: String): Promise<AwardedBadge> source
Remove Awarded Badge
Params:
Name | Type | Attribute | Description |
awardedBadge | Object |
|
The mobile user, must have id |
awardedBadge.attributes | Object |
|
Hashmap to add for award badge |
awardedBadge.user | User |
|
The mobile user, must have id |
awardedBadge.user.id | Number |
|
The mobile user id |
awardedBadge.badge | Badge |
|
The mobile user, must have id |
awardedBadge.badge.id | Number |
|
The mobile user id |
cacheMode | String |
|
Override the caching method for this call |
Throw:
If missing token or missing required parameters |
Example:
import { userService, AwardedBadge, Badge, User } from 'clinical6';
const data = new AwardedBadge({ updatedAt: '2018-06-02' });
data.awardee = new User({ id: 5, ... });
data.badge = new Badge({ id: 5, ... });
// You can add an awarded badge using the `removeAwardedBadge` method
userService.removeAwardedBadge(data).then(data => console.log(data));
// Additionally, you can do the same thing using `User.removeAwardedBadge()`
user.removeAwardedBadge(badge).then(data => console.log(data));
public async requestPasswordReset(attributes: Object): Promise source
Starts the reset password process and sends an email to the user with instructions.
Throw:
If missing required parameters |
Example:
import { mobileUserService } from 'clinical6';
mobileUserService.requestPasswordReset({ email: 'test@test.com' });
mobileUserService.requestPasswordReset({ account_name: 'jsmith' });
import { userService } from 'clinical6';
userService.requestPasswordReset({ email: 'test@test.com' });
Test:
- [unit] UserService.requestPasswordReset should throw errors for invalid parameters
- [unit] UserService.requestPasswordReset should successfully requestPasswordReset mobile user with a mobile user object
- [unit] UserService.requestPasswordReset should throw an error if the email is invalid
- [unit] UserService.requestPasswordReset should throw errors for invalid parameters
- [unit] UserService.requestPasswordReset should successfully requestPasswordReset mobile user with a mobile user object
- [unit] UserService.requestPasswordReset should throw an error if the email is invalid
public resendInvite(id: Number, options: any): Promise source
Resends an invite to a related mobile user.
Params:
Name | Type | Attribute | Description |
id | Number |
|
The id of the related mobile user to resend the invite to. |
options | any |
|
Additional options submitted to the server |
Throw:
If missing token or missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.resendInvite(23);
import { userService } from 'clinical6';
userService.resendInvite(23, {});
public async resetPassword(attributes: Object, device: Device): Promise<User> source
Allows users to complete the Password reset flow.
Params:
Name | Type | Attribute | Description |
attributes | Object | The authorization object |
|
attributes.reset_password_token | String |
|
Token from request password reset email |
attributes.password | String |
|
New password to reset to. |
attributes.email | String |
|
Email to login. |
device | Device |
|
Reset with this device (Default to saved device). |
device.id | Number |
|
Reset with this device (Default to saved device). |
Throw:
If missing required parameters |
Example:
import { mobileUserService } from 'clinical6';
mobileUserService.resetPassword({ reset_password_token: 'a820348103828f8as0d8f', password: 'password1234'});
Test:
- [unit] UserService.resetPassword should throw errors for invalid parameters
- [unit] UserService.resetPassword should successfully resetPassword mobile user with correct attributes
- [unit] UserService.resetPassword should throw an error if the password token is invalid
- [unit] UserService.resetPassword should throw errors for invalid parameters
- [unit] UserService.resetPassword should throw an error if the password token is invalid
public resetPasswordSimple(newPassword: String, newPasswordConf: String, oldPassword: String): Promise source
Sends user's account name via email. This method does not require an access token.
Throw:
If missing token or missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.resetPasswordSimple('test', 'test', 'test2');
{
"error_detail": "Review the new_password and new_password_confirmation parameters",
"friendly_error": "Password and confirmation do not match",
"internal_code": 50362,
"more_info": "",
"status": "fail",
"message": "Password and confirmation do not match"
}
public async revokeConsent(user: User, cacheMode: String): Promise source
This method revokes the consent for a user.
Throw:
If missing required parameters |
public async saveProfile(param: Object, options: String): Promise<Profile> source
Update Profile
Params:
Name | Type | Attribute | Description |
param | Object |
|
The user or profile |
options | String |
|
Modify the nature of the call and response |
options.cacheMode | String |
|
Override the caching method for this call |
options.meta | Object |
|
Pass and retrieve through reference meta data |
Throw:
If missing token or missing required parameters |
Example:
import { mobileUserService, Profile, User } from 'clinical6';
// You can update a profile using the `saveProfile` method
// Update profile using the Current User, `clinical6.user`
mobileUserService.saveProfile().then(profile => console.log(profile));
// Update profile using a User object
const user1 = new User({ ... }); // user must have a related profile, which it does by default
mobileUserService.saveProfile(user1).then(profile => console.log(profile));
// Update profile using a Profile object
const profile = new Profile({ ... }); // profile must have a related user
mobileUserService.saveProfile(profile).then(profile => console.log(profile));
// Update profile using a Profile object and apply meta data
const profile = new Profile({ ... }); // profile must have a related user
mobileUserService.saveProfile(profile, { meta: { something: 23 }}).then(profile => console.log(profile));
// Updating just one attribute on the logged in user
mobileUserService.saveProfile({
profile: { zipCode: 51038 }
}).then(profile => console.log(profile));
// Updating just one attribute on a different user
const user2 = new User({ ... });
mobileUserService.saveProfile({
profile: { zipCode: 51038 },
user: user2
}).then(profile => console.log(profile));
// Additionally, you can do the same thing using `User.saveProfile()`
const user3 = new User({ ... }); // user must have a related profile, which it does by default
user3.saveProfile().then(profile => console.log(profile));
public async sendConfirmation(email: String): Promise source
Sends a confirmation email to an email address
Params:
Name | Type | Attribute | Description |
String | Email address to send the reset password email to. |
Throw:
If missing required parameters |
Example:
import { mobileUserService } from 'clinical6';
mobileUserService.sendConfirmation('test@test.com');
public setPin(json: Object): Promise source
Sets the pin value for an invited user. This method will set the initial value of a PIN. In some workflows it is also possible to specify account_name if it is pre-provisioned.
Throw:
If missing token or missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.setPin({
pin: 123456,
pin_confirmation: 123456
});
import { userService } from 'clinical6';
userService.setPin({
pin: 123456,
pin_confirmation: 123456,
account_name
});
public async signIn(attributes: Object, device: Device, cacheMode: String): Promise<Session> source
Sign in user with account name.
Params:
Name | Type | Attribute | Description |
attributes | Object | The authorization object |
|
attributes.account_name | String | Account name to login. |
|
attributes.email | String | Email to login. |
|
attributes.password | String | Login with this password. |
|
device | Device |
|
Login with this device (Default to saved device). |
cacheMode | String |
|
Override the caching method for this call |
Return:
Promise<Session> | Promise returning a session with a user and authenticationToken and logging in future calls |
Throw:
If missing required parameters |
Example:
import { mobileUserService } from 'clinical6';
mobileUserService.signIn({ account_name: 'jsmith', password: 'password1234'});
mobileUserService.signIn({ email: 'jsmith@gmail.com', password: 'password1234'});
public async signOut(): Promise source
Detaches the device from the mobile_user. If the current mobile_user is a guest, his information will be destroyed. After this method is executed the device won't have any access_token associated and won't be able to make other requests until it signs in. Destroys a user's session
This method does not require access token.
Test:
- [unit] UserService.signOut should clear the client authToken, device, and storage
- [unit] UserService.signOut should successfully sign out and remove auth token from client
- [unit] UserService.signOut should clear the client authToken, device, and storage
- [unit] UserService.signOut should successfully sign out and remove auth token from client
public signUp(username: String, password: String, profile: Object): Promise source
Sign up a user with a user profile. The Client#device fields uuid
, technology
,
version
, and pushId
are required to exist sign in to occur
In order to sign up for a new user account, profile information and credentials can be used to
execute the signUp
method:
Throw:
If missing required parameters and device info |
Decorators:
- deprecate
Example:
import { UserService } from 'clinical6';
const userService = new UserService();
userService.signUp(username, pw, profile).then(function(data){
// User is created and an authtotken is passed back
}, function(err){
// error
});
{
"status": "ok",
"auth_token": "93a46e8f956ea7be0cd6a087629e8550",
"verification_status": "unverified",
"encryption_key": "87206e2605a4bcfeb213e3c702c55190"
}
Test:
- [unit] UserService.signUp should throw an error when invalid arguments are passed
- [unit] UserService.signUp should reply with a friendly error message for missing/invalid credentials
- [unit] UserService.signUp should pass on an error message for a post request
- [unit] UserService.signUp should receive valid response for a post request
public async unlockUser(email: String, unlockToken: String): Promise source
Unlocks a user
Throw:
If missing required parameters |
Example:
import { mobileUserService } from 'clinical6';
mobileUserService.unlockUser('test@test.com', 'fakeToken123');
public update(user: User, options: String): Promise<User> source
Call a PATCH request on the main obj.type expecting JSON API information.
Override:
JsonApiService#updateExample:
import { User, mobileUserService } from 'clinical6';
const user = new User({...});
// you can update a user using the `update` method.
mobileUserService.update(user).then(user => console.log(user));
// you could also just call `save` on the user if it has an id, which will also
// invoke the `update` method
user.save();
public async updateAwardedBadge(awardedBadge: Object, cacheMode: String): Promise<AwardedBadge> source
Update Awarded Badge
Params:
Name | Type | Attribute | Description |
awardedBadge | Object |
|
The mobile user, must have id |
awardedBadge.attributes | Object |
|
Hashmap to add for award badge |
awardedBadge.user | User |
|
The mobile user, must have id |
awardedBadge.user.id | Number |
|
The mobile user id |
awardedBadge.badge | Badge |
|
The mobile user, must have id |
awardedBadge.badge.id | Number |
|
The mobile user id |
cacheMode | String |
|
Override the caching method for this call |
Throw:
If missing token or missing required parameters |
Example:
import { userService, AwardedBadge, Badge, User } from 'clinical6';
const data = new AwardedBadge({ updatedAt: '2018-06-02' });
data.awardee = new User({ id: 5, ... });
data.badge = new Badge({ id: 5, ... });
// You can update an awarded badge using the `updateAwardedBadge` method
userService.updateAwardedBadge(data).then(awardedBadge => console.log(awardedBadge));
// Additionally, you can do the same thing using `User.updateAwardedBadge()`
user.updateAwardedBadge(data).then(awardedBadge => console.log(awardedBadge));
public async updateProfileAttribute(profile: Object, id: Number): Promise source
Updates the profile information for the current, authenticated user.
Throw:
If missing token or missing required parameters |
Decorators:
- deprecate
Example:
import { userService } from 'clinical6';
userService.updateProfileAttribute({
"email": "test@test.com"
}, 23);
{
"status": "ok",
"id": 2,
"content": {
"id": 2,
"value": "new_value",
"profile_attribute_id": 20,
"profile_id": 146,
"created_at": "2016-10-07T00:54:38.000Z",
"updated_at": "2016-10-07T00:54:38.175Z",
"recurrent_capture_id": null,
"recurrent_capture_type": null
}
}
{
"error_detail": {
"ProfileValue": [
"not_found"
]
},
"friendly_error": "Profile value not found using the value:-1",
"internal_code": 50364,
"more_info": "",
"status": "fail",
"message": "Profile value not found using the value:-1"
}
Test:
- [unit] UserService.updateProfileAttribute should throw an error when there is no profile parameter
- [unit] UserService.updateProfileAttribute should throw an error when there is no id parameter
- [unit] UserService.updateProfileAttribute should successfully update a user profile attribute with a profile object and an id value
public async updateSchedule(schedule: Object, cacheMode: String): Promise<Schedule> source
Update Schedule
Params:
Name | Type | Attribute | Description |
schedule | Object |
|
The mobile user, must have id |
schedule.attributes | Object |
|
Hashmap to add for a schedule |
schedule.mobileUser | User |
|
The mobile user, must have id |
schedule.mobileUser.id | Number |
|
The mobile user id |
cacheMode | String |
|
Override the caching method for this call |
Throw:
If missing token or missing required parameters |
Example:
import { userService, Schedule } from 'clinical6';
const data = new Schedule({ updatedAt: '2018-06-02' });
// You can update a schedule using the `updateSchedule` method
userService.updateSchedule(data).then(schedule => console.log(schedule));
// Additionally, you can do the same thing using `User.updateSchedule()`
user.updateSchedule(data).then(schedule => console.log(schedule));
Private Methods
private _loginGetSession(response: Session | User, device: Device): Session source
Get and Login Session From Response