-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetlTransformerAdult.ts
162 lines (147 loc) · 3.86 KB
/
etlTransformerAdult.ts
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
import data from "tempadult.json";
import fs from "fs";
import path from "path";
import { DateTime } from "luxon";
const todaysDate = DateTime.now()
.setZone("America/New_York")
.toFormat("yyyy-MM-dd");
// const formattedDate = DateTime.fromFormat(todaysDate, "yyyy-MM-dd");
console.log(todaysDate);
type TRANSPLANT_DATA = {
region: string | null;
wait_list_type: string | null;
wait_list_time: string | null;
blood_type_a: number | null;
blood_type_b: number | null;
blood_type_ab: number | null;
blood_type_o: number | null;
blood_type_all: number | null;
report_date: string;
};
let transformedData: Array<TRANSPLANT_DATA> = [];
let finalTransformedData: Array<TRANSPLANT_DATA> = [];
let region = "";
let waitListType = "";
// do some more transformations on the data
for (let index = 0; index < data.length; index++) {
const row = data[index];
// console.log(row);
if (
!row.WaitListTime &&
!row["All ABO"] &&
!row.O &&
!row.A &&
!row.B &&
!row.AB
) {
// skip the row and don't process it
} else {
// set the region
if (row.Region) {
region = row.Region;
} else {
region = region;
}
// set the wait list type
if (row.WaitListType) {
waitListType = row.WaitListType;
} else {
waitListType = waitListType;
}
const obj: TRANSPLANT_DATA = {
region,
wait_list_type: waitListType,
wait_list_time: row.WaitListTime,
blood_type_a: row.A,
blood_type_b: row.B,
blood_type_ab: row.AB,
blood_type_o: row.O,
blood_type_all: row["All ABO"],
report_date: todaysDate,
};
transformedData.push(obj);
}
}
// console.log(transformedData);
// transform again by checking to see if each region has all of the wait list times for each wait list type
const regions = [
"All Regions",
"Region 1",
"Region 2",
"Region 3",
"Region 4",
"Region 5",
"Region 6",
"Region 7",
"Region 8",
"Region 9",
"Region 10",
"Region 11",
];
const waitListTypes = [
"All Types",
"Adult Status 1",
"Adult Status 2",
"Adult Status 3",
"Adult Status 4",
"Adult Status 5",
"Adult Status 6",
];
const waitListTimes = [
"All Time",
"< 30 Days",
"30 to < 90 Days",
"90 Days to < 6 Months",
"6 Months to < 1 Year",
"1 Year to < 2 Years",
"2 Years to < 3 Years",
"3 Years to < 5 Years",
"5 or More Years",
];
// Fill out missing data points
for (let index = 0; index < regions.length; index++) {
const region = regions[index];
for (let index = 0; index < waitListTypes.length; index++) {
const waitListType = waitListTypes[index];
for (let index = 0; index < waitListTimes.length; index++) {
const waitListTime = waitListTimes[index];
const dataExists = transformedData.filter(
(r: TRANSPLANT_DATA) =>
r.region === region &&
r.wait_list_type === waitListType &&
r.wait_list_time === waitListTime
);
if (dataExists.length > 0) {
// console.log(dataExists);
finalTransformedData.push(dataExists[0]);
} else {
console.log(
`Data does not exists for ${region} - ${waitListType} - ${waitListTime}`
);
const obj: TRANSPLANT_DATA = {
region,
wait_list_type: waitListType,
wait_list_time: waitListTime,
blood_type_a: 0,
blood_type_b: 0,
blood_type_ab: 0,
blood_type_o: 0,
blood_type_all: 0,
report_date: todaysDate,
};
// console.log(obj);
finalTransformedData.push(obj);
}
}
}
}
console.log(finalTransformedData);
const file = path.join(process.cwd(), "DatabaseWaitingListAdult.json");
console.log(file);
fs.writeFile(file, JSON.stringify(finalTransformedData, null, 2), (err) => {
if (err) {
console.error(err);
} else {
console.log("Created new file successfully");
}
});