fluent-cerner-js 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,238 @@
1
+ /**
2
+ * Options for a new order
3
+ * @param {boolean} isRxOrder Marks the order order as a prescription. Is mutually exclusive from
4
+ * isSatelliteOrder. Field will be set to false if left undefined; this resolves to 0 when built.
5
+ * @param {boolean} isSatelliteOrder Moarks the order origination as satellite. Is mutually
6
+ * exclusive from isRxOrder. Field will be set to false if left undefined; this resolves to 0 when built.
7
+ * @param {number} orderSentenceId The optional Cerner order_sentence_id to be associated with
8
+ * the new order. Field will be set to 0 if undefined.
9
+ * @param {number} nomenclatureId The optional Cerner nomenclature_id to be associated with the
10
+ * new order. Field will be set to 0 if undefined.
11
+ * @param {boolean} skipInteractionCheckUntilSign Determines cerner sign-time interaction
12
+ * checking. A value of true skips checking for interactions until orders are signed, false
13
+ * will not. Field will be set to false if left undefined; this resolves to 0 when built.
14
+ */
15
+ export type NewOrderOpts = {
16
+ isRxOrder?: boolean;
17
+ isSatelliteOrder?: boolean;
18
+ orderSentenceId?: number;
19
+ nomenclatureId?: number;
20
+ skipInteractionCheckUntilSign?: boolean;
21
+ };
22
+
23
+ export class MPageOrder {
24
+ private _orderAction: string = '';
25
+ getOrderAction = () => this._orderAction;
26
+
27
+ private _orderId: number = 0;
28
+ getOrderId = () => this._orderId;
29
+
30
+ private _synonymId: number = 0;
31
+ getSynonymId = () => this._synonymId;
32
+
33
+ private _orderOrigination: number = 0;
34
+ getOrderOrigination = () => this._orderOrigination;
35
+
36
+ private _orderSentenceId: number = 0;
37
+ getOrderSentenceId = () => this._orderSentenceId;
38
+
39
+ private _nomenclatureId: number = 0;
40
+ getNomenclatureId = () => this._nomenclatureId;
41
+
42
+ private _signTimeInteraction: number = 0;
43
+ getSignTimeInteraction = () => this._signTimeInteraction;
44
+
45
+ /**
46
+ * Creates a new MPageOrder with the order action 'ACTIVATE', which is the prototype for activating an existing future order.
47
+ *
48
+ * @since 0.1.0
49
+ * @category MPage Events - Orders
50
+ * @param {number} orderId The order id value for the order to activate.
51
+ * @returns {this} Returns itself to continue chaining method calls.
52
+ */
53
+ willActivate(orderId: number) {
54
+ this._orderAction = 'ACTIVATE';
55
+ this._orderId = orderId;
56
+ return this;
57
+ }
58
+ /**
59
+ * Creates a new MPageOrder with the order action 'CANCEL DC', which is the prototype for canceling and discontinuing an existing future order.
60
+ *
61
+ * @since 0.1.0
62
+ * @param {number} orderId The order id value for the order to activate.
63
+ * @returns {this} Returns itself to continue chaining method calls.
64
+ */
65
+ willCancelDiscontinue(orderId: number) {
66
+ this._orderAction = 'CANCEL DC';
67
+ this._orderId = orderId;
68
+ return this;
69
+ }
70
+ /**
71
+ * Creates a new MPageOrder with the order action 'CANCEL REORD', which is the prototype for cancelling and reordering an existing future order.
72
+ *
73
+ * @since 0.1.0
74
+ * @param {number} orderId The order id value for the order to activate.
75
+ * @returns {this} Returns itself to continue chaining method calls.
76
+ */
77
+ willCancelReorder(orderId: number) {
78
+ this._orderAction = 'CANCEL REORD';
79
+ this._orderId = orderId;
80
+ return this;
81
+ }
82
+ /**
83
+ * Creates a new MPageOrder with the order action 'CLEAR', which is the prototype for clearing actions of an existing future order.
84
+ *
85
+ * @since 0.1.0
86
+ * @param {number} orderId The order id value for the order to activate.
87
+ * @returns {this} Returns itself to continue chaining method calls.
88
+ */
89
+ willClear(orderId: number) {
90
+ this._orderAction = 'CLEAR';
91
+ this._orderId = orderId;
92
+ return this;
93
+ }
94
+ /**
95
+ * Creates a new MPageOrder with the order action 'CONVERT_INPAT', which is the prototype for converting a prescription order into an inpatient order.
96
+ *
97
+ * @since 0.1.0
98
+ * @param {number} orderId The order id value for the order to activate.
99
+ * @returns {this} Returns itself to continue chaining method calls.
100
+ */
101
+ willConvertInpatient(orderId: number) {
102
+ this._orderAction = 'CONVERT_INPAT';
103
+ this._orderId = orderId;
104
+ return this;
105
+ }
106
+ /**
107
+ * Creates a new MPageOrder with the order action 'CONVERT_RX', which is the prototype for converting an inpatient order into a prescription.
108
+ *
109
+ * @since 0.1.0
110
+ * @param {number} orderId The order id value for the order to activate.
111
+ * @returns {this} Returns itself to continue chaining method calls.
112
+ */
113
+ willConvertToPrescriptionOrder(orderId: number) {
114
+ this._orderAction = 'CONVERT_RX';
115
+ this._orderId = orderId;
116
+ return this;
117
+ }
118
+ /**
119
+ * Creates a new MPageOrder with the order action 'MODIFY', which is the prototype for modifying an existing future order.
120
+ *
121
+ * @since 0.1.0
122
+ * @param {number} orderId The order id value for the order to activate.
123
+ * @returns {this} Returns itself to continue chaining method calls.
124
+ */
125
+ willModify(orderId: number) {
126
+ this._orderAction = 'MODIFY';
127
+ this._orderId = orderId;
128
+ return this;
129
+ }
130
+ /**
131
+ * Creates a new MPage Order with order action 'ORDER'.
132
+ *
133
+ * @since 0.1.0
134
+ * @category MPage Events - Orders
135
+ * @param {number} synonymId The Cerner synonym_id to be associated with the new order. Must be set.
136
+ * @param {NewOrderOpts} options required when making a new order
137
+ * @returns {this} Returns itself to continue chaining method calls.
138
+ * default to a normal order type.
139
+ * @throws Error if `isRxOrder` and `isSatelliteOrder` are both set to true. These two are mutually exclusive and setting
140
+ * both creates underfined behavior with respect the order origination field.
141
+ * @example
142
+ * m.willMakeNewOrder(34, true, 13, 42, true).toString() => "{'ORDER'|34|5|1342|1}"
143
+ */
144
+
145
+ willMakeNewOrder(synonymId: number, opts?: NewOrderOpts) {
146
+ const {
147
+ isRxOrder,
148
+ isSatelliteOrder,
149
+ orderSentenceId,
150
+ nomenclatureId,
151
+ skipInteractionCheckUntilSign,
152
+ } = opts || {};
153
+
154
+ if (isRxOrder && isSatelliteOrder)
155
+ throw new Error('must select either isRxOrder or isSatelliteOrder');
156
+ this._orderAction = 'ORDER';
157
+ this._synonymId = synonymId;
158
+ this._orderSentenceId = orderSentenceId || 0;
159
+ this._nomenclatureId = nomenclatureId || 0;
160
+ this._signTimeInteraction = skipInteractionCheckUntilSign ? 1 : 0;
161
+ this._orderOrigination = isSatelliteOrder ? 5 : isRxOrder ? 1 : 0;
162
+
163
+ return this;
164
+ }
165
+
166
+ /**
167
+ * Creates a new MPageOrder with the order action 'RENEW', which is the prototype for reviewing an existing non-prescription order.
168
+ *
169
+ * @since 0.1.0
170
+ * @param {number} orderId The order id value for the order to activate.
171
+ * @returns {this} Returns itself to continue chaining method calls.
172
+ */
173
+ willRenewNonPrescription(orderId: number) {
174
+ this._orderAction = 'RENEW';
175
+ this._orderId = orderId;
176
+ return this;
177
+ }
178
+ /**
179
+ * Creates a new MPageOrder with the order action 'RENEW_RX', which is the prototype for renewing an existing prescription order.
180
+ *
181
+ * @since 0.1.0
182
+ * @param {number} orderId The order id value for the order to activate.
183
+ * @returns {this} Returns itself to continue chaining method calls.
184
+ */
185
+ willRenewPrescription(orderId: number) {
186
+ this._orderAction = 'RENEW_RX';
187
+ this._orderId = orderId;
188
+ return this;
189
+ }
190
+ /**
191
+ * Creates a new MPageOrder with the order action 'REPEAT', which is the prototype for copying an order.
192
+ *
193
+ * @since 0.1.0
194
+ * @param {number} orderId The order id value for the order to activate.
195
+ * @returns {this} Returns itself to continue chaining method calls.
196
+ */
197
+ willCopyExistingOrder(orderId: number) {
198
+ this._orderAction = 'REPEAT';
199
+ this._orderId = orderId;
200
+ return this;
201
+ }
202
+ /**
203
+ * Creates a new MPageOrder with the order action 'RESUME', which is the prototype for resuming a suspended order.
204
+ *
205
+ * @since 0.1.0
206
+ * @param {number} orderId The order id value for the order to activate.
207
+ * @returns {this} Returns itself to continue chaining method calls.
208
+ */
209
+ willResumeSuspendedOrder(orderId: number) {
210
+ this._orderAction = 'RESUME';
211
+ this._orderId = orderId;
212
+ return this;
213
+ }
214
+ /**
215
+ * Creates a new MPageOrder with the order action 'SUSPEND', which is the prototype for suspending an existing order.
216
+ *
217
+ * @since 0.1.0
218
+ * @param {number} orderId The order id value for the order to activate.
219
+ * @returns {this} Returns itself to continue chaining method calls.
220
+ */
221
+ willSuspend(orderId: number) {
222
+ this._orderAction = 'SUSPEND';
223
+ this._orderId = orderId;
224
+ return this;
225
+ }
226
+
227
+ /**
228
+ * Overrides the toString() method for representing the objects internal state as a string.
229
+ *
230
+ * @since 0.1.0
231
+ * @returns {string} string representation of MPageOrder's internal state
232
+ */
233
+ toString(): string {
234
+ return this._orderAction === 'ORDER'
235
+ ? `{${this._orderAction}|${this._synonymId}|${this._orderOrigination}|${this._orderSentenceId}|${this._nomenclatureId}|${this._signTimeInteraction}}`
236
+ : `{${this._orderAction}|${this._orderId}}`;
237
+ }
238
+ }
@@ -0,0 +1,126 @@
1
+ import { MPageOrder } from '.';
2
+
3
+ class MPageOrderEvent {
4
+ private _orders: Array<MPageOrder>;
5
+ getOrders = () => this._orders;
6
+
7
+ private _tabList: { tab: number; tabDisplayFlag: number } = {
8
+ tab: 0,
9
+ tabDisplayFlag: 0,
10
+ };
11
+ getTabList = () => this._tabList;
12
+
13
+ private _personId: number = 0;
14
+ getPersonId = () => this._personId;
15
+
16
+ private _encounterId: number = 0;
17
+ getEncounterId = () => this._encounterId;
18
+
19
+ private _powerPlanFlag: number = 0;
20
+ getPowerPlanFlag = () => this._powerPlanFlag;
21
+
22
+ private _defaultDisplay: number = 0;
23
+ getDefaultDisplay = () => this._defaultDisplay;
24
+
25
+ private _silentSignFlag: number = 0;
26
+ getSilentSignFlag = () => this._silentSignFlag;
27
+
28
+ constructor() {
29
+ this._orders = [];
30
+ this._tabList = { tab: 0, tabDisplayFlag: 0 };
31
+ // Disable PowerPlans by default
32
+ this._powerPlanFlag = 0;
33
+ // Disable PowerOrders by default
34
+ this._tabList.tabDisplayFlag = 0;
35
+ this.customizeOrderListProfile();
36
+ this.launchOrderProfile();
37
+ // Do NOT sign silently by default
38
+ this._silentSignFlag = 0;
39
+ }
40
+
41
+ forPerson(id: number) {
42
+ this._personId = id;
43
+ return this;
44
+ }
45
+
46
+ forEncounter(id: number) {
47
+ this._encounterId = id;
48
+ return this;
49
+ }
50
+
51
+ addOrders(orders: Array<MPageOrder> | MPageOrder) {
52
+ if (!Array.isArray(orders)) {
53
+ orders = [orders];
54
+ }
55
+ this._orders = this._orders.concat(orders);
56
+ return this;
57
+ }
58
+
59
+ enablePowerPlans() {
60
+ this._powerPlanFlag = 24;
61
+ return this;
62
+ }
63
+
64
+ customizeOrderListProfile() {
65
+ this._tabList.tab = 2;
66
+ return this;
67
+ }
68
+
69
+ customizeMedicationListProfile() {
70
+ this._tabList.tab = 3;
71
+ return this;
72
+ }
73
+
74
+ enablePowerOrders() {
75
+ this._tabList.tabDisplayFlag = 127;
76
+ return this;
77
+ }
78
+
79
+ launchOrderSearch() {
80
+ this._defaultDisplay = 8;
81
+ return this;
82
+ }
83
+
84
+ launchOrderProfile() {
85
+ this._defaultDisplay = 16;
86
+ return this;
87
+ }
88
+
89
+ launchOrdersForSignature() {
90
+ this._defaultDisplay = 32;
91
+ return this;
92
+ }
93
+
94
+ signSilently() {
95
+ this._silentSignFlag = 1;
96
+ return this;
97
+ }
98
+
99
+ send() {
100
+ try {
101
+ // @ts-ignore
102
+ w.MPAGES_EVENT('ORDERS', this.toString());
103
+ } catch (e) {
104
+ if (e instanceof ReferenceError) {
105
+ console.warn(
106
+ `We're likely not inside PowerChart. The output would be an MPAGES_EVENT: ${this.toString()}`
107
+ );
108
+ } else {
109
+ throw e;
110
+ }
111
+ }
112
+ }
113
+
114
+ toString(): string {
115
+ const head = `${this._personId}|${this._encounterId}|`;
116
+ let body: string = '';
117
+ this._orders.forEach(order => {
118
+ body += order.toString();
119
+ });
120
+ const tail = `|${this._powerPlanFlag}|{${this._tabList.tab}|${this._tabList.tabDisplayFlag}}|${this._defaultDisplay}|${this._silentSignFlag}`;
121
+
122
+ return `${head}${body}${tail}`;
123
+ }
124
+ }
125
+
126
+ export { MPageOrderEvent };
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { MPageOrderEvent } from './MPageOrderEvent';
2
+ import { MPageOrder, NewOrderOpts } from './MPageOrder';
3
+
4
+ export { MPageOrderEvent, MPageOrder, NewOrderOpts };