<commit_before>Support multi-Tenancy

	interleave_registries
		id
		name						VARCHAR(255)		NOT NULL

	interleave_registry_affiliates
		id							INTEGER				NOT NULL,
		interleave_registry_id			INTEGER				NOT NULL,
		name						VARCHAR(255)		NOT NULL

	interleave_registry_affiliate_users
		id								INTEGER				NOT NULL,
		interleave_registry_affiliate_id	INTEGER				NOT NULL,	
		username						VARCHAR(255)		NOT NULL

	interleave_registry_cdm_sources
		id							INTEGER				NOT NULL,
		interleave_registry_id			INTEGER				NOT NULL,
		cdm_source_name				VARCHAR(255)		NOT NULL		--A registry can have multiple sources. Examples: 'RedCap', 'NM EDW', 'Catalona Database', 'PSPORE legacy'
																		--Every registry will include an 'Ex nihlo' entry to support manual entry. 	

		* Should this be at the affiliate level?

Support incremental loads and 'Ex niholo' entry.


	interleave_registry_entities
		id							INTEGER				NOT NULL,
		interleave_registry_id			INTEGER				NOT NULL,
	?	domain_id					VARCHAR(255)		NOT NULL,		--polymorphic pointer to representation of entity within OMOP cdm
	?	domain_entity_id			INTEGER				NOT NULL

		cdm_source_name				VARCHAR(255)		NOT NULL,		--polymorphic pointer to source of data
		cdm_source_domain_id		VARCHAR(255)		NULL,			--name of entity within source, not releveant for 'Ex nihlo'
		cdm_source_value			VARCHAR(255)		NULL			--stable identifier, not releveant for 'Ex nihlo'
		overriden					BOOLEAN				NULL			--keep track if an entity created by a non-'Ex nihlo' source has been overrriden	

Support PHI within OMOP


	winnnow_registry_person
		interleave_registry_affiliate_id	INTEGER				NOT NULL,	
		person_id						INTEGER				NOT NULL,	
		first_name						VARCHAR(255)		NOT NULL,
		last_name						VARCHAR(255)		NOT NULL,	
		middle_name						VARCHAR(255)		NOT NULL,		

	winnnow_registry_identifiers
		person_id						INTEGER				NOT NULL,	
		identifier						VARCHAR(255)		NOT NULL,
		identifier_concept_id			INTEGER				NOT NULL,
	    identifer_source_concept_value	VARCHAR(50) 		NOT NULL


Support regsitry expectation configuration

	interleave_data_points
		id							INTEGER				NOT NULL,
		interleave_registry_id			INTEGER				NOT NULL,
		name						VARCHAR(255)		NOT NULL,
		domain_id					VARCHAR(255)		NOT NULL,
x		parent_id					INTEGER				NOT NULL,
x		cardinality					INTEGER				NOT NULL,
		unrestricted				BOOLEAN			  	NOT NULL

	interleave_data_point_concepts
		id								INTEGER				NOT NULL,
		interleave_data_point_id			INTEGER				NOT NULL,
		domain_concept_id				INTEGER				NOT NULL		


	interleave_data_point_relationships
		id							INTEGER			NOT NULL,
		interleave_data_point_id		INTEGER			NOT NULL,
		domain_concept_id			INTEGER			NOT NULL,
		relationship_concept_id		INTEGER			NOT NULL
		
		
		
ln -s /etc/cdsi/db/interleave.yml database.yml 

* possible names

** winnow
** interleave
** interveave
** darn
** knead
** braid
** admix
** weave

*  Maybe use the type_concept_id for provenance of system indication.  And then have another table
maintain the type_concept_id, 

* Looks like observation_period is mandatory.

* Type concepts versus genearl concepts.


* SOURCE_TO_CONCEPT_MAP

* domains are roughly congate with the clinical entities
  domains correspond to domain tables

*  Each Standard Concept belongs to one domain, which defines the location where the Concept would be expected to occur within data tables of the CDM.  


select *
from domain
order by domain_name

select *
from concept
where domain_id = 'Condition'
and standard_concept = 'S'
and concept_name like '%Glioblastoma%'

select *
from concept
where domain_id = 'Gender'


select *
from concept_relationship
where concept_id_1 = 8532

select *
from concept
where concept_id = 44814665


select *
from relationship


select *
from concept_class
where lower(concept_class_name) like '%statin%'

select *
from concept
where lower(concept_name) like '%statin%'
and concept_class_id = 'Pharmacologic Class'
order by concept_name


select *
from concept
where concept_class_id = 'Pharmacologic Class'
order by concept_name


"Somatostatin Analog"


select *
from vocabulary
where vocabulary_reference = 'OMOP generated'
		<commit_msg>Update preliminary analysis document.<commit_after>Support multi-Tenancy

	interleave_registries
		id
		name						VARCHAR(255)		NOT NULL

	interleave_registry_affiliates
		id							INTEGER				NOT NULL,
		interleave_registry_id		INTEGER				NOT NULL,
		name						VARCHAR(255)		NOT NULL

	interleave_registry_affiliate_users
		id									INTEGER				NOT NULL,
		interleave_registry_affiliate_id	INTEGER				NOT NULL,	
		username							VARCHAR(255)		NOT NULL

	interleave_registry_cdm_sources
		id							INTEGER				NOT NULL,
		interleave_registry_id		INTEGER				NOT NULL,
		cdm_source_name				VARCHAR(255)		NOT NULL		--A registry can have multiple sources. Examples: 'RedCap', 'NM EDW', 'Catalona Database', 'PSPORE legacy'
																		--Every registry will include an 'Ex nihlo' entry to support manual entry. 	

		* Should this be at the affiliate level?

Support incremental loads and 'Ex niholo' entry.


	interleave_registry_entities
		id							INTEGER				NOT NULL,
		interleave_registry_id		INTEGER				NOT NULL,
	?	domain_concept_id			INTEGER				NOT NULL,		--polymorphic pointer to representation of entity within OMOP cdm
	?	fact_id						INTEGER				NOT NULL
		cdm_source_name				VARCHAR(255)		NOT NULL,		--polymorphic pointer to source of data
		cdm_source_domain_id		VARCHAR(255)		NULL,			--name of entity within source, not releveant for 'Ex nihlo'
		cdm_source_value			VARCHAR(255)		NULL			--stable identifier, not releveant for 'Ex nihlo'
		overriden					BOOLEAN				NULL			--keep track if an entity created by a non-'Ex nihlo' source has been overrriden	

Support PHI within OMOP

	interleave_person
		interleave_registry_affiliate_id	INTEGER				NOT NULL,	
		person_id							INTEGER				NOT NULL,	
		first_name							VARCHAR(255)		NOT NULL,
		last_name							VARCHAR(255)		NOT NULL,	
		middle_name							VARCHAR(255)		NOT NULL,		

	interleave_person_identifiers
		person_id						INTEGER				NOT NULL,	
		identifier						VARCHAR(255)		NOT NULL,
		identifier_concept_id			INTEGER				NOT NULL,
	    identifer_source_concept_value	VARCHAR(50) 		NOT NULL


Support regsitry expectation configuration

	interleave_data_points
		id							INTEGER				NOT NULL,
		interleave_registry_id		INTEGER				NOT NULL,
		name						VARCHAR(255)		NOT NULL,
		domain_id					VARCHAR(255)		NOT NULL,
		cardinality					INTEGER				NOT NULL,
		unrestricted				BOOLEAN			  	NOT NULL

	interleave_data_point_concepts
		id								INTEGER				NOT NULL,
		interleave_data_point_id		INTEGER				NOT NULL,
		domain_concept_id				INTEGER				NOT NULL		


	interleave_data_point_relationships
		id								INTEGER			NOT NULL,
		interleave_data_point_id		INTEGER			NOT NULL,
		domain_concept_id				INTEGER			NOT NULL,
		relationship_concept_id			INTEGER			NOT NULL
		
		
		
ln -s /etc/cdsi/db/interleave.yml database.yml 

* possible names

** winnow
** interleave
** interveave
** darn
** knead
** braid
** admix
** weave

*  Maybe use the type_concept_id for provenance of system indication.  And then have another table
maintain the type_concept_id, 

* Looks like observation_period is mandatory.

* Type concepts versus genearl concepts.


* SOURCE_TO_CONCEPT_MAP

* domains are roughly congate with the clinical entities
  domains correspond to domain tables

*  Each Standard Concept belongs to one domain, which defines the location where the Concept would be expected to occur within data tables of the CDM.  


select *
from domain
order by domain_name

select *
from concept
where domain_id = 'Condition'
and standard_concept = 'S'
and concept_name like '%Glioblastoma%'

select *
from concept
where domain_id = 'Gender'


select *
from concept_relationship
where concept_id_1 = 8532

select *
from concept
where concept_id = 44814665


select *
from relationship


select *
from concept_class
where lower(concept_class_name) like '%statin%'

select *
from concept
where lower(concept_name) like '%statin%'
and concept_class_id = 'Pharmacologic Class'
order by concept_name


select *
from concept
where concept_class_id = 'Pharmacologic Class'
order by concept_name


"Somatostatin Analog"


select *
from vocabulary
where vocabulary_reference = 'OMOP generated'
		
{'fraction_non_alphanumeric': 0.04645565049945842, 'fraction_numerical': 0.013359008304248405, 'mean_word_length': 3.450990894483128, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '606170', 'n_tokens_mistral': 3380, 'n_tokens_neox': 2729, 'n_words': 857}