Skip to content

Commit

Permalink
BAH-828 | samuelmale, Roamin | Unable to apply Bahmni Liquibase chang…
Browse files Browse the repository at this point in the history
…es on a 'fresh' OpenMRS database. (#51)

* BAH-828:Unable to apply Bahmni Liquibase changes on a 'fresh' OpenMRS database.

* BAH-828: Reverting changes in V1_61__CreatingGlobalPropertyForPatientIdentifierType.sql

* BAH-828: Correcting a changeset's id

* Refactor 'reports-user' role assignment and unused validChecksums

* BAH-828: Provide valid checksums to work with demo database

* BAH-828: replace incorrect SQL check

Co-authored-by: Romain Buisson <[email protected]>
  • Loading branch information
samuelmale and rbuisson authored Feb 19, 2020
1 parent 8376d4f commit 70090be
Showing 1 changed file with 145 additions and 58 deletions.
203 changes: 145 additions & 58 deletions bahmnicore-omod/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
<comment>rel2</comment>
<sqlFile path="V1_24__AddUniqueConstraintToPatientidentifier.sql"/>
</changeSet>
<changeSet id="bahmni-4" author="tw" context="rel2">
<changeSet id="bahmni-201906101112" author="tw" context="rel2">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
select count(*) from information_schema.routines WHERE ROUTINE_SCHEMA = DATABASE() AND ROUTINE_NAME = 'add_concept';
</sqlCheck>
</preConditions>
<comment>rel2</comment>
<sqlFile splitStatements="false" path="V1_29__AddConceptProc.sql"/>
</changeSet>
Expand Down Expand Up @@ -93,7 +98,12 @@
<comment>rel3</comment>
<sqlFile splitStatements="false" path="V1_58__AddConceptReferenceMapProc.sql"/>
</changeSet>
<changeSet id="bahmni-20" author="tw" context="rel3">
<changeSet id="bahmni-201906101124" author="tw" context="rel3">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
select count(*) from information_schema.routines WHERE ROUTINE_SCHEMA = DATABASE() AND ROUTINE_NAME = 'add_concept_set_members';
</sqlCheck>
</preConditions>
<comment>rel3</comment>
<sqlFile splitStatements="false" path="V1_59__AddConceptSetMembersProc.sql"/>
</changeSet>
Expand Down Expand Up @@ -151,8 +161,19 @@
<comment>rel3</comment>
<sqlFile path="V1_71__PatientSearchSql.sql"/>
</changeSet>
<changeSet id="bahmni-201906170941" author="Samuel34">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
SELECT COUNT(*) FROM global_property where property = 'emr.primaryIdentifierType';
</sqlCheck>
</preConditions>
<comment>Introducing 'emr.primaryIdentifierType' GlobalProperty</comment>
<sql>
INSERT INTO global_property (property, uuid, description) values ('emr.primaryIdentifierType', UUID(), 'Primary identifier type for looking up patients, generating barcodes, etc');
</sql>
</changeSet>
<changeSet id="bahmni-35" author="tw" context="rel3">
<preConditions onFail="HALT">
<preConditions onFail="HALT">
<sqlCheck expectedResult="1">
SELECT COUNT(*) FROM global_property where property = 'emr.primaryIdentifierType'
</sqlCheck>
Expand Down Expand Up @@ -435,8 +456,14 @@
</sql>
</changeSet>

<changeSet id="bahmni-clinical-201402251700" author="Mihir,Vinay">
<validCheckSum>3:da4167ac93f082b79d4c3af1807fc7f7</validCheckSum>
<changeSet id="bahmni-core-201906201150" author="Mihir,Vinay">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
select count(*) from concept_name cn inner join concept c on cn.concept_id = c.concept_id where cn.name = 'REFERRED_OUT'
and cn.concept_name_type = 'FULLY_SPECIFIED' and c.datatype_id = (SELECT concept_datatype_id FROM concept_datatype WHERE name = 'N/A')
and c.class_id = (SELECT concept_class_id FROM concept_class WHERE name = 'Misc');
</sqlCheck>
</preConditions>
<comment>Add new concept to mark referred out tests</comment>
<sql>
set @concept_id = 0;
Expand All @@ -447,7 +474,7 @@
set @answer_concept_id = 0;
call add_concept(@concept_id, @concept_name_short_id,
@concept_name_full_id,'REFERRED_OUT','REFERRED_OUT', 'N/A', 'Misc', true);
select @labresults_concept_id := concept_id, min(concept_id) from concept_name where name = 'LABRESULTS_CONCEPT';
select @labresults_concept_id := concept_id, min(concept_id) from concept_name where name = 'LABRESULTS_CONCEPT' GROUP BY concept_id;
set @set_concept_id = @concept_id;
call add_concept_set_members (@labresults_concept_id,@set_concept_id,1);

Expand Down Expand Up @@ -1123,17 +1150,19 @@
`property_value`=@concept_set_uuid;
</sql>
</changeSet>
<changeSet id="bahmni-core-201407171700" author="Vinay, Indraneel">
<validCheckSum>3:2b64c9751b31b8fcc7a25f7545326632</validCheckSum>
<changeSet id="bahmni-core-201906101318" author="Vinay, Indraneel, Samuel34">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
select count(*) from global_property where property = 'order.durationUnitsConceptUuid';
</sqlCheck>
</preConditions>
<comment>Adding duration unit concepts and setting up associated global property</comment>
<sql>
set @concept_id = 0;
set @concept_name_short_id = 0;
set @concept_name_full_id = 0;

call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Duration Units', 'duration units', 'N/A', 'ConvSet', true);
set @set_concept_id = @concept_id;

call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Days', 'days', 'N/A', 'Misc', false);
call add_concept_set_members (@set_concept_id,@concept_id,1);

Expand Down Expand Up @@ -1252,38 +1281,28 @@
update drug_order set dosing_type='org.openmrs.SimpleDosingInstructions' where dosing_type='SIMPLE';
</sql>
</changeSet>
<changeSet id="bahmni-core-201408130010" author="Mujir">
<createTable tableName="import_status" >
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" primaryKeyName="import_status_pk" nullable="false" />
</column>

<!-- Should the file name columns be text?? -->
<column name="original_file_name" type="varchar(500)">
<constraints nullable="false"/>
</column>
<column name="saved_file_name" type="varchar(500)" >
<!--<constraints nullable="false" unique="true"/>-->
<constraints nullable="false" />
</column>
<column name="error_file_name" type="varchar(500)"/>
<column name="type" type="varchar(25)">
<constraints nullable="false"/>
</column>
<column name="status" type="varchar(25)">
<constraints nullable="false"/>
</column>
<column name="successful_records" type="numeric(6)"/>
<column name="failed_records" type="numeric(6)"/>
<column name="stage_name" type="varchar(10)" />
<column name="stack_trace" type="text" />

<column name="uploaded_by" type="varchar(20)">
<constraints nullable="false"/>
</column>
<column name="start_time" type="timestamp"/>
<column name="end_time" type="timestamp"/>
</createTable>
<changeSet id="bahmni-core-201906170948" author="Mujir, Samuel34">
<preConditions onFail="MARK_RAN">
<not><tableExists tableName="import_status"/></not>
</preConditions>
<comment>Introducing import status table</comment>
<sql>
CREATE TABLE import_status (
id INT AUTO_INCREMENT NOT NULL,
original_file_name VARCHAR(500) NOT NULL,
saved_file_name VARCHAR(500) NOT NULL,
error_file_name VARCHAR(500) NULL,
type VARCHAR(25) NOT NULL,
status VARCHAR(25) NOT NULL,
successful_records NUMERIC(6) NULL,
failed_records NUMERIC(6) NULL,
stage_name VARCHAR(10) NULL,
stack_trace TEXT NULL,
uploaded_by VARCHAR(20) NOT NULL,
start_time TIMESTAMP NULL DEFAULT NULL,
end_time TIMESTAMP NULL DEFAULT NULL,
CONSTRAINT import_status_pk PRIMARY KEY (id));
</sql>
</changeSet>
<changeSet id="bahmni-core-201408180936" author="Mujir, Mihir">
<preConditions onFail="MARK_RAN">
Expand Down Expand Up @@ -1365,8 +1384,14 @@
<column name="uuid" valueComputed="uuid()"/>
</insert>
</changeSet>
<changeSet id="bahmni-core-201408251456" author="Rohan">
<validCheckSum>3:ed9c04ea91806b2e8c789fad21d92302</validCheckSum>
<changeSet id="bahmni-core-201906211112" author="Rohan, Samuel34">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
select count(*) from concept_name cn inner join concept c on cn.concept_id = c.concept_id where cn.name = 'LAB_REPORT'
and cn.concept_name_type = 'FULLY_SPECIFIED' and c.datatype_id = (SELECT concept_datatype_id FROM concept_datatype WHERE name = 'TEXT')
and c.class_id = (SELECT concept_class_id FROM concept_class WHERE name = 'URL');
</sqlCheck>
</preConditions>
<comment>Add new concept LAB REPORT for uploaded file</comment>
<sql>
set @concept_id = 0;
Expand All @@ -1377,7 +1402,7 @@
set @answer_concept_id = 0;
call add_concept(@concept_id, @concept_name_short_id,
@concept_name_full_id,'LAB_REPORT','LAB_REPORT', 'Text', 'URL', true);
select @labresults_concept_id := concept_id, min(concept_id) from concept_name where name = 'LABRESULTS_CONCEPT';
select @labresults_concept_id := concept_id, min(concept_id) from concept_name where name = 'LABRESULTS_CONCEPT' GROUP BY concept_id;
set @set_concept_id = @concept_id;
call add_concept_set_members (@labresults_concept_id,@set_concept_id,1);
</sql>
Expand Down Expand Up @@ -3527,23 +3552,48 @@
<comment>New roles and privileges for bahmni</comment>
<sqlFile path="V1_96_NewRolesAndPrivileges.sql"/>
</changeSet>
<changeSet id="map-users-to-new-roles" author="Jaswanth, Ravindra">
<preConditions onFail="MARK_RAN">
<changeSet id="bahmni-core-201906201151" author="Samuel34">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
select count(*) from role where role = 'Bahmni-User'
select count(*) from users where system_id='superman';
</sqlCheck>
</preConditions>
<comment>Adding superman user</comment>
<sql>
SET @puuid = uuid();
INSERT INTO person(gender, birthdate_estimated, dead, creator, date_created, uuid) VALUES('M', 0, 0, 1, now(), @puuid);
SELECT person_id INTO @person_id from person where uuid = @puuid;
INSERT INTO person_name(person_id, preferred, given_name, family_name, creator, date_created, uuid) VALUES(@person_id, 1, 'Super', 'Man', 1, now(), @puuid);
INSERT INTO users(system_id, creator, date_created, person_id, uuid, username, password, salt) VALUES ('superman', 1, now(),@person_id, uuid(), 'superman', 'e28e3ae84c66bfba6b2c50a406567f3e34fea1d76b17c006931571fe5d940f6c6b81e49cf8ea5e0adfca19fe3beb68d8ad79f7c3812e92b8d502a9afcf2029b2', '1c9d7e94aeeb7a2459ef45ed200b2944582e0e7088d75f9b57a3644861ea766c20a269b3fe2eadaff1bc445ecfbd9bd3c0c550dfd813de48d39423cd3d1a8b10');
INSERT INTO provider (person_id, identifier, creator, date_created, uuid, name) VALUES (@person_id, 'superman', 1, now(), uuid(), 'superman');
</sql>
</changeSet>
<changeSet id="bahmni-core-202002031441" author="Jaswanth, Ravindra, Samuel34, rbuisson">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="2">
select count(*) from users where system_id = 'admin' or system_id = 'superman'
</sqlCheck>
</preConditions>
<comment>Map users to new roles</comment>
<sql>
set @id = NULL;
select user_id from users where username='admin' into @id;
INSERT INTO `user_role` VALUES (@id, 'bypass2FA'),(@id,'Provider'),(@id,'System Developer');

select user_id from users where username='reports-user' into @id;
INSERT INTO `user_role` VALUES (@id, 'Reports-App');
select user_id from users where system_id='admin' into @id;
INSERT IGNORE INTO `user_role` VALUES (@id,'Provider'),(@id,'System Developer');

select user_id from users where username='superman' into @id;
INSERT INTO `user_role` VALUES (@id,'Provider'),(@id,'System Developer'), (@id, 'SuperAdmin');
select user_id from users where system_id='superman' into @id;
INSERT IGNORE INTO `user_role` VALUES (@id,'Provider'),(@id,'System Developer'), (@id, 'SuperAdmin');
</sql>
</changeSet>
<changeSet id="bahmni-core-201906170327" author="Samuel34">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="1">
select count(*) from role where role = 'Reports-App';
</sqlCheck>
</preConditions>
<comment>Map 'reports-user' user to new roles</comment>
<sql>
select user_id from users where username = 'reports-user' into @id;
INSERT IGNORE INTO `user_role` VALUES (@id, 'Reports-App');
</sql>
</changeSet>
<changeSet id="assign-role-to-automation-user" author="Jaswanth">
Expand Down Expand Up @@ -3872,8 +3922,9 @@

</sql>
</changeSet>

<changeSet id="20170308-1000" author="Sidtharthan, Gaurav">
<validCheckSum>3:2b48153e296e929a8c7fe8bd519654ec</validCheckSum>
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
SELECT COUNT(*) FROM concept where concept_id in (select concept_id from concept_name where
Expand Down Expand Up @@ -3959,8 +4010,9 @@
INSERT IGNORE INTO role_privilege (role, privilege) SELECT * FROM (SELECT 'Clinical-App-Read-Only', 'Get Forms') AS tmp WHERE EXISTS ( SELECT role FROM role WHERE role = 'Clinical-App-Read-Only' );
</sql>
</changeSet>

<changeSet author="sidtharthanan, Darius" id="20170302-1225">
<validCheckSum>3:a735e6b93635ffb2bc7e6a01a24407c3</validCheckSum>
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
SELECT COUNT(*) FROM concept where concept_id in (select concept_id from concept_name where
Expand Down Expand Up @@ -4330,6 +4382,31 @@
INSERT INTO role_privilege(role, privilege) VALUES ("OT: ReadOnly", "app:ot");
</sql>
</changeSet>

<changeSet author="Samuel34" id="bahmni-core-201906131441" runOnChange="true">
<preConditions onFail="MARK_RAN">
<not>
<viewExists viewName="concept_view"/>
</not>
</preConditions>
<comment>Creating view concept</comment>
<createView viewName="concept_view" replaceIfExists="true">
SELECT concept.concept_id, concept_full_name.name AS concept_full_name, concept_short_name.name
AS concept_short_name, concept_class.name AS concept_class_name,concept_datatype.name
AS concept_datatype_name,concept.retired,concept_description.description,concept.date_created
AS date_created FROM concept LEFT OUTER JOIN concept_name AS concept_full_name
ON concept_full_name.concept_id = concept.concept_id AND concept_full_name.concept_name_type =
'FULLY_SPECIFIED'
AND concept_full_name.locale = 'en' AND concept_full_name.voided = 0
LEFT OUTER JOIN concept_name AS concept_short_name ON concept_short_name.concept_id = concept.concept_id
AND concept_short_name.concept_name_type = 'SHORT'AND concept_short_name.locale = 'en' AND
concept_short_name.voided = 0
LEFT OUTER JOIN concept_class ON concept_class.concept_class_id = concept.class_id
LEFT OUTER JOIN concept_datatype ON concept_datatype.concept_datatype_id = concept.datatype_id
LEFT OUTER JOIN concept_description ON concept_description.concept_id = concept.concept_id;
</createView>
</changeSet>

<changeSet id="201805112235" author="Suman">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="1">
Expand Down Expand Up @@ -4397,7 +4474,6 @@
<comment>Override SQL query for Get Patient Details in Ward</comment>
<sqlFile path="BahmniBMPatientListInWard.sql"/>
</changeSet>

<changeSet id="201905101200" author="Angshu,Bindu">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
Expand Down Expand Up @@ -4437,4 +4513,15 @@
<column name="uuid" valueComputed=" uuid() "/>
</insert>
</changeSet>
<changeSet id="bahmni-core-201906201136" author="Samuel34">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
select count(*) from role_privilege where role = 'Anonymous' and privilege = 'Get Locations';
</sqlCheck>
</preConditions>
<comment>Assign the 'Get Locations' previlege to the Anonymous user</comment>
<sql>
INSERT INTO role_privilege (role, privilege) VALUES ('Anonymous', 'Get Locations');
</sql>
</changeSet>
</databaseChangeLog>

0 comments on commit 70090be

Please sign in to comment.