src/helpers/consult/ConsultationParticipant.js
import ConsultationParticipantModel from '../../models/consult/ConsultationParticipant';
import Helper from '../Helper';
import { aggregate } from '../../utilities/ClassUtility';
import { serviceFactory } from '../../utilities/factories/ServiceFactory';
/**
* Helper class representing a ConsultationParticipant.
*/
class ConsultationParticipant extends aggregate(ConsultationParticipantModel, Helper) {
/**
* Constructor for helper class representing an Video Consultation
*
* @param {Object} json - json api response from server
*/
constructor(json = {}) {
super(json);
this.deserializeRelationshipStubs(json);
this.syncRelationships(json);
}
/** @type {String} - The type */
static get type() {
return 'video_consultation_participants';
}
/** @type {Consultation} */
get consultation() {
return this._relationships.video_consultation;
}
/** @type {Consultation} */
set consultation(Consultation) {
/** @type {Consultation} */
this._relationships.video_consultation = Consultation;
}
/** @type {User} */
get user() {
return this._relationships.participant;
}
/** @type {User} */
set user(participant) {
/** @type {User} */
this._relationships.participant = participant;
}
/**
* Deletes a consultation
* @return {Promise} - Returns a promise via ajax call.
*
* @example
* import { ConsultationParticipant, Client } from 'clinical6';
*
* // Removes consultation from server and local storage
* const consultation = new ConsultationParticipant({...});
* consultation.delete();
*
* // No longer in storage
* Client.instance.storageUtility.has('consultations', { id: 1 });
*/
delete() {
const service = serviceFactory.get(this.type);
return service.delete(this);
}
/**
* Saves a video consultation (insert if id doesn't exist, update if it does)
* @return {Promise<ConsultationParticipant>} - Returns a promise via ajax call.
*
* @example
* import { ConsultationParticipant, clinical6 } from 'clinical6';
*
* // Inserts new role (no existing id)
* const consultation = new ConsultationParticipant({
* "data": {
* "type": "video_consultation_participants",
* "attributes": {},
* "relationships": {
* "video_consultation": {
* "data": {
* "id": 18,
* "type": "video_consultations"
* }
* },
* "participant": {
* "data": {
* "id": 527,
* "type": "mobile_users"
* }
* }
* }
* }
* });
* consultation.save();
* // Updates existing consultation if it has an existing id
*/
async save() {
const service = serviceFactory.get(this.type);
return (this.id) ? service.update(this) : service.insert(this);
}
}
export default ConsultationParticipant;