@nsshunt/stsdatamanagement 1.18.100 → 1.18.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -54
- package/db-scripts/builddb.sql +13 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,100 +29,108 @@ docker run --name postgres-5432 -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d --
|
|
|
29
29
|
|
|
30
30
|
select count(*) from stsresource;
|
|
31
31
|
|
|
32
|
-
/* Create
|
|
32
|
+
/* Create General Search Indexes */
|
|
33
33
|
|
|
34
34
|
/* GIN Index */
|
|
35
|
-
drop index idx_stsresource_gin;
|
|
35
|
+
--drop index idx_stsresource_gin;
|
|
36
36
|
CREATE INDEX idx_stsresource_gin ON stsresource USING GIN (resdesc_jsonb);
|
|
37
37
|
|
|
38
38
|
/* btree indexes */
|
|
39
|
-
drop index idx_stsresource_id;
|
|
39
|
+
--drop index idx_stsresource_id;
|
|
40
|
+
--We don't use where here becuase all FHIR resources will have an id field
|
|
40
41
|
CREATE INDEX idx_stsresource_id ON stsresource ((resdesc_jsonb->>'id'));
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
CREATE INDEX idx_stsresource_given ON stsresource ((resdesc_jsonb->'name'->0->>'given'));
|
|
43
|
+
-- Create Indexes for FHIR resources
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
CREATE INDEX
|
|
45
|
+
--DROP INDEX idx_stsresource_given;
|
|
46
|
+
CREATE INDEX idx_stsresource_given
|
|
47
|
+
ON stsresource ((resdesc_jsonb->'name'->0->>'given'))
|
|
48
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
47
49
|
|
|
48
|
-
drop index
|
|
50
|
+
--drop index idx_stsresource_family;
|
|
51
|
+
CREATE INDEX idx_stsresource_family ON stsresource ((resdesc_jsonb->'name'->0->>'family'))
|
|
52
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
53
|
+
|
|
54
|
+
--drop index idx_stsresource_text_div_01;
|
|
49
55
|
CREATE INDEX idx_stsresource_text_div_01
|
|
50
|
-
ON stsresource ((resdesc_jsonb->'text'->>'div'))
|
|
56
|
+
ON stsresource ((resdesc_jsonb->'text'->>'div'))
|
|
57
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
51
58
|
|
|
52
59
|
/* btree indexes - alternate method - for queries, quotes will be need '"<search string>"' */
|
|
53
|
-
drop index idx_stsresource_text_div_02;
|
|
60
|
+
--drop index idx_stsresource_text_div_02;
|
|
54
61
|
CREATE INDEX idx_stsresource_text_div_02
|
|
55
|
-
ON stsresource ((resdesc_jsonb#>'{text,div}'))
|
|
62
|
+
ON stsresource ((resdesc_jsonb#>'{text,div}'))
|
|
63
|
+
WHERE (resdesc_jsonb#>'{_resourceType}')::text = '"Person"';
|
|
56
64
|
|
|
57
65
|
/* Queries using our indexes */
|
|
58
66
|
|
|
59
|
-
/* Get record using the BTREE index given */
|
|
60
|
-
|
|
61
|
-
select
|
|
62
|
-
resdesc_jsonb->'id' as id,
|
|
63
|
-
resdesc_jsonb->'name'->0->>'given' as given,
|
|
64
|
-
resdesc_jsonb->'name'->0->>'family' as family,
|
|
65
|
-
resdesc_jsonb->'name' as name
|
|
66
|
-
from stsresource
|
|
67
|
-
where resdesc_jsonb notnull
|
|
68
|
-
and resdesc_jsonb->'name'->0->>'given' >= 'y' and resdesc_jsonb->'name'->0->>'given' < 'yzzzzzzzzzzzzz'
|
|
69
|
-
and validto is null
|
|
70
|
-
order by family, given, id
|
|
71
|
-
limit 20;
|
|
72
|
-
|
|
73
67
|
/* Get records using the GIN index */
|
|
74
68
|
SELECT *
|
|
75
69
|
FROM stsresource
|
|
76
|
-
WHERE resdesc_jsonb @> '{"
|
|
70
|
+
WHERE resdesc_jsonb @> '{"_resourceType": "Person"}'
|
|
71
|
+
AND resdesc_jsonb @> '{"name": [{"family": "Adams"}]}';
|
|
77
72
|
|
|
78
73
|
SELECT oid, resdesc_jsonb#>'{text,div}' AS text_div
|
|
79
74
|
FROM stsresource
|
|
80
|
-
WHERE resdesc_jsonb
|
|
75
|
+
WHERE resdesc_jsonb @> '{"_resourceType": "Person"}'
|
|
81
76
|
AND resdesc_jsonb @> '{"text": {"div": "New Record 100"}}';
|
|
82
|
-
|
|
77
|
+
|
|
78
|
+
/* Get record using the BTREE index given */
|
|
79
|
+
SELECT resdesc_jsonb->'id' as id,
|
|
80
|
+
resdesc_jsonb->'name'->0->>'given' as given,
|
|
81
|
+
resdesc_jsonb->'name'->0->>'family' as family,
|
|
82
|
+
resdesc_jsonb->'name' as name
|
|
83
|
+
FROM stsresource
|
|
84
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person'
|
|
85
|
+
AND resdesc_jsonb->'name'->0->>'given' >= 'y' and resdesc_jsonb->'name'->0->>'given' < 'yzzzzzzzzzzzzz'
|
|
86
|
+
AND validto is null
|
|
87
|
+
ORDER BY family, given, id
|
|
88
|
+
LIMIT 20;
|
|
89
|
+
|
|
83
90
|
/* Get record using the BTREE index 01 */
|
|
84
91
|
SELECT oid, resdesc_jsonb#>'{text,div}' AS text_div
|
|
85
92
|
FROM stsresource
|
|
86
|
-
WHERE resdesc_jsonb
|
|
93
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person'
|
|
87
94
|
AND resdesc_jsonb->'text'->>'div' = 'New Record 200';
|
|
88
95
|
|
|
89
96
|
/* Get record using the BTREE index 02 */
|
|
90
97
|
SELECT oid, resdesc_jsonb#>'{text,div}' AS text_div
|
|
91
98
|
FROM stsresource
|
|
92
|
-
WHERE resdesc_jsonb
|
|
99
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person'
|
|
93
100
|
AND resdesc_jsonb#>'{text,div}' = '"New Record 400"';
|
|
94
101
|
|
|
95
102
|
/* Query using id index */
|
|
96
103
|
SELECT oid, resdesc_jsonb->>'id' as id, *
|
|
97
104
|
FROM stsresource
|
|
98
105
|
WHERE resdesc_jsonb->>'id' >= '_b' and resdesc_jsonb->>'id' < '_bzzzzzzzzzzzz'
|
|
99
|
-
|
|
106
|
+
ORDER BY resdesc_jsonb->>'id'
|
|
100
107
|
LIMIT 20;
|
|
101
108
|
|
|
102
109
|
/* Query using given index */
|
|
103
|
-
SELECT distinct given, family
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
resdesc_jsonb
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
AND resdesc_jsonb->'name'->0->>'given' < 'azzzzzzz'
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
SELECT distinct given, family
|
|
111
|
+
FROM (
|
|
112
|
+
SELECT resdesc_jsonb->'name'->0->>'given' as given, resdesc_jsonb->'name'->0->>'family' as family
|
|
113
|
+
FROM stsresource
|
|
114
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person'
|
|
115
|
+
AND validto is null
|
|
116
|
+
AND resdesc_jsonb->'name'->0->>'given' >= 'a'
|
|
117
|
+
AND resdesc_jsonb->'name'->0->>'given' < 'azzzzzzz'
|
|
118
|
+
)
|
|
119
|
+
ORDER BY given DESC
|
|
120
|
+
LIMIT 20;
|
|
114
121
|
|
|
115
122
|
/* Query using family and given indexes */
|
|
116
|
-
SELECT distinct given, family
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
resdesc_jsonb
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
AND resdesc_jsonb->'name'->0->>'given' < 'azzzzzzz'
|
|
124
|
-
AND resdesc_jsonb->'name'->0->>'family' >= 'y'
|
|
125
|
-
AND resdesc_jsonb->'name'->0->>'family' < 'yzzzzzzzzzzzz'
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
SELECT distinct given, family
|
|
124
|
+
FROM (
|
|
125
|
+
SELECT resdesc_jsonb->'name'->0->>'given' as given, resdesc_jsonb->'name'->0->>'family' as family
|
|
126
|
+
FROM stsresource
|
|
127
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person'
|
|
128
|
+
AND validto is null
|
|
129
|
+
AND resdesc_jsonb->'name'->0->>'given' >= 'a'
|
|
130
|
+
AND resdesc_jsonb->'name'->0->>'given' < 'azzzzzzz'
|
|
131
|
+
AND resdesc_jsonb->'name'->0->>'family' >= 'y'
|
|
132
|
+
AND resdesc_jsonb->'name'->0->>'family' < 'yzzzzzzzzzzzz'
|
|
133
|
+
)
|
|
134
|
+
ORDER BY given DESC
|
|
135
|
+
LIMIT 20;
|
|
128
136
|
|
package/db-scripts/builddb.sql
CHANGED
|
@@ -827,7 +827,7 @@ ALTER FUNCTION public.delete_stsentity_latest(character varying, character varyi
|
|
|
827
827
|
OWNER TO postgres;
|
|
828
828
|
|
|
829
829
|
|
|
830
|
-
/* Create General Search Indexes
|
|
830
|
+
/* Create General Search Indexes */
|
|
831
831
|
|
|
832
832
|
/* GIN Index */
|
|
833
833
|
--drop index idx_stsresource_gin;
|
|
@@ -835,19 +835,27 @@ CREATE INDEX idx_stsresource_gin ON stsresource USING GIN (resdesc_jsonb);
|
|
|
835
835
|
|
|
836
836
|
/* btree indexes */
|
|
837
837
|
--drop index idx_stsresource_id;
|
|
838
|
+
--We don't use where here becuase all FHIR resources will have an id field
|
|
838
839
|
CREATE INDEX idx_stsresource_id ON stsresource ((resdesc_jsonb->>'id'));
|
|
839
840
|
|
|
841
|
+
-- Create Indexes for FHIR resources
|
|
842
|
+
|
|
840
843
|
--DROP INDEX idx_stsresource_given;
|
|
841
|
-
CREATE INDEX idx_stsresource_given
|
|
844
|
+
CREATE INDEX idx_stsresource_given
|
|
845
|
+
ON stsresource ((resdesc_jsonb->'name'->0->>'given'))
|
|
846
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
842
847
|
|
|
843
848
|
--drop index idx_stsresource_family;
|
|
844
|
-
CREATE INDEX idx_stsresource_family ON stsresource ((resdesc_jsonb->'name'->0->>'family'))
|
|
849
|
+
CREATE INDEX idx_stsresource_family ON stsresource ((resdesc_jsonb->'name'->0->>'family'))
|
|
850
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
845
851
|
|
|
846
852
|
--drop index idx_stsresource_text_div_01;
|
|
847
853
|
CREATE INDEX idx_stsresource_text_div_01
|
|
848
|
-
ON stsresource ((resdesc_jsonb->'text'->>'div'))
|
|
854
|
+
ON stsresource ((resdesc_jsonb->'text'->>'div'))
|
|
855
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
849
856
|
|
|
850
857
|
/* btree indexes - alternate method - for queries, quotes will be need '"<search string>"' */
|
|
851
858
|
--drop index idx_stsresource_text_div_02;
|
|
852
859
|
CREATE INDEX idx_stsresource_text_div_02
|
|
853
|
-
ON stsresource ((resdesc_jsonb#>'{text,div}'))
|
|
860
|
+
ON stsresource ((resdesc_jsonb#>'{text,div}'))
|
|
861
|
+
WHERE (resdesc_jsonb#>'{_resourceType}')::text = '"Person"';
|