-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv-test.js
More file actions
255 lines (228 loc) · 13.2 KB
/
csv-test.js
File metadata and controls
255 lines (228 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const htmlencode = require('htmlencode').htmlEncode;
const csvWriter = createCsvWriter({
path: 'out.csv',
//header
header: [
{ id: 'id', title: 'IDissue' },
{ id: 'title', title: 'Title'},
{ id: 'status', title: 'Status'},
{ id: 'category', title: 'Category'},
{ id: 'type', title: 'Type'},
{ id: 'description', title: 'Description' },
{ id: 'analysis', title: 'Analysis'},
{ id: 'conversion', title: 'ConversionDesc'},
{ id: 'origin', title: 'Origin'},
{ id: 'synopsis', title: 'Synopsis'},
{ id: 'currentSetup', title: 'CurrentSetup'},
{ id: 'assigned', title: 'Assigned' },
{ id: 'reviewer', title: 'Reviewer' },
{ id: 'facilitator', title: 'Facilitator'},
{ id: 'reportedDate', title: 'ReportedDate'},
]
});
//setup connection
const knex = require('knex')({
client: 'mssql',
connection: {
host: '172.25.0.226',
user: 'CAPA_webuser',
password: 'CaPa',
database: 'CAPA'
}
});
let objectArray = [];
checkForNulls = (item) => {
for(let i in item)
{
if(item[i] === null)
item[i] = '';
}
}
knex.select().from('LogIssue').orderBy('IDissue', 'desc').where('Status','Complete')
//.andWhere('IDissue', '<', 283)
.andWhereNot('IDissue', 364)
.andWhereNot('IDissue', 362)
.andWhereNot('IDissue', 350)
.andWhereNot('IDissue', 338)
//.limit(10)
//381-366
//corrupt 364
.then(async (rows) => {
for (let item of rows) {
checkForNulls(item);
id = item.IDissue;
title = item.GenInfoTitle;
status = item.Status;
category = item.GenInfoCategory;
type = item.GenInfoType;
item.GenInfoDescription !== '' ? description = htmlencode(item.GenInfoDescription) : '';
analysis = item.RcaAnalysis;
conversion = `<b>GENERAL INFORMATION</b><br><br><br>`
conversion += `<b>CAPA ID#:</b> ${item.IDissue}<br><br>`;
conversion += `<b>Entered By:</b> ${item.GenInfoEnteredBy} @ ${item.GenInfoEnteredTime}<br><br>`;
conversion += `<b>Last Edit By:</b> ${item.GenInfoEditBy} @ ${item.GenInfoEditTime}<br><br>`;
conversion += `<b>Source:</b> ${item.GenInfoSource}<br><br>`;
conversion += `<b>Category:</b> ${item.GenInfoCategory}<br><br>`;
conversion += `<b>Scope:</b> ${item.GenInfoScope}<br><br>`;
// conversion += `"<b>Responsible:</b> ${item.GenInfoSource}<br><br>`;
await knex.select().from('LogIssueResponsible').where('IDissue', item.IDissue)
.then((rows) => {
let responsibleString = '';
if (rows.length > 0) {
responsibleString = '<b>Responsible:</b> ';
let comma = '';
for (let x of rows) {
responsibleString += `${comma}${x.GenInfoResponsible}`;
comma = ', ';
}
}
responsibleString !== '' ? conversion += `${responsibleString}<br><br>` : conversion += '';
});
conversion += `<b>Risk Evaluation:</b> ${item.GenInfoRisk.replace(/"/g,"'")}<br><br>`;
conversion += `<b>MDR #:</b> <a href="${item.MdrLink}">${item.MdrNumber}</a><br><br>`;
conversion += `<b>MDR Due Date:</b> ${item.MdrDueDate}<br><br>`;
conversion += `<b>Correction Report #:</b> <a href="${item.CorrectionReportLink}">${item.CorrectionReportNumber}</a><br><br>`;
conversion += `<b>Correction Report Due Date:</b> ${item.CorrectionReporDueDate}<br><br>`;
// Associated Audit Findings
// Related CAPAs
await knex.select().from('LogIssueRelated').where('IDissue', item.IDissue)
.then((rows) => {
let relatedString = '';
if (rows.length > 0) {
relatedString = '<b>Related CAPA Issues:</b> ';
let comma = '';
for (let x of rows) {
relatedString += `${comma}<a href="http://magicweb/CAPA/IssueDisplay.asp?ID=${x.IDrelated}">${x.IDrelated}</a>`;
comma = ', ';
}
}
relatedString !== '' ? conversion += `${relatedString}<br><br>` : conversion += '';
});
origin = `<b>APPRAISAL SUMMARY</b><br><br><br>`;
item.ApprovalFiledBy ? origin += `<b>Filed By:</b> ${item.AppraisalFiledBy} @ ${item.AppraisalFiledTime}<br><br>` : '';
item.AppraisalResearch !== '' ? origin += `<b>Research Notes:</b> ${item.AppraisalResearch.replace(/"/g,"'")}<br><br>` : origin += '';
item.AppraisalImpact !== '' ? origin += `<b>Is there impact and risk to the overall quality system?</b> ${item.AppraisalImpact.replace(/"/g,"'")}<br><br>` : origin += '';
item.AppraisalAction !== '' ? origin += `<b>What immediate or remedial action was taken?</b> ${item.AppraisalAction.replace(/"/g,"'")}<br><br>` : origin += '';
item.AppraisalResolve !== '' ? origin += `<b>Did the action resolve the issue?</b> ${item.AppraisalResolve.replace(/"/g,"'")}<br><br>` : origin += '';
item.AppraisalOther !== '' ? origin += `<b>What, if any, other action will be taken?</b> ${item.AppraisalOther.replace(/"/g,"'")}<br><br>` : origin += '';
origin += `<br><b>ROOT CAUSE ANALYSIS</b><br><br><br>`;
item.RcaFiledBy ? origin += `<b>Filed By:</b> ${item.RcaFiledBy} @ ${item.RcaFiledTime}<br><br>` : '';
item.RcaScope !== '' ? origin += `<b>Scope:</b> ${item.RcaScope.replace(/"/g,"'")}<br><br>` : origin += '';
item.RcaSummary !== '' ? origin += `<b>Historical Summary:</b> ${item.RcaSummary.replace(/"/g,"'")}<br><br>` : origin += '';
item.RcaCause !== '' ? origin += `<b>Cause of Issue:</b> ${item.RcaCause.replace(/"/g,"'")}<br><br>` : origin += '';
item.RcaDocumentation !== '' ? origin += `<b>Documentation:</b> ${item.RcaDocumentation.replace(/"/g,"'")}<br><br>` : origin += '';
await knex.select().from('LogIssueRcaStaff').where('IDissue', item.IDissue)
.then((rows) => {
let relatedString = '';
if (rows.length > 0) {
relatedString = '<b>Staff:</b> ';
let comma = '';
for (let x of rows) {
relatedString += `${comma}${x.RcaStaff}`;
comma = ', ';
}
}
relatedString !== '' ? origin += `${relatedString}<br><br>,` : origin += ',';
});
item.OverrideDetails !== '' ? origin += `<b>Supporting Details:</b> ${item.OverrideDetails.replace(/"/g,"'")}<br><br>` : origin += '';
origin += `<br><b>ROOT CAUSES</b><br><br><br>`;
origin += `<b>Filed By:</b> ${item.RcaConclusionFiledBy} @ ${item.RcaConclusionFiledTime}<br><br>`;
await knex.select().from('LogIssueRcaCategory').where('IDissue', item.IDissue)
.then((rows) => {
let relatedString = '';
if (rows.length > 0) {
relatedString = '<b>Cause Category : Root Cause</b>';
for (let x of rows) {
relatedString += `<br>${x.RcaCategory} : ${x.RcaRoot}`;
}
}
relatedString !== '' ? origin += `${relatedString}<br><br>` : origin += '';
});
origin += `<br><b>ACTION</b><br><br><br>`;
//Need to find field for Action
origin += `<br><b>CORRECTION</b><br><br><br>`;
item.CorrectionDetail !== '' ? origin += `${item.CorrectionDetail.replace(/"/g,"'")}<br><br>` : origin += '';
item.CorrectionTargetDate ? origin += `<b>Correction Target:</b> ${item.CorrectionTargetDate}<br><br>` : '';
item.CorrectionComplete ? origin += `<b>Correction Complete:</b> ${item.CorrectionComplete}<br><br>` : '';
item.CorrectionDts ? origin += `<b>Originating DTS/DEV-ID Issue:</b> ${item.CorrectionDts}<br><br>` : '';
item.CorrectionDtsComplete ? origin += `<b>DTS/DEV-ID Complete:</b> ${item.CorrectionDtsComplete}<br><br>` : '';
item.CorrectionCategory ? origin += `<b>Bug Audit Category:</b> ${item.CorrectionCategory}<br><br>` : '';
origin += `<b>NO ACTION</b><br><br>`;
item.NoActionReason !== '' ? origin += `${item.NoActionReason.replace(/"/g,"'")}<br><br>` : origin += '';
origin += `<b>RCA/ACTION APPROVAL</b><br><br>`;
item.ApprovalFiledBy ? origin += `<b>Filed By:</b> ${item.ApprovalFiledBy} @ ${item.ApprovalFiledTime}<br><br>` : '';
item.ApprovalNotes !== '' ? origin += `Notes: ${item.ApprovalNotes.replace(/"/g,"'")}<br><br>` : origin += '';
synopsis = `<br><b>CAPA PLAN</b><br><br><br>`;
item.CapaFiledBy ? synopsis += `<b>Filed By:</b> ${item.CapaFiledBy} @ ${item.CapaFiledTime}<br><br>` : '';
// Check if Cause Category needs to be repeated
item.CapaScope !== '' ? synopsis += `<b>Scope:</b> ${item.CapaScope.replace(/"/g,"'")}<br><br>` : synopsis += '';
item.CapaActivities !== '' ? synopsis += `<b>Activities:</b> ${item.CapaActivities.replace(/"/g,"'")}<br><br>` : synopsis += '';
item.CapaSchedule !== '' ? synopsis += `<b>Schedulee:</b> ${item.CapaSchedule.replace(/"/g,"'")}<br><br>` : synopsis += '';
item.CapaResources !== '' ? synopsis += `<b>Resources:</b> ${item.CapaResources.replace(/"/g,"'")}<br><br>` : synopsis += '';
item.CapaImplementFrom ? synopsis += `<b>Implement From:</b> ${item.CapaImplementFrom}<br><br>` : '';
item.CapaImplementThru ? synopsis += `<b>Implement Thru:</b> ${item.CapaImplementThru}<br><br>` : '';
// item.CapaCorrectDetail !==''? synopsis += `<b>Correction Detail:</b> ${item.CapaCorrectDetail.replace(/"/g,"'")}<br><br>` : synopsis +='';
// synopsis += `<b>Correction Target:</b> ${item.CapaCorrectTarget}<br><br>`;
// synopsis += `<b>Correction Complete:</b> ${item.CapaCorrectComplete}<br><br>`;
synopsis += `<br><b>CAPA PLAN ADDENDUM</b><br><br><br>`;
item.CapaAddendumNotes !== '' ? synopsis += `<b>Notes:</b> ${item.CapaAddendumNotes.replace(/"/g,"'")}<br><br>` : synopsis += '';
synopsis += `<br><b>CAPA PLAN VERIFICATION</b><br><br><br>`;
synopsis += `<b>Verification Person:</b> ${item.CapaVerifyPerson}<br><br>`;
synopsis += `<b>Verification By:</b> ${item.CapaVerifyFiledBy}<br><br>`;
await knex.select().from('LogIssueIso9001').where('IDissue', item.IDissue)
.then((rows) => {
let isoString = '';
if (rows.length > 0) {
isoString = `<b>ISO 9001:</b> <br>`;
for (let iso of rows) {
isoString += `${iso.Iso9001}<br>`;
}
}
isoString !== '' ? synopsis += `${isoString}<br>` : synopsis += '';
});
await knex.select().from('LogIssueIso27001').where('IDissue', item.IDissue)
.then((rows) => {
let isoString = '';
if (rows.length > 0) {
isoString = `<b>ISO 27001:</b> <br>`;
for (let iso of rows) {
isoString += `${iso.Iso27001}<br>`;
}
}
isoString !== '' ? synopsis += `${isoString}<br>` : synopsis += '';
});
//too long in some rows, causing the csv to crash that item
item.CapaVerifyNotes !== '' ? synopsis += `"<b>Notes:</b> ${item.CapaVerifyNotes.replace(/"/g,"'")}<br><br>"` : synopsis += '';
synopsis += `<br><b>CAPA PLAN APPROVAL</b><br><br><br>`;
item.CapaReviewFiledBy ? synopsis += `<b>Filed By:</b> ${item.CapaReviewFiledBy} @ ${item.CapaReviewFiledTime}<br><br>` : '';
item.CapaAction !== '' ? synopsis += `<b>Notes:</b> ${item.CapaAction.replace(/"/g,"'")}<br><br>` : synopsis += '';
synopsis += `<br><b>CAPA APPROVAL</b><br><br><br>`;
synopsis += `<b>Filed By:</b> ${item.CapaApprovalFiledBy} @ ${item.CapaApprovalFiledTime}<br><br>`;
item.CapaApprovalNotes !== '' ? synopsis += `"<b>Notes:</b> ${item.CapaApprovalNotes.replace(/"/g,"'")}<br><br>"` : synopsis += '';
currentSetup = `<br><b>INTERNAL AUDIT</b><br><br><br>`;
item.AuditInfoFiledBy ? currentSetup += `<b>Filed By:</b> ${item.AuditInfoFiledBy} @ ${item.AuditInfoFiledTime}<br><br>` : '';
item.AuditReadyDate ? currentSetup += `<b>Ready For Audit:</b> ${item.AuditReadyDate}<br><br>` : '';
item.AuditConsiderations !== '' ? currentSetup += `<b>Audit Considerations:</b> ${item.AuditConsiderations.replace(/"/g,"'")}<br><br>` : currentSetup += '';
item.AuditReport !== '' ? currentSetup += `<b>Audit Report:</b> ${item.AuditReport.replace(/"/g,"'")}<br><br>` : currentSetup += '';
item.AuditNotes !== '' ? currentSetup += `<b>Notes:</b> ${item.AuditNotes.replace(/"/g,"'")}<br><br>` : currentSetup += '';
await knex.select().from('LogIssueAssigned').where('IDissue', item.IDissue).limit(1)
.then((rows) => {
for (let row of rows) {
let {
Assigned
} = row;
assigned = Assigned;
}
});
reviewer = item.GenInfoReviewer;
facilitator = item.GenInfoFacilitator;
reportedDate = item.GenInfoReportedDate;
let test = {id, title, status, category, type, description, analysis, conversion, origin, synopsis, currentSetup, assigned, reviewer, facilitator, reportedDate};
objectArray.push(test);
}
})
.then(() =>
csvWriter
.writeRecords(objectArray)
.then(()=> console.log('The CSV file was written successfully')));