UNPKG

elationjs

Version:

A node SDK for interacting with the Elation Health API

80 lines (65 loc) 2.24 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); const noteFactory = client => { var _class, _temp, _initialiseProps; return _temp = _class = class Note { constructor(input) { _initialiseProps.call(this); this.id = input.id; this.type = input.type; this.template = input.template; this.patient = input.patient; this.physician = input.physician; this.bullets = input.bullets; this.chart_date = input.chart_date; this.document_date = input.document_date; } static build(input) { const newNoteData = { type: input.type, template: input.template, patient: input.patient, physician: input.physician, bullets: input.bullets || [], chart_date: input.chart_date || new Date().toISOString(), document_date: input.document_date || new Date().toISOString() }; return new this(newNoteData); } static create(input) { const note = this.build(input); return this.postToElation(note); } static postToElation(note) { return client.post('visit_notes/', JSON.stringify(note)).then(({ data }) => new this(data)); } static getNote(id) { return client.get(`visit_notes/${id}`).then(({ data }) => new this(data)); } static findNotes(input) { const searchQString = Object.keys(input).reduce((qString, key) => qString.concat(input[key].map(data => `&${key}[]=${data}`).join('')), ''); return client.get(`visit_notes/${searchQString.replace(/^&/, '?')}`).then(({ data }) => data.results.map(note => new this(note))); } static delete(id) { return client.delete(`visit_notes/${id}`).then(() => ({ id, deleted: true })); } }, _initialiseProps = function () { this.addBullet = bullet => { this.bullets = this.bullets.concat(bullet); return this; }; this.removeBullet = idx => { this.bullets = idx > 0 ? [...this.bullets.slice(0, idx), ...this.bullets.slice(idx + 1)] : this.bullets.slice(idx + 1); return this; }; this.save = () => { return Note.postToElation(this); }; }, _temp; }; exports.default = noteFactory;