-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added archival mode #183
Added archival mode #183
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
-- noqa: disable=all | ||
-- This sql was autogenerated as a reference example using the library CLI. | ||
-- Its format is tied to the specific database it was run against, and it may not | ||
-- be correct for all databases. Use the CLI's build option to derive the best SQL | ||
-- for your dataset. | ||
-- This sql was autogenerated as a reference example using the library | ||
-- CLI.Its format is tied to the specific database it was run against, | ||
-- and it may not be correct for all databases. Use the CLI's build | ||
-- option to derive the best SQL for your dataset. | ||
|
||
-- ########################################################### | ||
|
||
|
@@ -20,7 +20,7 @@ CREATE TABLE core__condition_codable_concepts_display AS ( | |
condition AS s, | ||
UNNEST(s.code.coding) AS u (codeable_concept) | ||
WHERE | ||
u.codeable_concept.system = 'http://snomed.info/sct' | ||
u.codeable_concept.system LIKE 'http://snomed.info/sct' | ||
), --noqa: LT07 | ||
|
||
system_code_1 AS ( | ||
|
@@ -34,7 +34,7 @@ CREATE TABLE core__condition_codable_concepts_display AS ( | |
condition AS s, | ||
UNNEST(s.code.coding) AS u (codeable_concept) | ||
WHERE | ||
u.codeable_concept.system = 'http://hl7.org/fhir/sid/icd-10-cm' | ||
u.codeable_concept.system LIKE 'http://hl7.org/fhir/sid/icd-10-cm' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm lightly curious about the performance cost of this. Correctness is more important obvi, but if this is noticeably slower, I imagine the jinja could switch to like if it detects a wildcard. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a half baked idea in my head of moving the system extraction logic into here in some way, or in some other way doing db introspection to help build these queries out in a more nuanced fashion. but - only doing LIKE when required seems like low hanging fruit in the interim. |
||
), --noqa: LT07 | ||
|
||
system_code_2 AS ( | ||
|
@@ -48,7 +48,63 @@ CREATE TABLE core__condition_codable_concepts_display AS ( | |
condition AS s, | ||
UNNEST(s.code.coding) AS u (codeable_concept) | ||
WHERE | ||
u.codeable_concept.system = 'http://hl7.org/fhir/sid/icd-9-cm' | ||
u.codeable_concept.system LIKE 'http://hl7.org/fhir/sid/icd-9-cm' | ||
), --noqa: LT07 | ||
|
||
system_code_3 AS ( | ||
SELECT DISTINCT | ||
s.id AS id, | ||
'3' AS priority, | ||
u.codeable_concept.code AS code, | ||
u.codeable_concept.display AS display, | ||
u.codeable_concept.system AS code_system | ||
FROM | ||
condition AS s, | ||
UNNEST(s.code.coding) AS u (codeable_concept) | ||
WHERE | ||
u.codeable_concept.system LIKE 'http://hl7.org/fhir/sid/icd-9-cm/diagnosis' | ||
), --noqa: LT07 | ||
|
||
system_code_4 AS ( | ||
SELECT DISTINCT | ||
s.id AS id, | ||
'4' AS priority, | ||
u.codeable_concept.code AS code, | ||
u.codeable_concept.display AS display, | ||
u.codeable_concept.system AS code_system | ||
FROM | ||
condition AS s, | ||
UNNEST(s.code.coding) AS u (codeable_concept) | ||
WHERE | ||
u.codeable_concept.system LIKE 'urn:oid:1.2.840.114350.1.13.71.2.7.2.728286' | ||
), --noqa: LT07 | ||
|
||
system_code_5 AS ( | ||
SELECT DISTINCT | ||
s.id AS id, | ||
'5' AS priority, | ||
u.codeable_concept.code AS code, | ||
u.codeable_concept.display AS display, | ||
u.codeable_concept.system AS code_system | ||
FROM | ||
condition AS s, | ||
UNNEST(s.code.coding) AS u (codeable_concept) | ||
WHERE | ||
u.codeable_concept.system LIKE 'urn:oid:1.2.840.114350.1.13.71.2.7.4.698084.10375' | ||
), --noqa: LT07 | ||
|
||
system_code_6 AS ( | ||
SELECT DISTINCT | ||
s.id AS id, | ||
'6' AS priority, | ||
u.codeable_concept.code AS code, | ||
u.codeable_concept.display AS display, | ||
u.codeable_concept.system AS code_system | ||
FROM | ||
condition AS s, | ||
UNNEST(s.code.coding) AS u (codeable_concept) | ||
WHERE | ||
u.codeable_concept.system LIKE 'http://terminology.hl7.org/CodeSystem/data-absent-reason' | ||
), --noqa: LT07 | ||
|
||
union_table AS ( | ||
|
@@ -75,6 +131,39 @@ CREATE TABLE core__condition_codable_concepts_display AS ( | |
code, | ||
display | ||
FROM system_code_2 | ||
UNION | ||
SELECT | ||
id, | ||
priority, | ||
code_system, | ||
code, | ||
display | ||
FROM system_code_3 | ||
UNION | ||
SELECT | ||
id, | ||
priority, | ||
code_system, | ||
code, | ||
display | ||
FROM system_code_4 | ||
UNION | ||
SELECT | ||
id, | ||
priority, | ||
code_system, | ||
code, | ||
display | ||
FROM system_code_5 | ||
UNION | ||
SELECT | ||
id, | ||
priority, | ||
code_system, | ||
code, | ||
display | ||
FROM system_code_6 | ||
|
||
), | ||
|
||
partitioned_table AS ( | ||
|
@@ -127,6 +216,7 @@ CREATE TABLE core__condition_codable_concepts_all AS ( | |
code, | ||
display | ||
FROM system_code_0 | ||
|
||
) | ||
SELECT | ||
id, | ||
|
@@ -154,11 +244,11 @@ WITH temp_condition AS ( | |
cca.code_system, | ||
cca.display, | ||
date(from_iso8601_timestamp(c.recordeddate)) AS recordeddate, | ||
date_trunc('week', date(from_iso8601_timestamp(c.recordeddate))) | ||
date_trunc('week', date(from_iso8601_timestamp(c."recordeddate"))) | ||
AS recordeddate_week, | ||
date_trunc('month', date(from_iso8601_timestamp(c.recordeddate))) | ||
date_trunc('month', date(from_iso8601_timestamp(c."recordeddate"))) | ||
AS recordeddate_month, | ||
date_trunc('year', date(from_iso8601_timestamp(c.recordeddate))) | ||
date_trunc('year', date(from_iso8601_timestamp(c."recordeddate"))) | ||
AS recordeddate_year | ||
FROM condition AS c | ||
LEFT JOIN core__condition_codable_concepts_all AS cca ON c.id = cca.id | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially had a thought that maybe this should be a toplevel action instead of a flag on
export
but after thinking about it more, decided you had the right of it. Just talking out loud - in case you had thoughts on that too. But I think this makes sense.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i started off that way too, but in digging in, since it's 90% the same, it was A) faster to get it in here, B) a little DRYer, and C) i kind of like keeping the number of base level cli verbs low.