From b6425cd3264e1f632f700d9d38b516e0bae9de82 Mon Sep 17 00:00:00 2001 From: Evanette Burrows Date: Fri, 26 Jan 2024 17:20:07 -0500 Subject: [PATCH 1/7] Add scripts for location and caresite support Vignettes and updated documentation forthcoming --- R/CreateVocabMapTables.r | 3 +- R/LoadEventTables.r | 22 ++++ .../cdm_version/v531/insert_care_site.sql | 21 ++++ .../cdm_version/v531/insert_location.sql | 27 +++++ .../cdm_version/v531/insert_person.sql | 9 +- .../v531/insert_visit_occurrence.sql | 26 ++-- .../cdm_version/v540/create_states_map.sql | 53 +++++++++ .../cdm_version/v540/insert_care_site.sql | 21 ++++ .../cdm_version/v540/insert_location.sql | 27 +++++ .../cdm_version/v540/insert_person.sql | 112 ++++++++++-------- vignettes/Device_exposure.Rmd | 2 +- 11 files changed, 257 insertions(+), 66 deletions(-) create mode 100644 inst/sql/sql_server/cdm_version/v531/insert_care_site.sql create mode 100644 inst/sql/sql_server/cdm_version/v531/insert_location.sql create mode 100644 inst/sql/sql_server/cdm_version/v540/create_states_map.sql create mode 100644 inst/sql/sql_server/cdm_version/v540/insert_care_site.sql create mode 100644 inst/sql/sql_server/cdm_version/v540/insert_location.sql diff --git a/R/CreateVocabMapTables.r b/R/CreateVocabMapTables.r index 60a653c..a14282c 100644 --- a/R/CreateVocabMapTables.r +++ b/R/CreateVocabMapTables.r @@ -33,7 +33,8 @@ CreateVocabMapTables <- queries <- c( "create_source_to_standard_vocab_map.sql", - "create_source_to_source_vocab_map.sql" + "create_source_to_source_vocab_map.sql", + "create_states_map.sql" ) if (!sqlOnly) { diff --git a/R/LoadEventTables.r b/R/LoadEventTables.r index c0dfea8..9ffe996 100644 --- a/R/LoadEventTables.r +++ b/R/LoadEventTables.r @@ -93,6 +93,28 @@ LoadEventTables <- function(connectionDetails, } } + # location + fileQuery <- "insert_location.sql" + sql <- SqlRender::loadRenderTranslateSql( + sqlFilename = file.path(sqlFilePath, fileQuery), + packageName = "ETLSyntheaBuilder", + dbms = connectionDetails$dbms, + cdm_schema = cdmSchema, + synthea_schema = syntheaSchema + ) + runStep(sql, fileQuery) + + # care_site + fileQuery <- "insert_care_site.sql" + sql <- SqlRender::loadRenderTranslateSql( + sqlFilename = file.path(sqlFilePath, fileQuery), + packageName = "ETLSyntheaBuilder", + dbms = connectionDetails$dbms, + cdm_schema = cdmSchema, + synthea_schema = syntheaSchema + ) + runStep(sql, fileQuery) + # person fileQuery <- "insert_person.sql" sql <- SqlRender::loadRenderTranslateSql( diff --git a/inst/sql/sql_server/cdm_version/v531/insert_care_site.sql b/inst/sql/sql_server/cdm_version/v531/insert_care_site.sql new file mode 100644 index 0000000..c65d65f --- /dev/null +++ b/inst/sql/sql_server/cdm_version/v531/insert_care_site.sql @@ -0,0 +1,21 @@ + + +insert into @cdm_schema.care_site ( +care_site_id, +care_site_name, +place_of_service_concept_id, +location_id, +care_site_source_value, +place_of_service_source_value +) + +select +row_number()over(order by o.id) care_site_id, +o.name care_site_name, +0 place_of_service_concept_id, +cast(null as integer) location_id, +o.id care_site_source_value, +cast(null as varchar) place_of_service_source_value + +from @synthea_schema.organizations o +; diff --git a/inst/sql/sql_server/cdm_version/v531/insert_location.sql b/inst/sql/sql_server/cdm_version/v531/insert_location.sql new file mode 100644 index 0000000..b86b9d6 --- /dev/null +++ b/inst/sql/sql_server/cdm_version/v531/insert_location.sql @@ -0,0 +1,27 @@ + + +insert into @cdm_schema.location ( +location_id, +address_1, +address_2, +city, +state, +zip, +county, +location_source_value +) +select +row_number() over () as location_id, +locations.* +from +(select distinct +cast(null as varchar) address_1, +cast(null as varchar) address_2, +p.city city, +states_map.state_abbreviation state, +cast(null as varchar) county, +p.zip zip, +p.zip location_source_value +from @synthea_schema.patients p) locations +left join @cdm_schema.states_map states_map on locations.state=states_map.state +; \ No newline at end of file diff --git a/inst/sql/sql_server/cdm_version/v531/insert_person.sql b/inst/sql/sql_server/cdm_version/v531/insert_person.sql index fd05881..c253508 100644 --- a/inst/sql/sql_server/cdm_version/v531/insert_person.sql +++ b/inst/sql/sql_server/cdm_version/v531/insert_person.sql @@ -19,6 +19,12 @@ race_source_concept_id, ethnicity_source_value, ethnicity_source_concept_id ) +with mapped_states as ( + + select distinct l.location_id,l.city,states_map.state,l.zip + from @cdm_schema.location l + left join states_map state_map on l.state=states_map.state_abbreviation +) select row_number()over(order by p.id), case upper(p.gender) @@ -40,7 +46,7 @@ select when Upper(p.ethnicity) = 'NONHISPANIC' then 38003564 else 0 end, - NULL, + l.location_id, NULL, NULL, p.id, @@ -51,4 +57,5 @@ select p.ethnicity, 0 from @synthea_schema.patients p + left join mapped_states l on p.city = l.city and p.state=l.state and p.zip=l.zip where p.gender is not null; diff --git a/inst/sql/sql_server/cdm_version/v531/insert_visit_occurrence.sql b/inst/sql/sql_server/cdm_version/v531/insert_visit_occurrence.sql index 567f856..da44130 100644 --- a/inst/sql/sql_server/cdm_version/v531/insert_visit_occurrence.sql +++ b/inst/sql/sql_server/cdm_version/v531/insert_visit_occurrence.sql @@ -20,14 +20,14 @@ preceding_visit_occurrence_id ) select av.visit_occurrence_id, - p.person_id, + p.person_id, - case lower(av.encounterclass) + case lower(av.encounterclass) when 'ambulatory' then 9202 when 'emergency' then 9203 when 'inpatient' then 9201 when 'wellness' then 9202 - when 'urgentcare' then 9203 + when 'urgentcare' then 9203 when 'outpatient' then 9202 else 0 end, @@ -35,16 +35,16 @@ select av.visit_start_date, av.visit_end_date, av.visit_end_date, - 32827, - pr.provider_id, - null, + 32827, + pr.provider_id, + cs.care_site_id, av.encounter_id, - 0, + 0, + 0, + null, 0, null, - 0, - null, - lag(av.visit_occurrence_id) + lag(av.visit_occurrence_id) over(partition by p.person_id order by av.visit_start_date) from @cdm_schema.all_visits av @@ -53,8 +53,10 @@ join @cdm_schema.person p join @synthea_schema.encounters e on av.encounter_id = e.id and av.patient = e.patient -join @cdm_schema.provider pr +join @cdm_schema.provider pr on e.provider = pr.provider_source_value +join @cdm_schema.care_site cs + on e.organization = cs.care_site_source_value where av.visit_occurrence_id in ( select distinct visit_occurrence_id_new - from @cdm_schema.final_visit_ids); \ No newline at end of file + from @cdm_schema.final_visit_ids); diff --git a/inst/sql/sql_server/cdm_version/v540/create_states_map.sql b/inst/sql/sql_server/cdm_version/v540/create_states_map.sql new file mode 100644 index 0000000..7576f4c --- /dev/null +++ b/inst/sql/sql_server/cdm_version/v540/create_states_map.sql @@ -0,0 +1,53 @@ +INSERT INTO states_map (state, state_abbreviation) +VALUES + ('Alabama', 'AL'), + ('Alaska', 'AK'), + ('Arizona', 'AZ'), + ('Arkansas', 'AR'), + ('California', 'CA'), + ('Colorado', 'CO'), + ('Connecticut', 'CT'), + ('Delaware', 'DE'), + ('District of Columbia', 'DC'), + ('Florida', 'FL'), + ('Georgia', 'GA'), + ('Hawaii', 'HI'), + ('Idaho', 'ID'), + ('Illinois', 'IL'), + ('Indiana', 'IN'), + ('Iowa', 'IA'), + ('Kansas', 'KS'), + ('Kentucky', 'KY'), + ('Louisiana', 'LA'), + ('Maine', 'ME'), + ('Maryland', 'MD'), + ('Massachusetts', 'MA'), + ('Michigan', 'MI'), + ('Minnesota', 'MN'), + ('Mississippi', 'MS'), + ('Missouri', 'MO'), + ('Montana', 'MT'), + ('Nebraska', 'NE'), + ('Nevada', 'NV'), + ('New Hampshire', 'NH'), + ('New Jersey', 'NJ'), + ('New Mexico', 'NM'), + ('New York', 'NY'), + ('North Carolina', 'NC'), + ('North Dakota', 'ND'), + ('Ohio', 'OH'), + ('Oklahoma', 'OK'), + ('Oregon', 'OR'), + ('Pennsylvania', 'PA'), + ('Rhode Island', 'RI'), + ('South Carolina', 'SC'), + ('South Dakota', 'SD'), + ('Tennessee', 'TN'), + ('Texas', 'TX'), + ('Utah', 'UT'), + ('Vermont', 'VT'), + ('Virginia', 'VA'), + ('Washington', 'WA'), + ('West Virginia', 'WV'), + ('Wisconsin', 'WI'), + ('Wyoming', 'WY'); \ No newline at end of file diff --git a/inst/sql/sql_server/cdm_version/v540/insert_care_site.sql b/inst/sql/sql_server/cdm_version/v540/insert_care_site.sql new file mode 100644 index 0000000..c65d65f --- /dev/null +++ b/inst/sql/sql_server/cdm_version/v540/insert_care_site.sql @@ -0,0 +1,21 @@ + + +insert into @cdm_schema.care_site ( +care_site_id, +care_site_name, +place_of_service_concept_id, +location_id, +care_site_source_value, +place_of_service_source_value +) + +select +row_number()over(order by o.id) care_site_id, +o.name care_site_name, +0 place_of_service_concept_id, +cast(null as integer) location_id, +o.id care_site_source_value, +cast(null as varchar) place_of_service_source_value + +from @synthea_schema.organizations o +; diff --git a/inst/sql/sql_server/cdm_version/v540/insert_location.sql b/inst/sql/sql_server/cdm_version/v540/insert_location.sql new file mode 100644 index 0000000..09eac7f --- /dev/null +++ b/inst/sql/sql_server/cdm_version/v540/insert_location.sql @@ -0,0 +1,27 @@ + + +insert into @cdm_schema.location ( +location_id, +address_1, +address_2, +city, +state, +zip, +county, +location_source_value +) +select +row_number() over () as location_id, +locations.* +from +(select distinct +cast(null as varchar) address_1, +cast(null as varchar) address_2, +p.city city, +states_map.state_abbreviation state, +cast(null as varchar) county, +p.zip zip, +p.zip location_source_value +from @synthea_schema.patients p) locations +left join @cdm_schema.states_map states_map on locations.state=states_map.state +; diff --git a/inst/sql/sql_server/cdm_version/v540/insert_person.sql b/inst/sql/sql_server/cdm_version/v540/insert_person.sql index ae55fff..c253508 100644 --- a/inst/sql/sql_server/cdm_version/v540/insert_person.sql +++ b/inst/sql/sql_server/cdm_version/v540/insert_person.sql @@ -1,51 +1,61 @@ -insert into @cdm_schema.person - (person_id, - gender_concept_id, - year_of_birth, - month_of_birth, - day_of_birth, - birth_datetime, - race_concept_id, - ethnicity_concept_id, - location_id, - provider_id, - care_site_id, - person_source_value, - gender_source_value, - gender_source_concept_id, - race_source_value, - race_source_concept_id, - ethnicity_source_value, - ethnicity_source_concept_id) -select row_number() over(order by p.id), - case Upper(p.gender) - when 'M' then 8507 - when 'F' then 8532 - end, - Year(p.birthdate), - Month(p.birthdate), - Day(p.birthdate), - p.birthdate, - case Upper(p.race) - when 'WHITE' then 8527 - when 'BLACK' then 8516 - when 'ASIAN' then 8515 - else 0 - end, - case - when Upper(p.ethnicity) = 'HISPANIC' then 38003563 - when Upper(p.ethnicity) = 'NONHISPANIC' then 38003564 - else 0 - end, - NULL, - NULL, - NULL, - p.id, - p.gender, - 0, - p.race, - 0, - p.ethnicity, - 0 -from @synthea_schema.patients p -where p.gender is not null; + +insert into @cdm_schema.person ( +person_id, +gender_concept_id, +year_of_birth, +month_of_birth, +day_of_birth, +birth_datetime, +race_concept_id, +ethnicity_concept_id, +location_id, +provider_id, +care_site_id, +person_source_value, +gender_source_value, +gender_source_concept_id, +race_source_value, +race_source_concept_id, +ethnicity_source_value, +ethnicity_source_concept_id +) +with mapped_states as ( + + select distinct l.location_id,l.city,states_map.state,l.zip + from @cdm_schema.location l + left join states_map state_map on l.state=states_map.state_abbreviation +) +select + row_number()over(order by p.id), + case upper(p.gender) + when 'M' then 8507 + when 'F' then 8532 + end, + YEAR(p.birthdate), + MONTH(p.birthdate), + DAY(p.birthdate), + p.birthdate, + case upper(p.race) + when 'WHITE' then 8527 + when 'BLACK' then 8516 + when 'ASIAN' then 8515 + else 0 + end, + case + when Upper(p.ethnicity) = 'HISPANIC' then 38003563 + when Upper(p.ethnicity) = 'NONHISPANIC' then 38003564 + else 0 + end, + l.location_id, + NULL, + NULL, + p.id, + p.gender, + 0, + p.race, + 0, + p.ethnicity, + 0 + from @synthea_schema.patients p + left join mapped_states l on p.city = l.city and p.state=l.state and p.zip=l.zip + where p.gender is not null; diff --git a/vignettes/Device_exposure.Rmd b/vignettes/Device_exposure.Rmd index 005d369..999a958 100644 --- a/vignettes/Device_exposure.Rmd +++ b/vignettes/Device_exposure.Rmd @@ -23,7 +23,7 @@ vignette: > | device_exposure_end_date | stop | | | | device_exposure_end_datetime | stop | | | | device_type_concept_id | | Set to 32827 (EHR encounter record) for all records | | -| unique_device_id |udi | | | +| unique_device_id |udi | For OMOP v5.3 left(udi,50) to account for unique_device_id character length | | | quantity | | cast(null as integer) | | | provider_id | provider | Look up provider_id using provider, joining to the provider.provider_source_value field in the omop table | | | visit_occurrence_id | encounter | Lookup visit_occurrence_id using encounter, joining to temp table defined in AllVisitTable.sql. | | From 325c5d335c6905062c55569626718fd4b3ededfa Mon Sep 17 00:00:00 2001 From: Evanette Burrows Date: Mon, 29 Jan 2024 13:29:26 -0500 Subject: [PATCH 2/7] Create create_states_map.sql --- .../cdm_version/v531/create_states_map.sql | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 inst/sql/sql_server/cdm_version/v531/create_states_map.sql diff --git a/inst/sql/sql_server/cdm_version/v531/create_states_map.sql b/inst/sql/sql_server/cdm_version/v531/create_states_map.sql new file mode 100644 index 0000000..7576f4c --- /dev/null +++ b/inst/sql/sql_server/cdm_version/v531/create_states_map.sql @@ -0,0 +1,53 @@ +INSERT INTO states_map (state, state_abbreviation) +VALUES + ('Alabama', 'AL'), + ('Alaska', 'AK'), + ('Arizona', 'AZ'), + ('Arkansas', 'AR'), + ('California', 'CA'), + ('Colorado', 'CO'), + ('Connecticut', 'CT'), + ('Delaware', 'DE'), + ('District of Columbia', 'DC'), + ('Florida', 'FL'), + ('Georgia', 'GA'), + ('Hawaii', 'HI'), + ('Idaho', 'ID'), + ('Illinois', 'IL'), + ('Indiana', 'IN'), + ('Iowa', 'IA'), + ('Kansas', 'KS'), + ('Kentucky', 'KY'), + ('Louisiana', 'LA'), + ('Maine', 'ME'), + ('Maryland', 'MD'), + ('Massachusetts', 'MA'), + ('Michigan', 'MI'), + ('Minnesota', 'MN'), + ('Mississippi', 'MS'), + ('Missouri', 'MO'), + ('Montana', 'MT'), + ('Nebraska', 'NE'), + ('Nevada', 'NV'), + ('New Hampshire', 'NH'), + ('New Jersey', 'NJ'), + ('New Mexico', 'NM'), + ('New York', 'NY'), + ('North Carolina', 'NC'), + ('North Dakota', 'ND'), + ('Ohio', 'OH'), + ('Oklahoma', 'OK'), + ('Oregon', 'OR'), + ('Pennsylvania', 'PA'), + ('Rhode Island', 'RI'), + ('South Carolina', 'SC'), + ('South Dakota', 'SD'), + ('Tennessee', 'TN'), + ('Texas', 'TX'), + ('Utah', 'UT'), + ('Vermont', 'VT'), + ('Virginia', 'VA'), + ('Washington', 'WA'), + ('West Virginia', 'WV'), + ('Wisconsin', 'WI'), + ('Wyoming', 'WY'); \ No newline at end of file From c136a7bdda98b8ed722881e94e0a0a779784c13f Mon Sep 17 00:00:00 2001 From: Evanette Burrows Date: Tue, 6 Feb 2024 15:44:54 -0500 Subject: [PATCH 3/7] Update documentation --- docs/404.html | 20 +- docs/articles/Condition_occurrence.html | 22 +- docs/articles/Cost.html | 22 +- docs/articles/Device_exposure.html | 25 +- docs/articles/Drug_exposure.html | 22 +- docs/articles/Measurement.html | 22 +- docs/articles/Payer_plan_period.html | 22 +- docs/articles/care_site.html | 211 ++++++++++++++++ docs/articles/death.html | 20 +- docs/articles/index.html | 42 ++-- docs/articles/location.html | 230 ++++++++++++++++++ docs/articles/observation.html | 20 +- docs/articles/observation_period.html | 20 +- docs/articles/person.html | 20 +- docs/articles/procedure_occurrence.html | 20 +- docs/articles/provider.html | 20 +- docs/articles/visit_detail.html | 20 +- docs/articles/visit_occurrence.html | 20 +- docs/authors.html | 20 +- docs/index.html | 22 +- docs/pkgdown.yml | 16 +- .../CreateCDMIndexAndConstraintScripts.html | 20 +- docs/reference/CreateCDMIndices.html | 20 +- docs/reference/CreateCDMTables.html | 20 +- docs/reference/CreateMapAndRollupTables.html | 20 +- docs/reference/CreateSyntheaTables.html | 20 +- docs/reference/CreateVisitRollupTables.html | 20 +- docs/reference/CreateVocabMapTables.html | 20 +- docs/reference/DropEventTables.html | 20 +- docs/reference/DropMapAndRollupTables.html | 20 +- docs/reference/DropSyntheaTables.html | 20 +- docs/reference/DropVocabTables.html | 20 +- docs/reference/ETLSyntheaBuilder-package.html | 20 +- docs/reference/LoadEventTables.html | 20 +- docs/reference/LoadSyntheaTables.html | 20 +- docs/reference/LoadVocabFromCsv.html | 20 +- docs/reference/LoadVocabFromSchema.html | 20 +- docs/reference/TruncateEventTables.html | 20 +- docs/reference/TruncateVocabTables.html | 20 +- docs/reference/backupCDM.html | 20 +- docs/reference/createExtraIndices.html | 22 +- docs/reference/createPrunedTables.html | 20 +- docs/reference/exportToSQLite.html | 20 +- docs/reference/getEventConceptId.html | 20 +- docs/reference/index.html | 28 ++- docs/reference/pruneCDM.html | 20 +- docs/reference/restoreCDMTables.html | 20 +- docs/sitemap.xml | 6 + vignettes/care_site.Rmd | 23 ++ vignettes/index.md | 2 + vignettes/location.Rmd | 25 ++ 51 files changed, 1105 insertions(+), 337 deletions(-) create mode 100644 docs/articles/care_site.html create mode 100644 docs/articles/location.html create mode 100644 vignettes/care_site.Rmd create mode 100644 vignettes/location.Rmd diff --git a/docs/404.html b/docs/404.html index 2536686..96ef43e 100644 --- a/docs/404.html +++ b/docs/404.html @@ -49,25 +49,28 @@