1 | var _ = require('underscore'),
|
2 | moment = require('moment'),
|
3 | Ack;
|
4 |
|
5 | Ack = (function() {
|
6 | function Ack(options) {
|
7 | options = options || {};
|
8 |
|
9 | if (options.message) {
|
10 | options.values = options.message.translate({
|
11 | sendingApplication: 'MSH|3',
|
12 | sendingFacility: 'MSH|4',
|
13 | receivingApplication: 'MSH|5',
|
14 | receivingFacility: 'MSH|6',
|
15 | messageControlId: 'MSH|10'
|
16 | });
|
17 | }
|
18 |
|
19 | options = _.defaults(options, {
|
20 | code: 'AA',
|
21 | subs: {},
|
22 | values: {}
|
23 | });
|
24 |
|
25 | options.values = _.defaults(options.values, {
|
26 | sendingApplication: '',
|
27 | sendingFacility: '',
|
28 | receivingApplication: '',
|
29 | receivingFacility: '',
|
30 | messageControlId: '',
|
31 | textMessage: ''
|
32 | });
|
33 |
|
34 | this.template = _.template([
|
35 | "MSH|^~\\&|<%=receivingApplication%>|<%=receivingFacility%>|<%=sendingApplication%>|<%=sendingFacility%>|<%=date%>||ACK^O01|<%=messageControlId%>|P|2.3",
|
36 | "MSA|<%=code%>|<%=messageControlId%>|<%=textMessage%>"
|
37 | ].join('\r'));
|
38 |
|
39 | _.extend(this, options);
|
40 | }
|
41 |
|
42 | Ack.prototype.toString = function() {
|
43 | var date = moment(this.subs.dateTimeOfMessage).format('YYYYMMDDHHmmss'),
|
44 | textMessage = this.subs.textMessage,
|
45 | data;
|
46 |
|
47 | data = _.clone(this.subs);
|
48 | data = _.defaults(data, this.values, {
|
49 | code: this.code,
|
50 | date: date
|
51 | });
|
52 |
|
53 | return this.template(data);
|
54 | };
|
55 |
|
56 | return Ack;
|
57 | })();
|
58 |
|
59 | module.exports = Ack;
|