Skip to content

Commit

Permalink
Adds LOCATION updates and LOCATION_HISTORY table
Browse files Browse the repository at this point in the history
  • Loading branch information
clairblacketer committed Jul 24, 2018
1 parent 0c6be40 commit 5d26033
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 1 deletion.
63 changes: 63 additions & 0 deletions LOCATION/LOCATION ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*********************************************************************************
# Copyright 2014 Observational Health Data Sciences and Informatics
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
********************************************************************************/

/************************
####### # # ####### ###### ##### ###### # # ###### ####### # #
# # ## ## # # # # # # # # ## ## # # # # #
# # # # # # # # # # # # # # # # # # # # # #
# # # # # # # ###### # # # # # # # # ##### # #
# # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # #
####### # # ####### # ##### ###### # # ###### ####### #
Dev script to update the LOCATION table and create the LOCATION_HISTORY as described in github issues #91: https://github.com/OHDSI/CommonDataModel/issues/91 and #181 https://github.com/OHDSI/CommonDataModel/issues/181
last revised: 24-July-2017
author: Clair Blacketer, Gowtham Rao
*************************/

CREATE TABLE location
(
location_id INTEGER NOT NULL ,
address_1 VARCHAR(50) NULL ,
address_2 VARCHAR(50) NULL ,
city VARCHAR(50) NULL ,
state VARCHAR(2) NULL ,
zip VARCHAR(9) NULL ,
county VARCHAR(20) NULL ,
country VARCHAR(100) NULL ,
location_source_value VARCHAR(50) NULL ,
latitude FLOAT NULL ,
longitude FLOAT NULL
)
;

CREATE TABLE location_history
(
location_id INTEGER NOT NULL ,
relationship_type VARCHAR(50) NULL ,
domain_id VARCHAR(50) NOT NULL ,
entity_id INTEGER NOT NULL ,
start_date DATE NOT NULL ,
end_date DATE NULL
)
;
42 changes: 42 additions & 0 deletions LOCATION/LOCATION keys indices constraints.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*********************************************************************************
# Copyright 2014 Observational Health Data Sciences and Informatics
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
********************************************************************************/

/************************
####### # # ####### ###### ##### ###### # # ###### ####### # # ### # # ###### ####### # # ####### #####
# # ## ## # # # # # # # # ## ## # # # # # # ## # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # ###### # # # # # # # # ##### # # # # # # # # ##### # ##### #####
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # ## # # # # # # # #
####### # # ####### # ##### ###### # # ###### ####### # ### # # ###### ####### # # ####### #####
Dev script to create the required indexes for the recently accepted LOCATION and LOCATION_HISTORY table proposals as described in github issues #91: https://github.com/OHDSI/CommonDataModel/issues/91 and #181 https://github.com/OHDSI/CommonDataModel/issues/181
last revised: 24-July-2018
author: Clair Blacketer
description: These indices, primary keys and constraints are considered a minimal requirement to ensure adequate performance of analyses.
*************************/

/*Primary Key*/

ALTER TABLE location ADD CONSTRAINT xpk_location PRIMARY KEY NONCLUSTERED ( location_id ) ;

ALTER TABLE location_history ADD CONSTRAINT fpk_location_history FOREIGN KEY ( location_id ) REFERENCES location ( location_id ) ;
50 changes: 50 additions & 0 deletions LOCATION/LOCATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## LOCATION

Field|Required|Type|Description
:----------------------|:--------|:------------|:--------------------------------------------
|location_id|Yes|integer|A unique identifier for each geographic location.|
|address_1|No|varchar(50)|The address field 1, typically used for the street address, as it appears in the source data.|
|address_2|No|varchar(50)|The address field 2, typically used for additional detail such as buildings, suites, floors, as it appears in the source data.|
|city |No|varchar(50)|The city field as it appears in the source data.|
|state|No|varchar(2)|The state field as it appears in the source data.|
|zip|No|varchar(9)|The zip or postal code.|
|county|No|varchar(20)|The county.|
|country|No|varchar(100)|The country|
|location_source_value|No|varchar(50)|The verbatim information that is used to uniquely identify the location as it appears in the source data.|
|latitude|No|float|The geocoded latitude|
|longitude|No|float|The geocoded longitude|


### Conventions
* Each address or Location is unique and is present only once in the table.
* Locations do not contain names, such as the name of a hospital. In order to construct a full address that can be used in the postal service, the address information from the Location needs to be combined with information from the Care Site. The PERSON table does not contain name information at all.
* All fields in the Location tables contain the verbatim data in the source, no mapping or normalization takes place. None of the fields are mandatory. If the source data have no Location information at all, all Locations are represented by a single record. Typically, source data contain full or partial zip or postal codes or county or census district information.
* Zip codes are handled as strings of up to 9 characters length. For US addresses, these represent either a 3-digit abbreviated Zip code as provided by many sources for patient protection reasons, the full 5-digit Zip or the 9-digit (ZIP + 4) codes. Unless for specific reasons analytical methods should expect and utilize only the first 3 digits. For international addresses, different rules apply.
* The county information can be provided and is not redundant with information from the zip codes as not all of these have an unambiguous county designation.
* For standardized geospatial visualization and analysis, addresses need to be, at the minimum be geocoded into latitude and longitude. This allows it to put as a point on a map. This proposal is to add two fields, latitude and longitude to the location table.




## LOCATION_HISTORY

The LOCATION HISTORY table stores relationships between Persons or Care Sites and geographic locations over time.

Field|Required|Type|Description
:------------------------------|:--------|:------------|:----------------------------------------------
|location_id |Yes|integer|A foreign key to the location table.|
|relationship_type |No|varchar(50)|The type of relationship between location and entity.|
|domain_id |Yes|varchar(50)|The domain of the entity that is related to the location. Either PERSON, PROVIDER, or CARE_SITE.|
|entity_id |Yes|integer|The unique identifier for the entity. References either person_id, provider_id, or care_site_id, depending on domain_id.|
|start_date |Yes|date|The date the relationship started.|
|end_date |No|date|The date the relationship ended.|

### Conventions
* The entities (and permissible domains) with related locations are: Persons (PERSON), Providers (PROVIDER), and Care Sites (CARE_SITE)
* Domain_id specifies which table the entity_id refers to
* Locations and entities are static. Relationships between locations and entities are dynamic.
* When the domain is PERSON, the permissible values of relationship_type are: 'residence', 'work site', 'school'
* When the domain is CARE_SITE, the value of relationship_type is NULL
* **TODO** When the domain is PROVIDER, the value of relationship_type is 'office' **is this correct?**


8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ SURVEY
* [#137](https://github.com/OHDSI/CommonDataModel/issues/137)
* New table to the CDM
* Houses information related to the survey itself, all responses to the survey are housed in the OBSERVATION table
* The ddl for both the SURVEY table and updated OBSERVATION table are located in the SURVEY folder
* The ddl for both the SURVEY table and updated OBSERVATION table are located in the SURVEY folder

LOCATION/LOCATION_HISTORY
* [#91](https://github.com/OHDSI/CommonDataModel/issues/91)
* [#181](https://github.com/OHDSI/CommonDataModel/issues/181)
* Adds country and latitude/longitude to the LOCATION table
* Creates the new table LOCATION_HISTORY that allows the relation of multiple locations over time to CARE_SITES, PERSONs OR PROVIDERs

1 comment on commit 5d26033

@gowthamrao
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clairblacketer @cgreich @pbr6cornell

The location_history table is going to be an extremely large (EAV) like table. Currently we have two varchar(30) columns

  • relationship_type with values 'residence', 'work', 'school' etc
  • domain_id with values 'PERSON', 'PROVIDER', 'CARE_SITE' etc

Can we convert these to integers - using concept_id

i.e. instead of relationship_type, change to relationship_type_concept_id
domain_id to domain_concept_id or table_concept_id (to differentiate between tables belonging to same domain_id like visit_occurrence and visit_detail)

Please sign in to comment.