1 | var _ = require('underscore'),
|
2 | dateFormat = require('./date-format'),
|
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 | processingId: 'MSH|11',
|
17 | version: 'MSH|12'
|
18 | });
|
19 | }
|
20 |
|
21 | options = _.defaults(options, {
|
22 | code: 'AA',
|
23 | subs: {},
|
24 | values: {}
|
25 | });
|
26 |
|
27 | options.values = _.defaults(options.values, {
|
28 | sendingApplication: '',
|
29 | sendingFacility: '',
|
30 | receivingApplication: '',
|
31 | receivingFacility: '',
|
32 | messageControlId: '',
|
33 | processingId: '',
|
34 | version: '2.4',
|
35 | textMessage: ''
|
36 | });
|
37 |
|
38 | this.template = _.template([
|
39 | "MSH|^~\\&|<%=receivingApplication%>|<%=receivingFacility%>|<%=sendingApplication%>|<%=sendingFacility%>|<%=date%>||ACK^O01|<%=messageControlId%>|<%=processingId%>|<%=version%>",
|
40 | "MSA|<%=code%>|<%=messageControlId%>|<%=textMessage%>"
|
41 | ].join('\r'));
|
42 |
|
43 | _.extend(this, options);
|
44 | }
|
45 |
|
46 | Ack.prototype.toString = function() {
|
47 | var date = dateFormat(this.subs.dateTimeOfMessage),
|
48 | textMessage = this.subs.textMessage,
|
49 | data;
|
50 |
|
51 | data = _.clone(this.subs);
|
52 | data = _.defaults(data, this.values, {
|
53 | code: this.code,
|
54 | date: date
|
55 | });
|
56 |
|
57 | return this.template(data);
|
58 | };
|
59 |
|
60 | return Ack;
|
61 | })();
|
62 |
|
63 | module.exports = Ack;
|