-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport-data.sh
More file actions
82 lines (76 loc) · 2.49 KB
/
import-data.sh
File metadata and controls
82 lines (76 loc) · 2.49 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
#!/bin/bash
# Run the import script in the background
( echo "Waiting for PostgreSQL to be ready..."
until psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 1;" &> /dev/null; do
sleep 60
echo "Waiting for PostgreSQL... still not ready."
done
echo "PostgreSQL is ready."
# Ensure the health_insurance table exists before proceeding
echo "Checking if health_insurance table exists..."
until psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT to_regclass('public.health_insurance');" | grep -q "health_insurance"; do
echo "Waiting for health_insurance table to be created..."
sleep 240
done
echo "Importing JSON data into PostgreSQL..."
psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c"
WITH json_data AS (
SELECT jsonb_array_elements(pg_read_file('/docker-entrypoint-initdb.d/health-care-insurance.json')::jsonb) AS data
)
INSERT INTO health_insurance (
ik, datum, antragsschluessel, anrede, namenszeile_1, namenszeile_2, namenszeile_3, namenszeile_4,
h_strasse, h_lkz, h_plz, h_ort, p_lkz, p_ort, p_plz, postfach, tel_vorwahl, tel_ruf_nummer, fax_vorwahl, fax_nummer
)
SELECT
(data ->> 'IK')::BIGINT,
data ->> 'Datum',
(data ->> 'Antragsschluessel')::VARCHAR,
(data ->> 'Anrede')::VARCHAR,
data ->> 'Namenszeile_1',
data ->> 'Namenszeile_2',
data ->> 'Namenszeile_3',
data ->> 'Namenszeile_4',
data ->> 'H_Strasse',
data ->> 'H_LKZ',
data ->> 'H_PLZ',
data ->> 'H_Ort',
data ->> 'P_LKZ',
data ->> 'P_Ort',
(data ->> 'P_PLZ')::VARCHAR,
(data ->> 'Postfach')::VARCHAR,
data ->> 'TelVorwahl',
data ->> 'TelRufNummer',
data ->> 'FaxVorwahl',
data ->> 'FaxNummer'
FROM json_data;
"
echo "JSON import completed."
echo "Inserting workflow and step data..."
psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "
-- Insert into workflow table if not exists
INSERT INTO workflow (id)
VALUES (1)
ON CONFLICT (id) DO NOTHING;
-- Insert steps into step table
INSERT INTO step (id, name, skippable, parent_step_id)
VALUES
(0, 'Klinische Daten', false, NULL),
(1, 'Anforderung', false, NULL),
(2, 'Genetische Daten', false, NULL),
(3, 'MTB-Beschluss und MTB-Report', false, NULL),
(4, 'Übermittlung', false, NULL)
ON CONFLICT (id) DO NOTHING;
-- Insert into workflow_steps table if not exists
INSERT INTO workflow_steps (workflow_id, steps_id)
VALUES
(1, 0),
(1, 1),
(1, 2),
(1, 3),
(1, 4)
ON CONFLICT DO NOTHING;
"
echo "Workflow and step data insertion completed."
) &
# Immediately exit with a successful status
exit 0