Inspectdb to generate django models

Download sql statements files from: https://github.com/OHDSI/CommonDataModel/tree/main/ddl/5.4/postgresql

from laminci.db import setup_local_test_postgres
import lamindb_setup as ln_setup
from django.db import connection
pgurl = setup_local_test_postgres()
57191f10f02c8c9c5208e2d650badc24c3874ecc32a7023db8806d2dcc7a8fa9
馃挕 Created Postgres test instance: 'postgresql://postgres:[email protected]:5432/pgtest'
It runs in docker container 'pgtest'
ln_setup.init(storage="./default_storage", name="lOMOPCDM_5.4", db=pgurl)
for file in [
    "OMOPCDM_postgresql_5.4_ddl.sql", 
    "OMOPCDM_postgresql_5.4_indices.sql", 
    "OMOPCDM_postgresql_5.4_primary_keys.sql", 
    "OMOPCDM_postgresql_5.4_constraints.sql"]:
    print("Executing file:", file)
    with open(file, "r") as sql_file:
        sql_statements = sql_file.read()

    statements = sql_statements.split(";")

    with connection.cursor() as cursor:
        for statement in statements:
            # Remove comments and trailing whitespace
            statement = statement.strip().rstrip("--")
            if statement:  # Skip empty lines and comments
                try:
                    cursor.execute(statement)
                except Exception as e:
                    print("Error executing statement:", statement)
                    print(e)
Executing file: OMOPCDM_postgresql_5.4_indices.sql
Executing file: OMOPCDM_postgresql_5.4_primary_keys.sql
Executing file: OMOPCDM_postgresql_5.4_constraints.sql
ln_setup.django("inspectdb")
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#   * Rearrange models' order
#   * Make sure each model has one field with primary_key=True
#   * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior
#   * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models


class CareSite(models.Model):
    care_site_id = models.IntegerField(primary_key=True)
    care_site_name = models.CharField(max_length=255, blank=True, null=True)
    place_of_service_concept = models.ForeignKey('Concept', models.DO_NOTHING, blank=True, null=True)
    location = models.ForeignKey('Location', models.DO_NOTHING, blank=True, null=True)
    care_site_source_value = models.CharField(max_length=50, blank=True, null=True)
    place_of_service_source_value = models.CharField(max_length=50, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'care_site'


class CdmSource(models.Model):
    cdm_source_name = models.CharField(max_length=255)
    cdm_source_abbreviation = models.CharField(max_length=25)
    cdm_holder = models.CharField(max_length=255)
    source_description = models.TextField(blank=True, null=True)
    source_documentation_reference = models.CharField(max_length=255, blank=True, null=True)
    cdm_etl_reference = models.CharField(max_length=255, blank=True, null=True)
    source_release_date = models.DateField()
    cdm_release_date = models.DateField()
    cdm_version = models.CharField(max_length=10, blank=True, null=True)
    cdm_version_concept = models.ForeignKey('Concept', models.DO_NOTHING)
    vocabulary_version = models.CharField(max_length=20)

    class Meta:
        managed = False
        db_table = 'cdm_source'


class Cohort(models.Model):
    cohort_definition_id = models.IntegerField()
    subject_id = models.IntegerField()
    cohort_start_date = models.DateField()
    cohort_end_date = models.DateField()

    class Meta:
        managed = False
        db_table = 'cohort'


class CohortDefinition(models.Model):
    cohort_definition_id = models.IntegerField()
    cohort_definition_name = models.CharField(max_length=255)
    cohort_definition_description = models.TextField(blank=True, null=True)
    definition_type_concept = models.ForeignKey('Concept', models.DO_NOTHING)
    cohort_definition_syntax = models.TextField(blank=True, null=True)
    subject_concept = models.ForeignKey('Concept', models.DO_NOTHING, related_name='cohortdefinition_subject_concept_set')
    cohort_initiation_date = models.DateField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'cohort_definition'


class Concept(models.Model):
    concept_id = models.IntegerField(primary_key=True)
    concept_name = models.CharField(max_length=255)
    domain = models.ForeignKey('Domain', models.DO_NOTHING)
    vocabulary = models.ForeignKey('Vocabulary', models.DO_NOTHING)
    concept_class = models.ForeignKey('ConceptClass', models.DO_NOTHING)
    standard_concept = models.CharField(max_length=1, blank=True, null=True)
    concept_code = models.CharField(max_length=50)
    valid_start_date = models.DateField()
    valid_end_date = models.DateField()
    invalid_reason = models.CharField(max_length=1, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'concept'


class ConceptAncestor(models.Model):
    ancestor_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    descendant_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='conceptancestor_descendant_concept_set')
    min_levels_of_separation = models.IntegerField()
    max_levels_of_separation = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'concept_ancestor'


class ConceptClass(models.Model):
    concept_class_id = models.CharField(primary_key=True, max_length=20)
    concept_class_name = models.CharField(max_length=255)
    concept_class_concept = models.ForeignKey(Concept, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'concept_class'


class ConceptRelationship(models.Model):
    concept_id_1 = models.ForeignKey(Concept, models.DO_NOTHING, db_column='concept_id_1')
    concept_id_2 = models.ForeignKey(Concept, models.DO_NOTHING, db_column='concept_id_2', related_name='conceptrelationship_concept_id_2_set')
    relationship = models.ForeignKey('Relationship', models.DO_NOTHING)
    valid_start_date = models.DateField()
    valid_end_date = models.DateField()
    invalid_reason = models.CharField(max_length=1, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'concept_relationship'


class ConceptSynonym(models.Model):
    concept = models.ForeignKey(Concept, models.DO_NOTHING)
    concept_synonym_name = models.CharField(max_length=1000)
    language_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='conceptsynonym_language_concept_set')

    class Meta:
        managed = False
        db_table = 'concept_synonym'


class ConditionEra(models.Model):
    condition_era_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    condition_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    condition_era_start_date = models.DateField()
    condition_era_end_date = models.DateField()
    condition_occurrence_count = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'condition_era'


class ConditionOccurrence(models.Model):
    condition_occurrence_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    condition_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    condition_start_date = models.DateField()
    condition_start_datetime = models.DateTimeField(blank=True, null=True)
    condition_end_date = models.DateField(blank=True, null=True)
    condition_end_datetime = models.DateTimeField(blank=True, null=True)
    condition_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='conditionoccurrence_condition_type_concept_set')
    condition_status_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='conditionoccurrence_condition_status_concept_set', blank=True, null=True)
    stop_reason = models.CharField(max_length=20, blank=True, null=True)
    provider = models.ForeignKey('Provider', models.DO_NOTHING, blank=True, null=True)
    visit_occurrence = models.ForeignKey('VisitOccurrence', models.DO_NOTHING, blank=True, null=True)
    visit_detail = models.ForeignKey('VisitDetail', models.DO_NOTHING, blank=True, null=True)
    condition_source_value = models.CharField(max_length=50, blank=True, null=True)
    condition_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='conditionoccurrence_condition_source_concept_set', blank=True, null=True)
    condition_status_source_value = models.CharField(max_length=50, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'condition_occurrence'


class Cost(models.Model):
    cost_id = models.IntegerField(primary_key=True)
    cost_event_id = models.IntegerField()
    cost_domain = models.ForeignKey('Domain', models.DO_NOTHING)
    cost_type_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    currency_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='cost_currency_concept_set', blank=True, null=True)
    total_charge = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    total_cost = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    total_paid = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    paid_by_payer = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    paid_by_patient = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    paid_patient_copay = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    paid_patient_coinsurance = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    paid_patient_deductible = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    paid_by_primary = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    paid_ingredient_cost = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    paid_dispensing_fee = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    payer_plan_period_id = models.IntegerField(blank=True, null=True)
    amount_allowed = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    revenue_code_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='cost_revenue_code_concept_set', blank=True, null=True)
    revenue_code_source_value = models.CharField(max_length=50, blank=True, null=True)
    drg_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='cost_drg_concept_set', blank=True, null=True)
    drg_source_value = models.CharField(max_length=3, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'cost'


class Death(models.Model):
    person = models.ForeignKey('Person', models.DO_NOTHING)
    death_date = models.DateField()
    death_datetime = models.DateTimeField(blank=True, null=True)
    death_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, blank=True, null=True)
    cause_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='death_cause_concept_set', blank=True, null=True)
    cause_source_value = models.CharField(max_length=50, blank=True, null=True)
    cause_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='death_cause_source_concept_set', blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'death'


class DeviceExposure(models.Model):
    device_exposure_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    device_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    device_exposure_start_date = models.DateField()
    device_exposure_start_datetime = models.DateTimeField(blank=True, null=True)
    device_exposure_end_date = models.DateField(blank=True, null=True)
    device_exposure_end_datetime = models.DateTimeField(blank=True, null=True)
    device_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='deviceexposure_device_type_concept_set')
    unique_device_id = models.CharField(max_length=255, blank=True, null=True)
    production_id = models.CharField(max_length=255, blank=True, null=True)
    quantity = models.IntegerField(blank=True, null=True)
    provider = models.ForeignKey('Provider', models.DO_NOTHING, blank=True, null=True)
    visit_occurrence = models.ForeignKey('VisitOccurrence', models.DO_NOTHING, blank=True, null=True)
    visit_detail = models.ForeignKey('VisitDetail', models.DO_NOTHING, blank=True, null=True)
    device_source_value = models.CharField(max_length=50, blank=True, null=True)
    device_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='deviceexposure_device_source_concept_set', blank=True, null=True)
    unit_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='deviceexposure_unit_concept_set', blank=True, null=True)
    unit_source_value = models.CharField(max_length=50, blank=True, null=True)
    unit_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='deviceexposure_unit_source_concept_set', blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'device_exposure'


class DjangoMigrations(models.Model):
    id = models.BigAutoField(primary_key=True)
    app = models.CharField(max_length=255)
    name = models.CharField(max_length=255)
    applied = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'django_migrations'


class Domain(models.Model):
    domain_id = models.CharField(primary_key=True, max_length=20)
    domain_name = models.CharField(max_length=255)
    domain_concept = models.ForeignKey(Concept, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'domain'


class DoseEra(models.Model):
    dose_era_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    drug_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    unit_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='doseera_unit_concept_set')
    dose_value = models.DecimalField(max_digits=65535, decimal_places=65535)
    dose_era_start_date = models.DateField()
    dose_era_end_date = models.DateField()

    class Meta:
        managed = False
        db_table = 'dose_era'


class DrugEra(models.Model):
    drug_era_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    drug_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    drug_era_start_date = models.DateField()
    drug_era_end_date = models.DateField()
    drug_exposure_count = models.IntegerField(blank=True, null=True)
    gap_days = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'drug_era'


class DrugExposure(models.Model):
    drug_exposure_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    drug_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    drug_exposure_start_date = models.DateField()
    drug_exposure_start_datetime = models.DateTimeField(blank=True, null=True)
    drug_exposure_end_date = models.DateField()
    drug_exposure_end_datetime = models.DateTimeField(blank=True, null=True)
    verbatim_end_date = models.DateField(blank=True, null=True)
    drug_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='drugexposure_drug_type_concept_set')
    stop_reason = models.CharField(max_length=20, blank=True, null=True)
    refills = models.IntegerField(blank=True, null=True)
    quantity = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    days_supply = models.IntegerField(blank=True, null=True)
    sig = models.TextField(blank=True, null=True)
    route_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='drugexposure_route_concept_set', blank=True, null=True)
    lot_number = models.CharField(max_length=50, blank=True, null=True)
    provider = models.ForeignKey('Provider', models.DO_NOTHING, blank=True, null=True)
    visit_occurrence = models.ForeignKey('VisitOccurrence', models.DO_NOTHING, blank=True, null=True)
    visit_detail = models.ForeignKey('VisitDetail', models.DO_NOTHING, blank=True, null=True)
    drug_source_value = models.CharField(max_length=50, blank=True, null=True)
    drug_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='drugexposure_drug_source_concept_set', blank=True, null=True)
    route_source_value = models.CharField(max_length=50, blank=True, null=True)
    dose_unit_source_value = models.CharField(max_length=50, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'drug_exposure'


class DrugStrength(models.Model):
    drug_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    ingredient_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='drugstrength_ingredient_concept_set')
    amount_value = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    amount_unit_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='drugstrength_amount_unit_concept_set', blank=True, null=True)
    numerator_value = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    numerator_unit_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='drugstrength_numerator_unit_concept_set', blank=True, null=True)
    denominator_value = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    denominator_unit_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='drugstrength_denominator_unit_concept_set', blank=True, null=True)
    box_size = models.IntegerField(blank=True, null=True)
    valid_start_date = models.DateField()
    valid_end_date = models.DateField()
    invalid_reason = models.CharField(max_length=1, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'drug_strength'


class Episode(models.Model):
    episode_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    episode_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    episode_start_date = models.DateField()
    episode_start_datetime = models.DateTimeField(blank=True, null=True)
    episode_end_date = models.DateField(blank=True, null=True)
    episode_end_datetime = models.DateTimeField(blank=True, null=True)
    episode_parent_id = models.IntegerField(blank=True, null=True)
    episode_number = models.IntegerField(blank=True, null=True)
    episode_object_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='episode_episode_object_concept_set')
    episode_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='episode_episode_type_concept_set')
    episode_source_value = models.CharField(max_length=50, blank=True, null=True)
    episode_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='episode_episode_source_concept_set', blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'episode'


class EpisodeEvent(models.Model):
    episode = models.ForeignKey(Episode, models.DO_NOTHING)
    event_id = models.IntegerField()
    episode_event_field_concept = models.ForeignKey(Concept, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'episode_event'


class FactRelationship(models.Model):
    domain_concept_id_1 = models.ForeignKey(Concept, models.DO_NOTHING, db_column='domain_concept_id_1')
    fact_id_1 = models.IntegerField()
    domain_concept_id_2 = models.ForeignKey(Concept, models.DO_NOTHING, db_column='domain_concept_id_2', related_name='factrelationship_domain_concept_id_2_set')
    fact_id_2 = models.IntegerField()
    relationship_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='factrelationship_relationship_concept_set')

    class Meta:
        managed = False
        db_table = 'fact_relationship'


class LnschemaCoreArtifact(models.Model):
    uid = models.CharField(unique=True, max_length=20)
    key = models.CharField(max_length=255, blank=True, null=True)
    suffix = models.CharField(max_length=30)
    accessor = models.CharField(max_length=64, blank=True, null=True)
    description = models.CharField(max_length=255, blank=True, null=True)
    version = models.CharField(max_length=10, blank=True, null=True)
    size = models.BigIntegerField(blank=True, null=True)
    hash = models.CharField(max_length=86, blank=True, null=True)
    hash_type = models.CharField(max_length=30, blank=True, null=True)
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()
    created_by = models.ForeignKey('LnschemaCoreUser', models.DO_NOTHING)
    run = models.ForeignKey('LnschemaCoreRun', models.DO_NOTHING, blank=True, null=True)
    storage = models.ForeignKey('LnschemaCoreStorage', models.DO_NOTHING)
    transform = models.ForeignKey('LnschemaCoreTransform', models.DO_NOTHING, blank=True, null=True)
    visibility = models.SmallIntegerField()
    key_is_virtual = models.BooleanField()
    n_objects = models.BigIntegerField(blank=True, null=True)
    n_observations = models.BigIntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'lnschema_core_artifact'


class LnschemaCoreArtifactInputOf(models.Model):
    id = models.BigAutoField(primary_key=True)
    artifact = models.ForeignKey(LnschemaCoreArtifact, models.DO_NOTHING)
    run = models.ForeignKey('LnschemaCoreRun', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_artifact_input_of'
        unique_together = (('artifact', 'run'),)


class LnschemaCoreArtifactfeatureset(models.Model):
    id = models.BigAutoField(primary_key=True)
    slot = models.CharField(max_length=40, blank=True, null=True)
    feature_set = models.ForeignKey('LnschemaCoreFeatureset', models.DO_NOTHING)
    artifact = models.ForeignKey(LnschemaCoreArtifact, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_artifactfeatureset'
        unique_together = (('artifact', 'feature_set'),)


class LnschemaCoreArtifactulabel(models.Model):
    id = models.BigAutoField(primary_key=True)
    feature = models.ForeignKey('LnschemaCoreFeature', models.DO_NOTHING, blank=True, null=True)
    artifact = models.ForeignKey(LnschemaCoreArtifact, models.DO_NOTHING)
    ulabel = models.ForeignKey('LnschemaCoreUlabel', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_artifactulabel'
        unique_together = (('artifact', 'ulabel'),)


class LnschemaCoreCollection(models.Model):
    uid = models.CharField(unique=True, max_length=20)
    name = models.CharField(max_length=150)
    description = models.TextField(blank=True, null=True)
    version = models.CharField(max_length=10, blank=True, null=True)
    hash = models.CharField(max_length=86, blank=True, null=True)
    reference = models.CharField(max_length=255, blank=True, null=True)
    reference_type = models.CharField(max_length=25, blank=True, null=True)
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()
    created_by = models.ForeignKey('LnschemaCoreUser', models.DO_NOTHING)
    artifact = models.OneToOneField(LnschemaCoreArtifact, models.DO_NOTHING, blank=True, null=True)
    run = models.ForeignKey('LnschemaCoreRun', models.DO_NOTHING, blank=True, null=True)
    transform = models.ForeignKey('LnschemaCoreTransform', models.DO_NOTHING, blank=True, null=True)
    visibility = models.SmallIntegerField()

    class Meta:
        managed = False
        db_table = 'lnschema_core_collection'


class LnschemaCoreCollectionInputOf(models.Model):
    id = models.BigAutoField(primary_key=True)
    collection = models.ForeignKey(LnschemaCoreCollection, models.DO_NOTHING)
    run = models.ForeignKey('LnschemaCoreRun', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_collection_input_of'
        unique_together = (('collection', 'run'),)


class LnschemaCoreCollectionartifact(models.Model):
    id = models.BigAutoField(primary_key=True)
    collection = models.ForeignKey(LnschemaCoreCollection, models.DO_NOTHING)
    artifact = models.ForeignKey(LnschemaCoreArtifact, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_collectionartifact'
        unique_together = (('collection', 'artifact'),)


class LnschemaCoreCollectionfeatureset(models.Model):
    id = models.BigAutoField(primary_key=True)
    slot = models.CharField(max_length=50, blank=True, null=True)
    collection = models.ForeignKey(LnschemaCoreCollection, models.DO_NOTHING)
    feature_set = models.ForeignKey('LnschemaCoreFeatureset', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_collectionfeatureset'
        unique_together = (('collection', 'feature_set'),)


class LnschemaCoreCollectionulabel(models.Model):
    id = models.BigAutoField(primary_key=True)
    collection = models.ForeignKey(LnschemaCoreCollection, models.DO_NOTHING)
    feature = models.ForeignKey('LnschemaCoreFeature', models.DO_NOTHING, blank=True, null=True)
    ulabel = models.ForeignKey('LnschemaCoreUlabel', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_collectionulabel'
        unique_together = (('collection', 'ulabel'),)


class LnschemaCoreFeature(models.Model):
    uid = models.CharField(unique=True, max_length=12)
    name = models.CharField(max_length=150)
    type = models.CharField(max_length=64)
    unit = models.CharField(max_length=30, blank=True, null=True)
    description = models.TextField(blank=True, null=True)
    registries = models.CharField(max_length=120, blank=True, null=True)
    synonyms = models.TextField(blank=True, null=True)
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()
    created_by = models.ForeignKey('LnschemaCoreUser', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_feature'


class LnschemaCoreFeatureFeatureSets(models.Model):
    id = models.BigAutoField(primary_key=True)
    feature = models.ForeignKey(LnschemaCoreFeature, models.DO_NOTHING)
    featureset = models.ForeignKey('LnschemaCoreFeatureset', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_feature_feature_sets'
        unique_together = (('feature', 'featureset'),)


class LnschemaCoreFeatureset(models.Model):
    uid = models.CharField(unique=True, max_length=20)
    name = models.CharField(max_length=150, blank=True, null=True)
    n = models.IntegerField()
    type = models.CharField(max_length=64, blank=True, null=True)
    registry = models.CharField(max_length=120)
    hash = models.CharField(max_length=20, blank=True, null=True)
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()
    created_by = models.ForeignKey('LnschemaCoreUser', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_featureset'


class LnschemaCoreRun(models.Model):
    id = models.BigAutoField(primary_key=True)
    uid = models.CharField(unique=True, max_length=20)
    started_at = models.DateTimeField()
    is_consecutive = models.BooleanField(blank=True, null=True)
    reference = models.CharField(max_length=255, blank=True, null=True)
    reference_type = models.CharField(max_length=25, blank=True, null=True)
    created_at = models.DateTimeField()
    created_by = models.ForeignKey('LnschemaCoreUser', models.DO_NOTHING)
    report = models.ForeignKey(LnschemaCoreArtifact, models.DO_NOTHING, blank=True, null=True)
    transform = models.ForeignKey('LnschemaCoreTransform', models.DO_NOTHING)
    environment = models.ForeignKey(LnschemaCoreArtifact, models.DO_NOTHING, related_name='lnschemacorerun_environment_set', blank=True, null=True)
    finished_at = models.DateTimeField(blank=True, null=True)
    json = models.JSONField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'lnschema_core_run'


class LnschemaCoreRunReplicatedOutputArtifacts(models.Model):
    id = models.BigAutoField(primary_key=True)
    run = models.ForeignKey(LnschemaCoreRun, models.DO_NOTHING)
    artifact = models.ForeignKey(LnschemaCoreArtifact, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_run_replicated_output_artifacts'
        unique_together = (('run', 'artifact'),)


class LnschemaCoreRunReplicatedOutputCollections(models.Model):
    id = models.BigAutoField(primary_key=True)
    run = models.ForeignKey(LnschemaCoreRun, models.DO_NOTHING)
    collection = models.ForeignKey(LnschemaCoreCollection, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_run_replicated_output_collections'
        unique_together = (('run', 'collection'),)


class LnschemaCoreStorage(models.Model):
    uid = models.CharField(unique=True, max_length=12)
    root = models.CharField(unique=True, max_length=255)
    type = models.CharField(max_length=30)
    region = models.CharField(max_length=64, blank=True, null=True)
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()
    created_by = models.ForeignKey('LnschemaCoreUser', models.DO_NOTHING)
    description = models.CharField(max_length=255, blank=True, null=True)
    instance_uid = models.CharField(max_length=12, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'lnschema_core_storage'


class LnschemaCoreTransform(models.Model):
    uid = models.CharField(unique=True, max_length=16)
    name = models.CharField(max_length=150, blank=True, null=True)
    key = models.CharField(max_length=120, blank=True, null=True)
    version = models.CharField(max_length=10, blank=True, null=True)
    type = models.CharField(max_length=20)
    reference = models.CharField(max_length=255, blank=True, null=True)
    reference_type = models.CharField(max_length=25, blank=True, null=True)
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()
    created_by = models.ForeignKey('LnschemaCoreUser', models.DO_NOTHING)
    latest_report = models.ForeignKey(LnschemaCoreArtifact, models.DO_NOTHING, blank=True, null=True)
    source_code = models.ForeignKey(LnschemaCoreArtifact, models.DO_NOTHING, related_name='lnschemacoretransform_source_code_set', blank=True, null=True)
    description = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'lnschema_core_transform'


class LnschemaCoreTransformParents(models.Model):
    id = models.BigAutoField(primary_key=True)
    from_transform = models.ForeignKey(LnschemaCoreTransform, models.DO_NOTHING)
    to_transform = models.ForeignKey(LnschemaCoreTransform, models.DO_NOTHING, related_name='lnschemacoretransformparents_to_transform_set')

    class Meta:
        managed = False
        db_table = 'lnschema_core_transform_parents'
        unique_together = (('from_transform', 'to_transform'),)


class LnschemaCoreTransformUlabels(models.Model):
    id = models.BigAutoField(primary_key=True)
    transform = models.ForeignKey(LnschemaCoreTransform, models.DO_NOTHING)
    ulabel = models.ForeignKey('LnschemaCoreUlabel', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_transform_ulabels'
        unique_together = (('transform', 'ulabel'),)


class LnschemaCoreUlabel(models.Model):
    uid = models.CharField(unique=True, max_length=8)
    name = models.CharField(unique=True, max_length=150)
    description = models.TextField(blank=True, null=True)
    reference = models.CharField(max_length=255, blank=True, null=True)
    reference_type = models.CharField(max_length=25, blank=True, null=True)
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()
    created_by = models.ForeignKey('LnschemaCoreUser', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'lnschema_core_ulabel'


class LnschemaCoreUlabelParents(models.Model):
    id = models.BigAutoField(primary_key=True)
    from_ulabel = models.ForeignKey(LnschemaCoreUlabel, models.DO_NOTHING)
    to_ulabel = models.ForeignKey(LnschemaCoreUlabel, models.DO_NOTHING, related_name='lnschemacoreulabelparents_to_ulabel_set')

    class Meta:
        managed = False
        db_table = 'lnschema_core_ulabel_parents'
        unique_together = (('from_ulabel', 'to_ulabel'),)


class LnschemaCoreUser(models.Model):
    uid = models.CharField(unique=True, max_length=8)
    handle = models.CharField(unique=True, max_length=30)
    name = models.CharField(max_length=150, blank=True, null=True)
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'lnschema_core_user'


class Location(models.Model):
    location_id = models.IntegerField(primary_key=True)
    address_1 = models.CharField(max_length=50, blank=True, null=True)
    address_2 = models.CharField(max_length=50, blank=True, null=True)
    city = models.CharField(max_length=50, blank=True, null=True)
    state = models.CharField(max_length=2, blank=True, null=True)
    zip = models.CharField(max_length=9, blank=True, null=True)
    county = models.CharField(max_length=20, blank=True, null=True)
    location_source_value = models.CharField(max_length=50, blank=True, null=True)
    country_concept = models.ForeignKey(Concept, models.DO_NOTHING, blank=True, null=True)
    country_source_value = models.CharField(max_length=80, blank=True, null=True)
    latitude = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    longitude = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'location'


class Measurement(models.Model):
    measurement_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    measurement_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    measurement_date = models.DateField()
    measurement_datetime = models.DateTimeField(blank=True, null=True)
    measurement_time = models.CharField(max_length=10, blank=True, null=True)
    measurement_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='measurement_measurement_type_concept_set')
    operator_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='measurement_operator_concept_set', blank=True, null=True)
    value_as_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    value_as_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='measurement_value_as_concept_set', blank=True, null=True)
    unit_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='measurement_unit_concept_set', blank=True, null=True)
    range_low = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    range_high = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    provider = models.ForeignKey('Provider', models.DO_NOTHING, blank=True, null=True)
    visit_occurrence = models.ForeignKey('VisitOccurrence', models.DO_NOTHING, blank=True, null=True)
    visit_detail = models.ForeignKey('VisitDetail', models.DO_NOTHING, blank=True, null=True)
    measurement_source_value = models.CharField(max_length=50, blank=True, null=True)
    measurement_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='measurement_measurement_source_concept_set', blank=True, null=True)
    unit_source_value = models.CharField(max_length=50, blank=True, null=True)
    unit_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='measurement_unit_source_concept_set', blank=True, null=True)
    value_source_value = models.CharField(max_length=50, blank=True, null=True)
    measurement_event_id = models.IntegerField(blank=True, null=True)
    meas_event_field_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='measurement_meas_event_field_concept_set', blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'measurement'


class Metadata(models.Model):
    metadata_id = models.IntegerField(primary_key=True)
    metadata_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    metadata_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='metadata_metadata_type_concept_set')
    name = models.CharField(max_length=250)
    value_as_string = models.CharField(max_length=250, blank=True, null=True)
    value_as_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='metadata_value_as_concept_set', blank=True, null=True)
    value_as_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    metadata_date = models.DateField(blank=True, null=True)
    metadata_datetime = models.DateTimeField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'metadata'


class Note(models.Model):
    note_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    note_date = models.DateField()
    note_datetime = models.DateTimeField(blank=True, null=True)
    note_type_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    note_class_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='note_note_class_concept_set')
    note_title = models.CharField(max_length=250, blank=True, null=True)
    note_text = models.TextField()
    encoding_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='note_encoding_concept_set')
    language_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='note_language_concept_set')
    provider = models.ForeignKey('Provider', models.DO_NOTHING, blank=True, null=True)
    visit_occurrence = models.ForeignKey('VisitOccurrence', models.DO_NOTHING, blank=True, null=True)
    visit_detail = models.ForeignKey('VisitDetail', models.DO_NOTHING, blank=True, null=True)
    note_source_value = models.CharField(max_length=50, blank=True, null=True)
    note_event_id = models.IntegerField(blank=True, null=True)
    note_event_field_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='note_note_event_field_concept_set', blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'note'


class NoteNlp(models.Model):
    note_nlp_id = models.IntegerField(primary_key=True)
    note_id = models.IntegerField()
    section_concept = models.ForeignKey(Concept, models.DO_NOTHING, blank=True, null=True)
    snippet = models.CharField(max_length=250, blank=True, null=True)
    offset = models.CharField(max_length=50, blank=True, null=True)
    lexical_variant = models.CharField(max_length=250)
    note_nlp_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='notenlp_note_nlp_concept_set', blank=True, null=True)
    note_nlp_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='notenlp_note_nlp_source_concept_set', blank=True, null=True)
    nlp_system = models.CharField(max_length=250, blank=True, null=True)
    nlp_date = models.DateField()
    nlp_datetime = models.DateTimeField(blank=True, null=True)
    term_exists = models.CharField(max_length=1, blank=True, null=True)
    term_temporal = models.CharField(max_length=50, blank=True, null=True)
    term_modifiers = models.CharField(max_length=2000, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'note_nlp'


class Observation(models.Model):
    observation_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    observation_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    observation_date = models.DateField()
    observation_datetime = models.DateTimeField(blank=True, null=True)
    observation_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='observation_observation_type_concept_set')
    value_as_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    value_as_string = models.CharField(max_length=60, blank=True, null=True)
    value_as_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='observation_value_as_concept_set', blank=True, null=True)
    qualifier_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='observation_qualifier_concept_set', blank=True, null=True)
    unit_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='observation_unit_concept_set', blank=True, null=True)
    provider = models.ForeignKey('Provider', models.DO_NOTHING, blank=True, null=True)
    visit_occurrence = models.ForeignKey('VisitOccurrence', models.DO_NOTHING, blank=True, null=True)
    visit_detail = models.ForeignKey('VisitDetail', models.DO_NOTHING, blank=True, null=True)
    observation_source_value = models.CharField(max_length=50, blank=True, null=True)
    observation_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='observation_observation_source_concept_set', blank=True, null=True)
    unit_source_value = models.CharField(max_length=50, blank=True, null=True)
    qualifier_source_value = models.CharField(max_length=50, blank=True, null=True)
    value_source_value = models.CharField(max_length=50, blank=True, null=True)
    observation_event_id = models.IntegerField(blank=True, null=True)
    obs_event_field_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='observation_obs_event_field_concept_set', blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'observation'


class ObservationPeriod(models.Model):
    observation_period_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    observation_period_start_date = models.DateField()
    observation_period_end_date = models.DateField()
    period_type_concept = models.ForeignKey(Concept, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'observation_period'


class PayerPlanPeriod(models.Model):
    payer_plan_period_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey('Person', models.DO_NOTHING)
    payer_plan_period_start_date = models.DateField()
    payer_plan_period_end_date = models.DateField()
    payer_concept = models.ForeignKey(Concept, models.DO_NOTHING, blank=True, null=True)
    payer_source_value = models.CharField(max_length=50, blank=True, null=True)
    payer_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='payerplanperiod_payer_source_concept_set', blank=True, null=True)
    plan_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='payerplanperiod_plan_concept_set', blank=True, null=True)
    plan_source_value = models.CharField(max_length=50, blank=True, null=True)
    plan_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='payerplanperiod_plan_source_concept_set', blank=True, null=True)
    sponsor_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='payerplanperiod_sponsor_concept_set', blank=True, null=True)
    sponsor_source_value = models.CharField(max_length=50, blank=True, null=True)
    sponsor_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='payerplanperiod_sponsor_source_concept_set', blank=True, null=True)
    family_source_value = models.CharField(max_length=50, blank=True, null=True)
    stop_reason_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='payerplanperiod_stop_reason_concept_set', blank=True, null=True)
    stop_reason_source_value = models.CharField(max_length=50, blank=True, null=True)
    stop_reason_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='payerplanperiod_stop_reason_source_concept_set', blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'payer_plan_period'


class Person(models.Model):
    person_id = models.IntegerField(primary_key=True)
    gender_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    year_of_birth = models.IntegerField()
    month_of_birth = models.IntegerField(blank=True, null=True)
    day_of_birth = models.IntegerField(blank=True, null=True)
    birth_datetime = models.DateTimeField(blank=True, null=True)
    race_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='person_race_concept_set')
    ethnicity_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='person_ethnicity_concept_set')
    location = models.ForeignKey(Location, models.DO_NOTHING, blank=True, null=True)
    provider = models.ForeignKey('Provider', models.DO_NOTHING, blank=True, null=True)
    care_site = models.ForeignKey(CareSite, models.DO_NOTHING, blank=True, null=True)
    person_source_value = models.CharField(max_length=50, blank=True, null=True)
    gender_source_value = models.CharField(max_length=50, blank=True, null=True)
    gender_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='person_gender_source_concept_set', blank=True, null=True)
    race_source_value = models.CharField(max_length=50, blank=True, null=True)
    race_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='person_race_source_concept_set', blank=True, null=True)
    ethnicity_source_value = models.CharField(max_length=50, blank=True, null=True)
    ethnicity_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='person_ethnicity_source_concept_set', blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'person'


class ProcedureOccurrence(models.Model):
    procedure_occurrence_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey(Person, models.DO_NOTHING)
    procedure_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    procedure_date = models.DateField()
    procedure_datetime = models.DateTimeField(blank=True, null=True)
    procedure_end_date = models.DateField(blank=True, null=True)
    procedure_end_datetime = models.DateTimeField(blank=True, null=True)
    procedure_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='procedureoccurrence_procedure_type_concept_set')
    modifier_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='procedureoccurrence_modifier_concept_set', blank=True, null=True)
    quantity = models.IntegerField(blank=True, null=True)
    provider = models.ForeignKey('Provider', models.DO_NOTHING, blank=True, null=True)
    visit_occurrence = models.ForeignKey('VisitOccurrence', models.DO_NOTHING, blank=True, null=True)
    visit_detail = models.ForeignKey('VisitDetail', models.DO_NOTHING, blank=True, null=True)
    procedure_source_value = models.CharField(max_length=50, blank=True, null=True)
    procedure_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='procedureoccurrence_procedure_source_concept_set', blank=True, null=True)
    modifier_source_value = models.CharField(max_length=50, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'procedure_occurrence'


class Provider(models.Model):
    provider_id = models.IntegerField(primary_key=True)
    provider_name = models.CharField(max_length=255, blank=True, null=True)
    npi = models.CharField(max_length=20, blank=True, null=True)
    dea = models.CharField(max_length=20, blank=True, null=True)
    specialty_concept = models.ForeignKey(Concept, models.DO_NOTHING, blank=True, null=True)
    care_site = models.ForeignKey(CareSite, models.DO_NOTHING, blank=True, null=True)
    year_of_birth = models.IntegerField(blank=True, null=True)
    gender_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='provider_gender_concept_set', blank=True, null=True)
    provider_source_value = models.CharField(max_length=50, blank=True, null=True)
    specialty_source_value = models.CharField(max_length=50, blank=True, null=True)
    specialty_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='provider_specialty_source_concept_set', blank=True, null=True)
    gender_source_value = models.CharField(max_length=50, blank=True, null=True)
    gender_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='provider_gender_source_concept_set', blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'provider'


class Relationship(models.Model):
    relationship_id = models.CharField(primary_key=True, max_length=20)
    relationship_name = models.CharField(max_length=255)
    is_hierarchical = models.CharField(max_length=1)
    defines_ancestry = models.CharField(max_length=1)
    reverse_relationship_id = models.CharField(max_length=20)
    relationship_concept = models.ForeignKey(Concept, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'relationship'


class SourceToConceptMap(models.Model):
    source_code = models.CharField(max_length=50)
    source_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    source_vocabulary_id = models.CharField(max_length=20)
    source_code_description = models.CharField(max_length=255, blank=True, null=True)
    target_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='sourcetoconceptmap_target_concept_set')
    target_vocabulary = models.ForeignKey('Vocabulary', models.DO_NOTHING)
    valid_start_date = models.DateField()
    valid_end_date = models.DateField()
    invalid_reason = models.CharField(max_length=1, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'source_to_concept_map'


class Specimen(models.Model):
    specimen_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey(Person, models.DO_NOTHING)
    specimen_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    specimen_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='specimen_specimen_type_concept_set')
    specimen_date = models.DateField()
    specimen_datetime = models.DateTimeField(blank=True, null=True)
    quantity = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    unit_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='specimen_unit_concept_set', blank=True, null=True)
    anatomic_site_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='specimen_anatomic_site_concept_set', blank=True, null=True)
    disease_status_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='specimen_disease_status_concept_set', blank=True, null=True)
    specimen_source_id = models.CharField(max_length=50, blank=True, null=True)
    specimen_source_value = models.CharField(max_length=50, blank=True, null=True)
    unit_source_value = models.CharField(max_length=50, blank=True, null=True)
    anatomic_site_source_value = models.CharField(max_length=50, blank=True, null=True)
    disease_status_source_value = models.CharField(max_length=50, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'specimen'


class VisitDetail(models.Model):
    visit_detail_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey(Person, models.DO_NOTHING)
    visit_detail_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    visit_detail_start_date = models.DateField()
    visit_detail_start_datetime = models.DateTimeField(blank=True, null=True)
    visit_detail_end_date = models.DateField()
    visit_detail_end_datetime = models.DateTimeField(blank=True, null=True)
    visit_detail_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='visitdetail_visit_detail_type_concept_set')
    provider = models.ForeignKey(Provider, models.DO_NOTHING, blank=True, null=True)
    care_site = models.ForeignKey(CareSite, models.DO_NOTHING, blank=True, null=True)
    visit_detail_source_value = models.CharField(max_length=50, blank=True, null=True)
    visit_detail_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='visitdetail_visit_detail_source_concept_set', blank=True, null=True)
    admitted_from_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='visitdetail_admitted_from_concept_set', blank=True, null=True)
    admitted_from_source_value = models.CharField(max_length=50, blank=True, null=True)
    discharged_to_source_value = models.CharField(max_length=50, blank=True, null=True)
    discharged_to_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='visitdetail_discharged_to_concept_set', blank=True, null=True)
    preceding_visit_detail = models.ForeignKey('self', models.DO_NOTHING, blank=True, null=True)
    parent_visit_detail = models.ForeignKey('self', models.DO_NOTHING, related_name='visitdetail_parent_visit_detail_set', blank=True, null=True)
    visit_occurrence = models.ForeignKey('VisitOccurrence', models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'visit_detail'


class VisitOccurrence(models.Model):
    visit_occurrence_id = models.IntegerField(primary_key=True)
    person = models.ForeignKey(Person, models.DO_NOTHING)
    visit_concept = models.ForeignKey(Concept, models.DO_NOTHING)
    visit_start_date = models.DateField()
    visit_start_datetime = models.DateTimeField(blank=True, null=True)
    visit_end_date = models.DateField()
    visit_end_datetime = models.DateTimeField(blank=True, null=True)
    visit_type_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='visitoccurrence_visit_type_concept_set')
    provider = models.ForeignKey(Provider, models.DO_NOTHING, blank=True, null=True)
    care_site = models.ForeignKey(CareSite, models.DO_NOTHING, blank=True, null=True)
    visit_source_value = models.CharField(max_length=50, blank=True, null=True)
    visit_source_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='visitoccurrence_visit_source_concept_set', blank=True, null=True)
    admitted_from_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='visitoccurrence_admitted_from_concept_set', blank=True, null=True)
    admitted_from_source_value = models.CharField(max_length=50, blank=True, null=True)
    discharged_to_concept = models.ForeignKey(Concept, models.DO_NOTHING, related_name='visitoccurrence_discharged_to_concept_set', blank=True, null=True)
    discharged_to_source_value = models.CharField(max_length=50, blank=True, null=True)
    preceding_visit_occurrence = models.ForeignKey('self', models.DO_NOTHING, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'visit_occurrence'


class Vocabulary(models.Model):
    vocabulary_id = models.CharField(primary_key=True, max_length=20)
    vocabulary_name = models.CharField(max_length=255)
    vocabulary_reference = models.CharField(max_length=255, blank=True, null=True)
    vocabulary_version = models.CharField(max_length=255, blank=True, null=True)
    vocabulary_concept = models.ForeignKey(Concept, models.DO_NOTHING)

    class Meta:
        managed = False
        db_table = 'vocabulary'
def remove_lnchema_classes(file_path):
    """
    Removes entire classes starting with "Lnschema" from a Python file.

    Args:
    file_path: Path to the Python file.

    Returns:
    A string containing the modified code without "Lnschema" classes.
    """

    with open(file_path, "r") as f:
        content = f.readlines()

    # Flag to track if inside a class definition
    in_class = False
    class_name = None
    modified_lines = []

    for line in content:
        if line.strip().startswith("class Lnschema"):
            # Start of a class with "Lnschema" prefix
            in_class = True
            class_name = line.split()[1]  # Extract class name
        elif line.strip() == "}" and in_class:
            # End of the class with "Lnschema" prefix
            in_class = False
            class_name = None
        elif not in_class:
            # Lines outside a class or not starting with "Lnschema" class
            modified_lines.append(line)
        else:
            # Skip lines inside a class with "Lnschema" prefix
            pass

    return "".join(modified_lines)

# Example usage
file_path = "your_models.py"  # Replace with your actual file path
modified_code = remove_lnchema_classes(file_path)

# Optionally, write the modified code to a new file
with open("modified_models.py", "w") as f:
    f.write(modified_code)

print("Successfully removed entire 'Lnschema' classes!")