-
Notifications
You must be signed in to change notification settings - Fork 19
Add migrations for beneficiary residence columns and diagnostic devic… #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vanitha1822
merged 3 commits into
PSMRI:main
from
sehjotsinghunthinkable:migration/add-diagnostic-changes
Jul 29, 2026
+388
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
220 changes: 220 additions & 0 deletions
220
src/main/resources/db/migration/dbidentity/V19_Non_Household_Add_Column.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| -- ========================================================== | ||
| -- Add place of current living related columns to beneficiary | ||
| -- and household tables. | ||
| -- | ||
| -- Safe to execute multiple times. | ||
| -- Each column is added only if it does not already exist. | ||
| -- MODIFY statements execute only if the target column exists. | ||
| -- ========================================================== | ||
|
|
||
| USE db_identity; | ||
|
|
||
| SET @schema_name = 'db_identity'; | ||
| SET @tbl_beneficiarydetails = 'i_beneficiarydetails'; | ||
| SET @tbl_beneficiarydetails_rmnch = 'i_beneficiarydetails_rmnch'; | ||
| SET @tbl_householddetails = 'i_householddetails'; | ||
| SET @tbl_beneficiaryaddress = 'i_beneficiaryaddress'; | ||
| SET @col_gps_unavailable = 'isGpsUnavailable'; | ||
|
|
||
| -- ========================================================== | ||
| -- i_beneficiarydetails | ||
| -- ========================================================== | ||
|
|
||
| -- placeOfCurrentLiving | ||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 0, | ||
| 'ALTER TABLE db_identity.i_beneficiarydetails ADD COLUMN placeOfCurrentLiving VARCHAR(255) NULL;', | ||
| 'SELECT ''placeOfCurrentLiving already exists in i_beneficiarydetails'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_beneficiarydetails | ||
| AND COLUMN_NAME = 'placeOfCurrentLiving' | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- otherPlaceOfCurrentLiving | ||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 0, | ||
| 'ALTER TABLE db_identity.i_beneficiarydetails ADD COLUMN otherPlaceOfCurrentLiving VARCHAR(255) NULL;', | ||
| 'SELECT ''otherPlaceOfCurrentLiving already exists in i_beneficiarydetails'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_beneficiarydetails | ||
| AND COLUMN_NAME = 'otherPlaceOfCurrentLiving' | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- institutionName | ||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 0, | ||
| 'ALTER TABLE db_identity.i_beneficiarydetails ADD COLUMN institutionName VARCHAR(255) NULL;', | ||
| 'SELECT ''institutionName already exists in i_beneficiarydetails'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_beneficiarydetails | ||
| AND COLUMN_NAME = 'institutionName' | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- ========================================================== | ||
| -- i_beneficiarydetails_rmnch | ||
| -- ========================================================== | ||
|
|
||
| -- placeOfCurrentLiving | ||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 0, | ||
| 'ALTER TABLE db_identity.i_beneficiarydetails_rmnch ADD COLUMN placeOfCurrentLiving VARCHAR(255) NULL;', | ||
| 'SELECT ''placeOfCurrentLiving already exists in i_beneficiarydetails_rmnch'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_beneficiarydetails_rmnch | ||
| AND COLUMN_NAME = 'placeOfCurrentLiving' | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- otherPlaceOfCurrentLiving | ||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 0, | ||
| 'ALTER TABLE db_identity.i_beneficiarydetails_rmnch ADD COLUMN otherPlaceOfCurrentLiving VARCHAR(255) NULL;', | ||
| 'SELECT ''otherPlaceOfCurrentLiving already exists in i_beneficiarydetails_rmnch'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_beneficiarydetails_rmnch | ||
| AND COLUMN_NAME = 'otherPlaceOfCurrentLiving' | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- institutionName | ||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 0, | ||
| 'ALTER TABLE db_identity.i_beneficiarydetails_rmnch ADD COLUMN institutionName VARCHAR(255) NULL;', | ||
| 'SELECT ''institutionName already exists in i_beneficiarydetails_rmnch'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_beneficiarydetails_rmnch | ||
| AND COLUMN_NAME = 'institutionName' | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- ========================================================== | ||
| -- i_householddetails | ||
| -- ========================================================== | ||
|
|
||
| -- address | ||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 0, | ||
| 'ALTER TABLE db_identity.i_householddetails ADD COLUMN address VARCHAR(500) NULL;', | ||
| 'SELECT ''address already exists in i_householddetails'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_householddetails | ||
| AND COLUMN_NAME = 'address' | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- totalHhMembers | ||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 0, | ||
| 'ALTER TABLE db_identity.i_householddetails ADD COLUMN totalHhMembers INT NULL;', | ||
| 'SELECT ''totalHhMembers already exists in i_householddetails'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_householddetails | ||
| AND COLUMN_NAME = 'totalHhMembers' | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- registeredAtCampSite | ||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 0, | ||
| 'ALTER TABLE db_identity.i_householddetails ADD COLUMN registeredAtCampSite VARCHAR(255) NULL;', | ||
| 'SELECT ''registeredAtCampSite already exists in i_householddetails'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_householddetails | ||
| AND COLUMN_NAME = 'registeredAtCampSite' | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- registeredAtCampSiteId | ||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 0, | ||
| 'ALTER TABLE db_identity.i_householddetails ADD COLUMN registeredAtCampSiteId INT NULL;', | ||
| 'SELECT ''registeredAtCampSiteId already exists in i_householddetails'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_householddetails | ||
| AND COLUMN_NAME = 'registeredAtCampSiteId' | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- ========================================================== | ||
| -- Modify isGpsUnavailable in i_beneficiarydetails_rmnch | ||
| -- ========================================================== | ||
|
|
||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 1, | ||
| 'ALTER TABLE db_identity.i_beneficiarydetails_rmnch MODIFY COLUMN isGpsUnavailable TINYINT(1) NULL DEFAULT 0;', | ||
| 'SELECT ''isGpsUnavailable does not exist in i_beneficiarydetails_rmnch'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_beneficiarydetails_rmnch | ||
| AND COLUMN_NAME = @col_gps_unavailable | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- ========================================================== | ||
| -- Modify isGpsUnavailable in i_householddetails | ||
| -- ========================================================== | ||
|
|
||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 1, | ||
| 'ALTER TABLE db_identity.i_householddetails MODIFY COLUMN isGpsUnavailable TINYINT(1) NULL DEFAULT 0;', | ||
| 'SELECT ''isGpsUnavailable does not exist in i_householddetails'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_householddetails | ||
| AND COLUMN_NAME = @col_gps_unavailable | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
|
|
||
| -- ========================================================== | ||
| -- Modify isGpsUnavailable in i_beneficiaryaddress | ||
| -- ========================================================== | ||
|
|
||
| SET @sql = ( | ||
| SELECT IF(COUNT(*) = 1, | ||
| 'ALTER TABLE db_identity.i_beneficiaryaddress MODIFY COLUMN isGpsUnavailable TINYINT(1) NULL DEFAULT 0;', | ||
| 'SELECT ''isGpsUnavailable does not exist in i_beneficiaryaddress'';') | ||
| FROM INFORMATION_SCHEMA.COLUMNS | ||
| WHERE TABLE_SCHEMA = @schema_name | ||
| AND TABLE_NAME = @tbl_beneficiaryaddress | ||
| AND COLUMN_NAME = @col_gps_unavailable | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
168 changes: 168 additions & 0 deletions
168
src/main/resources/db/migration/dbiemr/V96_Device_Integration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| -- ========================================================== | ||
| -- Diagnostic device integration schema for db_iemr | ||
| -- Run against your local MySQL: | ||
| -- mysql -u root -p db_iemr < diagnostic_order_schema.sql | ||
| -- | ||
| -- Purpose: | ||
| -- Creates all database tables required for diagnostic device | ||
| -- integration. | ||
| -- | ||
| -- Safe to execute multiple times because CREATE TABLE IF NOT | ||
| -- EXISTS will skip table creation if the table already exists. | ||
| -- | ||
| -- Note: | ||
| -- This script only creates new tables. It does NOT modify an | ||
| -- existing table if its schema differs. Future schema changes | ||
| -- should be handled through separate ALTER TABLE migration scripts. | ||
| -- ========================================================== | ||
|
|
||
| USE db_iemr; | ||
|
|
||
| -- ========================================================== | ||
| -- Stores diagnostic order details sent to external providers. | ||
| -- One record represents one diagnostic order. | ||
| -- ========================================================== | ||
| CREATE TABLE IF NOT EXISTS tb_diagnostic_order ( | ||
| id BIGINT NOT NULL AUTO_INCREMENT, | ||
| order_event VARCHAR(100) NULL, | ||
| ben_reg_id BIGINT NULL, | ||
| provider_service_name VARCHAR(50) NULL, | ||
| provider_code VARCHAR(50) NULL, | ||
| order_type VARCHAR(20) NULL, | ||
| external_order_id VARCHAR(100) NULL, | ||
| provider_order_id VARCHAR(100) NULL, | ||
| status VARCHAR(20) NULL, | ||
| retry_count INT NULL DEFAULT 0, | ||
| last_polled_at DATETIME NULL, | ||
| test_completed_at DATETIME NULL, | ||
| error_message TEXT NULL, | ||
| reason_for_refusal TEXT NULL, | ||
| push_response_json LONGTEXT NULL, | ||
| patient_first_name VARCHAR(100) NULL, | ||
| patient_last_name VARCHAR(100) NULL, | ||
| patient_date_of_birth VARCHAR(10) NULL, | ||
| patient_sex VARCHAR(10) NULL, | ||
| created_by VARCHAR(100) NULL, | ||
| created_date DATETIME NOT NULL, | ||
| modified_by VARCHAR(100) NULL, | ||
| last_mod_date DATETIME NULL, | ||
| deleted BIT NOT NULL DEFAULT 0, | ||
|
|
||
| -- Sync/Common Fields | ||
| vanID INT NULL, | ||
| parkingPlaceID INT NULL, | ||
| visitCode BIGINT NULL, | ||
| processed VARCHAR(1) NOT NULL DEFAULT 'N', | ||
| vanSerialNo BIGINT NULL, | ||
| SyncedDate DATETIME NULL, | ||
| Syncedby VARCHAR(50) NULL, | ||
| SyncFailureReason TEXT NULL, | ||
|
|
||
| PRIMARY KEY (id), | ||
| UNIQUE KEY uk_diagnostic_order_ben_visit_type (ben_reg_id, visitCode, order_type), | ||
| UNIQUE KEY uk_diagnostic_order_external_order_id (external_order_id) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; | ||
|
sehjotsinghunthinkable marked this conversation as resolved.
|
||
|
|
||
| -- ========================================================== | ||
| -- Stores diagnostic results received for an order. | ||
| -- Each diagnostic order can have one result. | ||
| -- ========================================================== | ||
| CREATE TABLE IF NOT EXISTS tb_diagnostic_result ( | ||
| id BIGINT NOT NULL AUTO_INCREMENT, | ||
| diagnostic_order_id BIGINT NOT NULL, | ||
| ben_reg_id BIGINT NULL, | ||
| provider_status VARCHAR(20) NULL, | ||
| result_summary TEXT NULL, | ||
| raw_response_json LONGTEXT NULL, | ||
| tb_presence BIT NULL, | ||
| tb_confidence DOUBLE NULL, | ||
| drug_resistance_presence BIT NULL, | ||
| created_by VARCHAR(100) NULL, | ||
| created_date DATETIME NOT NULL, | ||
| modified_by VARCHAR(100) NULL, | ||
| last_mod_date DATETIME NULL, | ||
| deleted BIT NOT NULL DEFAULT 0, | ||
|
|
||
| -- Sync/Common Fields | ||
| vanID INT NULL, | ||
| parkingPlaceID INT NULL, | ||
| processed VARCHAR(1) NOT NULL DEFAULT 'N', | ||
| vanSerialNo BIGINT NULL, | ||
| SyncedDate DATETIME NULL, | ||
| Syncedby VARCHAR(50) NULL, | ||
| SyncFailureReason TEXT NULL, | ||
|
|
||
| PRIMARY KEY (id), | ||
| UNIQUE KEY uk_diagnostic_result_order_id (diagnostic_order_id), | ||
| CONSTRAINT fk_diagnostic_result_order | ||
| FOREIGN KEY (diagnostic_order_id) | ||
| REFERENCES tb_diagnostic_order (id) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; | ||
|
|
||
| -- ========================================================== | ||
| -- Stores documents/assets associated with diagnostic results | ||
| -- such as reports, PDFs, images, etc. | ||
| -- ========================================================== | ||
| CREATE TABLE IF NOT EXISTS tb_diagnostic_document ( | ||
| id BIGINT NOT NULL AUTO_INCREMENT, | ||
| diagnostic_order_id BIGINT NULL, | ||
| ben_reg_id BIGINT NULL, | ||
| order_type VARCHAR(20) NULL, | ||
| asset_type VARCHAR(50) NULL, | ||
| document_type VARCHAR(30) NULL, | ||
| epoch_time BIGINT NULL, | ||
| stored_file_name VARCHAR(150) NULL, | ||
| stored_path VARCHAR(255) NULL, | ||
| sha256_hash VARCHAR(64) NULL, | ||
| content_type VARCHAR(100) NULL, | ||
| original_file_name VARCHAR(255) NULL, | ||
| created_by VARCHAR(100) NULL, | ||
| created_date DATETIME NOT NULL, | ||
| modified_by VARCHAR(100) NULL, | ||
| last_mod_date DATETIME NULL, | ||
| deleted BIT NOT NULL DEFAULT 0, | ||
|
|
||
| -- Sync/Common Fields | ||
| vanID INT NULL, | ||
| parkingPlaceID INT NULL, | ||
| processed VARCHAR(1) NOT NULL DEFAULT 'N', | ||
| vanSerialNo BIGINT NULL, | ||
| SyncedDate DATETIME NULL, | ||
| Syncedby VARCHAR(50) NULL, | ||
| SyncFailureReason TEXT NULL, | ||
|
|
||
| PRIMARY KEY (id), | ||
| UNIQUE KEY uk_diagnostic_document_order_doctype (diagnostic_order_id, document_type), | ||
| KEY idx_diagnostic_document_ben_reg_id (ben_reg_id), | ||
| KEY idx_diagnostic_document_order_type (order_type), | ||
| KEY idx_diagnostic_document_epoch_time (epoch_time), | ||
| CONSTRAINT fk_diagnostic_document_order | ||
| FOREIGN KEY (diagnostic_order_id) | ||
| REFERENCES tb_diagnostic_order (id) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; | ||
|
|
||
| -- ========================================================== | ||
| -- Stores authentication tokens used for communicating with | ||
| -- external diagnostic providers. | ||
| -- ========================================================== | ||
| CREATE TABLE IF NOT EXISTS tb_diagnostic_provider_token ( | ||
| id BIGINT NOT NULL AUTO_INCREMENT, | ||
| provider_code VARCHAR(50) NOT NULL, | ||
| token_type VARCHAR(20) NOT NULL, | ||
| token_value TEXT NOT NULL, | ||
|
sehjotsinghunthinkable marked this conversation as resolved.
|
||
| expires_at DATETIME NULL, | ||
| created_date DATETIME NOT NULL, | ||
| last_mod_date DATETIME NULL, | ||
|
|
||
| -- Sync/Common Fields | ||
| vanID INT NULL, | ||
| parkingPlaceID INT NULL, | ||
| processed VARCHAR(1) NOT NULL DEFAULT 'N', | ||
| vanSerialNo BIGINT NULL, | ||
| SyncedDate DATETIME NULL, | ||
| Syncedby VARCHAR(50) NULL, | ||
| SyncFailureReason TEXT NULL, | ||
|
|
||
| PRIMARY KEY (id), | ||
| UNIQUE KEY uk_diagnostic_provider_token_code_type (provider_code, token_type) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.