Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add check for undefined

  • Loading branch information...
commit a66cd29f36f6fcf7e240e68ad7129ab970285d89 1 parent 9c5b767
Gradus Parnassum authored
1  .gitignore
... ...
@@ -1,2 +1,3 @@
1 1
 node_modules
2 2
 .DS_Store
  3
+npm-debug.log
145  lib/index.js
... ...
@@ -1,65 +1,110 @@
1 1
 (function() {
2  
-  var JsonCsv,
3  
-    __hasProp = Object.prototype.hasOwnProperty,
4  
-    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
  2
+  var JsonCsv;
5 3
 
6  
-  JsonCsv = (function(_super) {
  4
+  JsonCsv = (function() {
7 5
 
8  
-    __extends(JsonCsv, _super);
9  
-
10  
-    function JsonCsv() {
11  
-      JsonCsv.__super__.constructor.apply(this, arguments);
12  
-    }
  6
+    function JsonCsv() {}
13 7
 
14 8
     JsonCsv.prototype.parse = function(data, cb) {
15 9
       var csv, i, index, json, line;
16 10
       if (data == null) return cb('error no data');
17 11
       json = JSON.parse(data);
18  
-      delete json['_events'];
19 12
       csv = '';
  13
+      line = 'FROM DATE, THRU DATE, CARRIER ID, ACCOUNT ID, GROUP ID, FACILITY ID, MEMBER ID, MEMBER First Name, MEMBER Last Name, PRESC ID, PCP ID, PRESC NAME, PHARMACY, RX #, DATE DISP, REFILL, DRUG NAME, NDC, #DAYS SUP, Decimal QTY, SUBMITTED COST, APPROVED COST, OPAR, FEE, INC FEE, TAX, PAT PAY, MGMT FEE, AMOUNT PAID, batch_name, billing_period, disp_ndc, cost, patientId, awp, aac, medication_type, prescription_type, Status\r\n';
20 14
       i = 0;
21 15
       while (i < json.length) {
22  
-        line = 'FROM DATE, THRU DATE, CARRIER ID, ACCOUNT ID, GROUP ID, FACILITY ID, MEMBER ID, MEMBER First Name, MEMBER Last Name, PRESC ID, PCP ID, PRESC NAME, PHARMACY, RX #, DATE DISP, REFILL, DRUG NAME, NDC, #DAYS SUP, Decimal QTY, SUBMITTED COST, APPROVED COST, OPAR, FEE, INC FEE, TAX, PAT PAY, MGMT FEE, AMOUNT PAID, batch_name, billing_period, disp_ndc, cost, patientId, awp, aac, medication_type, prescription_type, Status\r\n';
23 16
         for (index in json[i]) {
24 17
           if (typeof json[i][index] === 'object') {
25  
-            line += json[i][index]['FROM DATE'] + ",";
26  
-            line += json[i][index]['THRU DATE'] + ",";
27  
-            line += json[i][index]['CARRIER ID'] + ",";
28  
-            line += json[i][index]['ACCOUNT ID'] + ",";
29  
-            line += json[i][index]['GROUP ID'] + ",";
30  
-            line += json[i][index]['FACILITY ID'] + ",";
31  
-            line += json[i][index]['MEMBER ID'] + ",";
32  
-            line += json[i][index]['MEMBER First Name'] + ",";
33  
-            line += json[i][index]['MEMBER Last Name'] + ",";
34  
-            line += json[i][index]['PRESC ID'] + ",";
35  
-            line += json[i][index]['PCP ID'] + ",";
36  
-            line += json[i][index]['PRESC NAME'] + ",";
37  
-            line += json[i][index]['PHARMACY'] + ",";
38  
-            line += json[i][index]['RX #'] + ",";
39  
-            line += json[i][index]['DATE DISP'] + ",";
40  
-            line += json[i][index]['REFILL'] + ",";
41  
-            line += json[i][index]['DRUG NAME'] + ",";
42  
-            line += json[i][index]['NDC'] + ",";
43  
-            line += json[i][index]['#DAYS SUP'] + ",";
44  
-            line += json[i][index]['Decimal QTY'] + ",";
45  
-            line += json[i][index]['SUBMITTED COST'] + ",";
46  
-            line += json[i][index]['APPROVED COST'] + ",";
47  
-            line += json[i][index]['OPAR'] + ",";
48  
-            line += json[i][index]['FEE'] + ",";
49  
-            line += json[i][index]['INC FEE'] + ",";
50  
-            line += json[i][index]['TAX'] + ",";
51  
-            line += json[i][index]['PAT PAY'] + ",";
52  
-            line += json[i][index]['MGMT FEE'] + ",";
53  
-            line += json[i][index]['AMOUNT PAID'] + ",";
54  
-            line += json[i][index]['batch_name'] + ",";
55  
-            line += json[i][index]['billing_period'] + ",";
56  
-            line += json[i][index]['disp_ndc'] + ",";
57  
-            line += json[i][index]['cost'] + ",";
58  
-            line += json[i][index]['patientId'] + ",";
59  
-            line += json[i][index]['awp'] + ",";
60  
-            line += json[i][index]['aac'] + ",";
61  
-            line += json[i][index]['medication_type'] + ",";
62  
-            line += json[i][index]['prescription_type'] + ",";
  18
+            if (json[i][index]['FROM DATE']) {
  19
+              line += json[i][index]['FROM DATE'] + ",";
  20
+            }
  21
+            if (json[i][index]['THRU DATE']) {
  22
+              line += json[i][index]['THRU DATE'] + ",";
  23
+            }
  24
+            if (json[i][index]['CARRIER ID']) {
  25
+              line += json[i][index]['CARRIER ID'] + ",";
  26
+            }
  27
+            if (json[i][index]['ACCOUNT ID']) {
  28
+              line += json[i][index]['ACCOUNT ID'] + ",";
  29
+            }
  30
+            if (json[i][index]['GROUP ID']) {
  31
+              line += json[i][index]['GROUP ID'] + ",";
  32
+            }
  33
+            if (json[i][index]['FACILITY ID']) {
  34
+              line += json[i][index]['FACILITY ID'] + ",";
  35
+            }
  36
+            if (json[i][index]['MEMBER ID']) {
  37
+              line += json[i][index]['MEMBER ID'] + ",";
  38
+            }
  39
+            if (json[i][index]['MEMBER First Name']) {
  40
+              line += json[i][index]['MEMBER First Name'] + ",";
  41
+            }
  42
+            if (json[i][index]['MEMBER Last Name']) {
  43
+              line += json[i][index]['MEMBER Last Name'] + ",";
  44
+            }
  45
+            if (json[i][index]['PRESC ID']) {
  46
+              line += json[i][index]['PRESC ID'] + ",";
  47
+            }
  48
+            if (json[i][index]['PCP ID']) line += json[i][index]['PCP ID'] + ",";
  49
+            if (json[i][index]['PRESC NAME']) {
  50
+              line += json[i][index]['PRESC NAME'] + ",";
  51
+            }
  52
+            if (json[i][index]['PHARMACY']) {
  53
+              line += json[i][index]['PHARMACY'] + ",";
  54
+            }
  55
+            if (json[i][index]['RX #']) line += json[i][index]['RX #'] + ",";
  56
+            if (json[i][index]['DATE DISP']) {
  57
+              line += json[i][index]['DATE DISP'] + ",";
  58
+            }
  59
+            if (json[i][index]['REFILL']) line += json[i][index]['REFILL'] + ",";
  60
+            if (json[i][index]['DRUG NAME']) {
  61
+              line += json[i][index]['DRUG NAME'] + ",";
  62
+            }
  63
+            if (json[i][index]['NDC']) line += json[i][index]['NDC'] + ",";
  64
+            if (json[i][index]['#DAYS SUP']) {
  65
+              line += json[i][index]['#DAYS SUP'] + ",";
  66
+            }
  67
+            if (json[i][index]['Decimal QTY']) {
  68
+              line += json[i][index]['Decimal QTY'] + ",";
  69
+            }
  70
+            if (json[i][index]['SUBMITTED COST']) {
  71
+              line += json[i][index]['SUBMITTED COST'] + ",";
  72
+            }
  73
+            if (json[i][index]['APPROVED COST']) {
  74
+              line += json[i][index]['APPROVED COST'] + ",";
  75
+            }
  76
+            if (json[i][index]['OPAR']) line += json[i][index]['OPAR'] + ",";
  77
+            if (json[i][index]['FEE']) line += json[i][index]['FEE'] + ",";
  78
+            if (json[i][index]['INC FEE']) line += json[i][index]['INC FEE'] + ",";
  79
+            if (json[i][index]['TAX']) line += json[i][index]['TAX'] + ",";
  80
+            if (json[i][index]['PAT PAY']) line += json[i][index]['PAT PAY'] + ",";
  81
+            if (json[i][index]['MGMT FEE']) {
  82
+              line += json[i][index]['MGMT FEE'] + ",";
  83
+            }
  84
+            if (json[i][index]['AMOUNT PAID']) {
  85
+              line += json[i][index]['AMOUNT PAID'] + ",";
  86
+            }
  87
+            if (json[i][index]['batch_name']) {
  88
+              line += json[i][index]['batch_name'] + ",";
  89
+            }
  90
+            if (json[i][index]['billing_period']) {
  91
+              line += json[i][index]['billing_period'] + ",";
  92
+            }
  93
+            if (json[i][index]['disp_ndc']) {
  94
+              line += json[i][index]['disp_ndc'] + ",";
  95
+            }
  96
+            if (json[i][index]['cost']) line += json[i][index]['cost'] + ",";
  97
+            if (json[i][index]['patientId']) {
  98
+              line += json[i][index]['patientId'] + ",";
  99
+            }
  100
+            if (json[i][index]['awp']) line += json[i][index]['awp'] + ",";
  101
+            if (json[i][index]['aac']) line += json[i][index]['aac'] + ",";
  102
+            if (json[i][index]['medication_type']) {
  103
+              line += json[i][index]['medication_type'] + ",";
  104
+            }
  105
+            if (json[i][index]['prescription_type']) {
  106
+              line += json[i][index]['prescription_type'] + ",";
  107
+            }
63 108
           } else {
64 109
             line += json[i][index];
65 110
           }
@@ -73,7 +118,7 @@
73 118
 
74 119
     return JsonCsv;
75 120
 
76  
-  })(require('events').EventEmitter);
  121
+  })();
77 122
 
78 123
   module.exports = new JsonCsv();
79 124
 
85  src/index.coffee
... ...
@@ -1,7 +1,7 @@
1 1
 # jsoncsv
2 2
 # simple json to csv converter
3 3
 
4  
-class JsonCsv extends require('events').EventEmitter
  4
+class JsonCsv
5 5
   # parse JSON data and return csv output
6 6
   # callback returns (err, row)
7 7
 
@@ -9,58 +9,57 @@ class JsonCsv extends require('events').EventEmitter
9 9
     return cb('error no data') unless data?
10 10
 
11 11
     json = JSON.parse(data)
12  
-    delete json['_events']
13 12
     csv = ''
  13
+    line = 'FROM DATE, THRU DATE, CARRIER ID, ACCOUNT ID, GROUP ID, FACILITY ID, MEMBER ID, MEMBER First Name, MEMBER Last Name, PRESC ID, PCP ID, PRESC NAME, PHARMACY, RX #, DATE DISP, REFILL, DRUG NAME, NDC, #DAYS SUP, Decimal QTY, SUBMITTED COST, APPROVED COST, OPAR, FEE, INC FEE, TAX, PAT PAY, MGMT FEE, AMOUNT PAID, batch_name, billing_period, disp_ndc, cost, patientId, awp, aac, medication_type, prescription_type, Status\r\n'
14 14
     i = 0
15  
-
16 15
     while i < json.length
17  
-      line = 'FROM DATE, THRU DATE, CARRIER ID, ACCOUNT ID, GROUP ID, FACILITY ID, MEMBER ID, MEMBER First Name, MEMBER Last Name, PRESC ID, PCP ID, PRESC NAME, PHARMACY, RX #, DATE DISP, REFILL, DRUG NAME, NDC, #DAYS SUP, Decimal QTY, SUBMITTED COST, APPROVED COST, OPAR, FEE, INC FEE, TAX, PAT PAY, MGMT FEE, AMOUNT PAID, batch_name, billing_period, disp_ndc, cost, patientId, awp, aac, medication_type, prescription_type, Status\r\n'
18 16
       for index of json[i]
19 17
         if typeof(json[i][index]) == 'object'
20  
-          line += json[i][index]['FROM DATE'] + ","
21  
-          line += json[i][index]['THRU DATE'] + ","
22  
-          line += json[i][index]['CARRIER ID'] + ","
23  
-          line += json[i][index]['ACCOUNT ID'] + ","
24  
-          line += json[i][index]['GROUP ID'] + ","
25  
-          line += json[i][index]['FACILITY ID'] + ","
26  
-          line += json[i][index]['MEMBER ID'] + ","
27  
-          line += json[i][index]['MEMBER First Name'] + ","
28  
-          line += json[i][index]['MEMBER Last Name'] + ","
29  
-          line += json[i][index]['PRESC ID'] + ","
30  
-          line += json[i][index]['PCP ID'] + ","
31  
-          line += json[i][index]['PRESC NAME'] + ","
32  
-          line += json[i][index]['PHARMACY'] + ","
33  
-          line += json[i][index]['RX #'] + ","
34  
-          line += json[i][index]['DATE DISP'] + ","
35  
-          line += json[i][index]['REFILL'] + ","
36  
-          line += json[i][index]['DRUG NAME'] + ","
37  
-          line += json[i][index]['NDC'] + ","
38  
-          line += json[i][index]['#DAYS SUP'] + ","
39  
-          line += json[i][index]['Decimal QTY'] + ","
40  
-          line += json[i][index]['SUBMITTED COST'] + ","
41  
-          line += json[i][index]['APPROVED COST'] + ","
42  
-          line += json[i][index]['OPAR'] + ","
43  
-          line += json[i][index]['FEE'] + ","
44  
-          line += json[i][index]['INC FEE'] + ","
45  
-          line += json[i][index]['TAX'] + ","
46  
-          line += json[i][index]['PAT PAY'] + ","
47  
-          line += json[i][index]['MGMT FEE'] + ","
48  
-          line += json[i][index]['AMOUNT PAID'] + ","
49  
-          line += json[i][index]['batch_name'] + ","
50  
-          line += json[i][index]['billing_period'] + ","
51  
-          line += json[i][index]['disp_ndc'] + ","
52  
-          line += json[i][index]['cost'] + ","
53  
-          line += json[i][index]['patientId'] + ","
54  
-          line += json[i][index]['awp'] + ","
55  
-          line += json[i][index]['aac'] + ","
56  
-          line += json[i][index]['medication_type'] + ","
57  
-          line += json[i][index]['prescription_type'] + ","
  18
+          line += json[i][index]['FROM DATE'] + "," if json[i][index]['FROM DATE']
  19
+          line += json[i][index]['THRU DATE'] + "," if json[i][index]['THRU DATE']
  20
+          line += json[i][index]['CARRIER ID'] + "," if json[i][index]['CARRIER ID']
  21
+          line += json[i][index]['ACCOUNT ID'] + "," if json[i][index]['ACCOUNT ID']
  22
+          line += json[i][index]['GROUP ID'] + "," if json[i][index]['GROUP ID']
  23
+          line += json[i][index]['FACILITY ID'] + "," if json[i][index]['FACILITY ID']
  24
+          line += json[i][index]['MEMBER ID'] + "," if json[i][index]['MEMBER ID']
  25
+          line += json[i][index]['MEMBER First Name'] + "," if json[i][index]['MEMBER First Name']
  26
+          line += json[i][index]['MEMBER Last Name'] + "," if json[i][index]['MEMBER Last Name']
  27
+          line += json[i][index]['PRESC ID'] + "," if json[i][index]['PRESC ID']
  28
+          line += json[i][index]['PCP ID'] + "," if json[i][index]['PCP ID']
  29
+          line += json[i][index]['PRESC NAME'] + "," if json[i][index]['PRESC NAME']
  30
+          line += json[i][index]['PHARMACY'] + "," if json[i][index]['PHARMACY']
  31
+          line += json[i][index]['RX #'] + "," if json[i][index]['RX #']
  32
+          line += json[i][index]['DATE DISP'] + "," if json[i][index]['DATE DISP']
  33
+          line += json[i][index]['REFILL'] + "," if json[i][index]['REFILL']
  34
+          line += json[i][index]['DRUG NAME'] + "," if json[i][index]['DRUG NAME']
  35
+          line += json[i][index]['NDC'] + "," if json[i][index]['NDC']
  36
+          line += json[i][index]['#DAYS SUP'] + "," if json[i][index]['#DAYS SUP']
  37
+          line += json[i][index]['Decimal QTY'] + "," if json[i][index]['Decimal QTY']
  38
+          line += json[i][index]['SUBMITTED COST'] + "," if json[i][index]['SUBMITTED COST']
  39
+          line += json[i][index]['APPROVED COST'] + "," if json[i][index]['APPROVED COST']
  40
+          line += json[i][index]['OPAR'] + "," if json[i][index]['OPAR']
  41
+          line += json[i][index]['FEE'] + "," if json[i][index]['FEE']
  42
+          line += json[i][index]['INC FEE'] + "," if json[i][index]['INC FEE']
  43
+          line += json[i][index]['TAX'] + "," if json[i][index]['TAX']
  44
+          line += json[i][index]['PAT PAY'] + "," if json[i][index]['PAT PAY']
  45
+          line += json[i][index]['MGMT FEE'] + "," if json[i][index]['MGMT FEE']
  46
+          line += json[i][index]['AMOUNT PAID'] + "," if json[i][index]['AMOUNT PAID']
  47
+          line += json[i][index]['batch_name'] + "," if json[i][index]['batch_name']
  48
+          line += json[i][index]['billing_period'] + "," if json[i][index]['billing_period']
  49
+          line += json[i][index]['disp_ndc'] + "," if json[i][index]['disp_ndc']
  50
+          line += json[i][index]['cost'] + "," if json[i][index]['cost']
  51
+          line += json[i][index]['patientId'] + "," if json[i][index]['patientId']
  52
+          line += json[i][index]['awp'] + "," if json[i][index]['awp']
  53
+          line += json[i][index]['aac'] + "," if json[i][index]['aac']
  54
+          line += json[i][index]['medication_type'] + "," if json[i][index]['medication_type']
  55
+          line += json[i][index]['prescription_type'] + "," if json[i][index]['prescription_type']
58 56
         else
59 57
           line += json[i][index]
60 58
       line.slice 0, line.Length - 1
61 59
       csv += line + "\r\n"
62 60
       i++
63  
-
64 61
     return cb(null, csv)
65 62
 
66 63
 module.exports = new JsonCsv()
  64
+
  65
+

0 notes on commit a66cd29

Please sign in to comment.
Something went wrong with that request. Please try again.