All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dule.bahmnicore-omod.1.2.0.source-code.liquibase.xml Maven / Gradle / Ivy

The newest version!
<?xml version="1.0" encoding="UTF-8"?>

<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">

    <!--
        See http://www.liquibase.org/manual/home#available_database_refactorings
        for a list of supported elements and attributes
    -->

    <property name="now" value="now()"/>

    <changeSet id="bahmni-setup-6" author="tw" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_reference_source where name = 'org.openmrs.module.emrapi';
            </sqlCheck>
        </preConditions>
        <comment>rel3</comment>
        <insert tableName="concept_reference_source">
            <column name="name" value="org.openmrs.module.emrapi"/>
            <column name="uuid" valueNumeric="name-of-uuid-function"/>
            <column name="description" value="Source used to tag concepts used in the EMR API module"/>
            <column name="date_created" valueDate="${now}"/>
            <column name="creator" value="1"/>
        </insert>
        <modifySql dbms="mysql">
            <replace replace="name-of-uuid-function" with="UUID()"/>
        </modifySql>
    </changeSet>

    <changeSet id="bahmni-1" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile path="V1_10__CreatingPatientIdentifierForBahmni.sql"/>
    </changeSet>
    <changeSet id="bahmni-2" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile path="V1_23__DeleteOpenMRSCorePersonAttributes.sql"/>
    </changeSet>
    <changeSet id="bahmni-3" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile path="V1_24__AddUniqueConstraintToPatientidentifier.sql"/>
    </changeSet>
    <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>
    <changeSet id="bahmni-5" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile splitStatements="false" path="V1_30__AddConceptAnswerProc.sql"/>
    </changeSet>
    <changeSet id="bahmni-7" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile splitStatements="false" path="V1_37__SetValueAsConceptIdProc.sql"/>
    </changeSet>
    <changeSet id="bahmni-clinical-1" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile path="V1_39__CreateLaboratoryPanelConcept.sql"/>
    </changeSet>
    <changeSet id="bahmni-10" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile path="V1_41__AddingIndexToCityVillage-JssSpecific.sql"/>
    </changeSet>
    <changeSet id="bahmni-11" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile path="V1_42__RemovingNotNullContraintOnOrderTypeId.sql"/>
    </changeSet>
    <changeSet id="bahmni-12" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile path="V1_43__AddOPDConsultationEncounterType.sql"/>
    </changeSet>
    <changeSet id="bahmni-31" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile path="V1_10__SetupRegistrationEncounterType.sql"/>
    </changeSet>
    <changeSet id="bahmni-16" author="tw" context="rel3">
        <validCheckSum>3:9596557aceeccee17eb9a9af5df316af</validCheckSum>
        <comment>rel3</comment>
        <sqlFile path="V1_55__addLabAndRadiologyOrderTypes.sql"/>
    </changeSet>
    <changeSet id="bahmni-17" author="tw" context="rel3">
        <comment>rel3</comment>
        <sqlFile splitStatements="false" path="V1_56__AddConceptDescriptionProc.sql"/>
    </changeSet>
    <changeSet id="bahmni-clinical-2" author="tw" context="rel3">
        <validCheckSum>3:248b34d9ff8955c24cfceffb8396e01c</validCheckSum>
        <comment>rel3</comment>
        <sqlFile path="V1_57__addDrugDosageInstructionsAndDosageFrequecies.sql"/>
    </changeSet>
    <changeSet id="bahmni-19" author="tw" context="rel3">
        <comment>rel3</comment>
        <sqlFile splitStatements="false" path="V1_58__AddConceptReferenceMapProc.sql"/>
    </changeSet>
    <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>
    <changeSet id="bahmni-clinical-3" author="tw" context="rel3">
        <validCheckSum>3:a15a57cb8324e3e099775d7838880b71</validCheckSum>
        <comment>rel3</comment>
        <sqlFile path="V1_60__AddDiagnosisConcepts.sql"/>
    </changeSet>
    <changeSet id="bahmni-clinical-4" author="tw" context="rel3">
        <validCheckSum>3:03c23be81ba7cebf6fec9df46bec239c</validCheckSum>
        <comment>rel3</comment>
        <sqlFile path="V1_62__AddDispositionConcepts.sql"/>
    </changeSet>
    <changeSet id="bahmni-clinical-5" author="tw" context="rel3">
        <validCheckSum>3:14d62b7a1d949387b19aeeb385c17408</validCheckSum>
        <comment>rel3</comment>
        <sqlFile path="V1_66__addConceptConsultationNote.sql"/>
    </changeSet>
    <changeSet id="bahmni-25" author="tw" context="rel3">
        <validCheckSum>3:89336c228d0063f50b24e7cc288793e5</validCheckSum>
        <comment>rel3</comment>
        <sqlFile path="V1_67__AddConceptSetForAdmission.sql"/>
    </changeSet>
    <changeSet id="bahmni-26" author="tw" context="rel3">
        <comment>rel3</comment>
        <sqlFile path="V1_68__EncounterTypeForAdmission.sql"/>
    </changeSet>
    <changeSet id="bahmni-27" author="tw" context="rel3">
        <validCheckSum>3:321fb0b2fbc8c0add1dac2fac4824068</validCheckSum>
        <comment>rel3</comment>
        <sqlFile path="V1_69__AddConceptSetForDischarge.sql"/>
    </changeSet>
    <changeSet id="bahmni-28" author="tw" context="rel3">
        <comment>rel3</comment>
        <sqlFile path="V1_70__EncounterTypeForDischarge.sql"/>
    </changeSet>
    <changeSet id="bahmni-29" author="tw" context="rel3">
        <comment>rel3</comment>
        <sqlFile splitStatements="false" path="V1_72__AddProcToInsertNewAddressLevel.sql"/>
    </changeSet>
    <changeSet id="bahmni-30" author="tw" context="rel3">
        <comment>rel3</comment>
        <update tableName="patient_identifier_type">
            <column name="name" value="Bahmni Id"/>
            <where>name='JSS'</where>
        </update>
    </changeSet>
    <changeSet id="bahmni-32" author="tw" context="rel3">
        <comment>rel3</comment>
        <sqlFile path="V1_78__EncounterTypeForTransfer.sql"/>
    </changeSet>
    <changeSet id="bahmni-33" author="tw" context="rel3" runOnChange="true">
        <validCheckSum>3:9265b4028eba323f1fe9752430c96b92</validCheckSum>
        <validCheckSum>3:8303f4f9d1ac7eb2de6c4d2b2466d873</validCheckSum>
        <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">
            <sqlCheck expectedResult="1">
                SELECT COUNT(*) FROM global_property where property = 'emr.primaryIdentifierType'
            </sqlCheck>
        </preConditions>
        <comment>rel3</comment>
        <sqlFile path="V1_61__CreatingGlobalPropertyForPatientIdentifierType.sql"/>
    </changeSet>
    <changeSet id="bahmni-36" author="tw" context="rel3">
        <validCheckSum>3:7e9c42924c89c509275adda048d3f6a0</validCheckSum>
        <comment>Add investigations meta data</comment>
        <sql>
            set @concept_id = 0;
            set @answer_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, 'Lab Departments', 'Lab departments', 'N/A', 'ConvSet', true);
            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Other Investigations', 'Other Investigations', 'N/A', 'ConvSet', true);
            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Other Investigations Categories', 'Other Investigations Categories', 'N/A', 'ConvSet', true);
        </sql>
    </changeSet>

    <changeSet id="bahmni-clinical-6" author="Hemanth" context="rel3">
        <comment>Add concept Adt Notes</comment>
        <sql>
            insert into concept (retired, short_name, description, datatype_id, class_id, is_set, creator, date_created,
            changed_by, date_changed, uuid)
            values (0, 'Adt Notes', 'Adt Notes',
            (select concept_datatype_id from concept_datatype where name = 'Text'),
            (select concept_class_id from concept_class where name = 'Misc'),
            0, 1, now(), 1, now(), uuid());
        </sql>
    </changeSet>

    <changeSet id="bahmni-clinical-7" author="Hemanth" context="rel3">
        <comment>Add concept-name Adt Notes</comment>
        <sql>
            insert into concept_name (concept_id, name, locale, locale_preferred, creator, date_created,
            concept_name_type, voided, uuid)
            values ((select concept_id from concept where short_name='Adt Notes'),
            'Adt Notes', 'en', 1, 1, now(), 'FULLY_SPECIFIED', 0, uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-8" author="Praveen" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM global_property where property = 'bahmni.encountersession.duration'
            </sqlCheck>
        </preConditions>
        <comment>Add encounter session duration</comment>
        <sql>
            insert into global_property (`property`, `property_value`, `description`, `uuid`)
            values ('bahmni.encountersession.duration',
            '60',
            'Encountersession duration in minutes',
            uuid()
            );
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-9" author="Praveen" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM global_property where property = 'emr.encounterMatcher'
            </sqlCheck>
        </preConditions>
        <comment>Add custom encounter session matcher</comment>
        <sql>
            insert into global_property (`property`, `property_value`, `description`, `uuid`)
            values ('emr.encounterMatcher',
            'org.bahmni.module.bahmnicore.matcher.EncounterSessionMatcher',
            'custom encounter session matcher',
            uuid()
            );
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-11" author="Arathy" context="rel3">
        <comment>Add concept Document</comment>
        <sql>
            insert into concept (retired, short_name, description, datatype_id, class_id, is_set, creator, date_created,
            changed_by, date_changed, uuid)
            values (0, 'Document', 'Document',
            (select concept_datatype_id from concept_datatype where name = 'Text'),
            (select concept_class_id from concept_class where name = 'Misc'),
            0, 1, now(), 1, now(), uuid());
        </sql>
    </changeSet>

    <changeSet id="bahmni-clinical-12" author="Arathy" context="rel3">
        <comment>Add concept-name Document</comment>
        <sql>
            insert into concept_name (concept_id, name, locale, locale_preferred, creator, date_created,
            concept_name_type, voided, uuid)
            values ((select concept_id from concept where short_name='Document'),
            'Document', 'en', 1, 1, now(), 'FULLY_SPECIFIED', 0, uuid());
        </sql>
    </changeSet>

    <changeSet id="bahmni-clinical-13" author="Arathy" context="rel3">
        <comment>Add Encounter Type Radiology</comment>
        <sql>
            insert into encounter_type (name, description, creator, date_created, uuid)
            VALUES ('RADIOLOGY', 'RADIOLOGY encounter', 1, curdate(), uuid());
        </sql>
    </changeSet>

    <changeSet id="bahmni-clinical-201401171353" author="banka-tw" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'app:clinical'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="app:clinical"/>
            <column name="description" value="Bahmni clinical app access privilege"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>

    <changeSet id="bahmni-clinical-201401171415" author="banka-tw" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'app:radiologyOrders'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="app:radiologyOrders"/>
            <column name="description" value="Bahmni radiology orders access privilege"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>

    <changeSet id="bahmni-clinical-201401171420" author="banka-tw" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'app:documents'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="app:documents"/>
            <column name="description" value="Privilege to access the documents scanning app"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-clinical-14" author="Praveen" context="rel3">
        <comment>Add new encounter type for investigation</comment>
        <sql>
            INSERT INTO encounter_type (name, description, creator, date_created, uuid) VALUES ('INVESTIGATION', 'Investigation encounter', 1, curdate(), uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-37" author="tw" context="rel3">
        <comment>Add job for processing reference data</comment>
        <sql>
            INSERT INTO scheduler_task_config(name, schedulable_class, start_time, start_time_pattern, repeat_interval,start_on_startup, started, created_by, date_created, uuid)
            VALUES ('Reference Data Task', 'org.bahmni.module.referncedatafeedclient.task.ReferenceDataFeedTask', now(),'MM/dd/yyyy HH:mm:ss', 60, 1, 0, 1, curdate(), uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-38" author="tw" context="rel3">
        <comment>Add job for processing failed reference data</comment>
        <sql>
            INSERT INTO scheduler_task_config(name, schedulable_class, start_time, start_time_pattern, repeat_interval,start_on_startup, started, created_by, date_created, uuid)
            VALUES ('Reference Data Failed Event Task', 'org.bahmni.module.referncedatafeedclient.task.ReferenceDataFailedEventTask', now(),'MM/dd/yyyy HH:mm:ss', 60, 1, 0, 1, curdate(), uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-39" author="tw" context="rel3">
        <comment>Update class name of reference data feed task and failed event task.</comment>
        <sql>
            UPDATE scheduler_task_config SET schedulable_class = 'org.bahmni.module.referencedatafeedclient.task.ReferenceDataFeedTask' WHERE name = 'Reference Data Task';
            UPDATE scheduler_task_config SET schedulable_class = 'org.bahmni.module.referencedatafeedclient.task.ReferenceDataFailedEventTask' WHERE name = 'Reference Data Failed Event Task';
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-201401281730" author="Banka,RT" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from encounter_type where name = 'LAB_RESULT'</sqlCheck>
        </preConditions>
        <comment>Add new encounter type for Lab Result</comment>
        <sql>
            INSERT INTO encounter_type (name, description, creator, date_created, uuid) VALUES ('LAB_RESULT', 'Lab Result encounter', 1, curdate(), uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-201401311600" author="TW" context="rel3">
        <validCheckSum>3:190851ded03e41d8b33b47c3cf720866</validCheckSum>
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from concept_name where name = 'LAB_RESULTS_CONCEPT_SET'
            </sqlCheck>
        </preConditions>
        <comment>Add concept set for Lab results</comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;

            set @answer_concept_id = 0;
            call add_concept(@concept_id, @concept_name_short_id,
            @concept_name_full_id,'LABRESULTS_CONCEPT','LABRESULTS_CONCEPT', 'N/A', 'Finding', true);

            set @labresults_concept_id = @concept_id;

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id,'LAB_RESULT','LAB_RESULT',
            'Text', 'Finding', false);
            set @set_concept_id = @concept_id;
            call add_concept_set_members (@labresults_concept_id,@set_concept_id,1);


            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id,'LAB_NOTES','LAB_NOTES', 'Text',
            'Finding', false);
            set @set_concept_id = @concept_id;
            call add_concept_set_members (@labresults_concept_id,@set_concept_id,1);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id,'LAB_MINNORMAL','LAB_MINNORMAL',
            'Numeric', 'Finding', false);
            set @set_concept_id = @concept_id;
            call add_concept_set_members (@labresults_concept_id,@set_concept_id,1);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id,'LAB_MAXNORMAL','LAB_MAXNORMAL',
            'Numeric', 'Finding', false);
            set @set_concept_id = @concept_id;
            call add_concept_set_members (@labresults_concept_id,@set_concept_id,1);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id,'LAB_ABNORMAL','LAB_ABNORMAL',
            'Boolean', 'Finding', false);
            set @set_concept_id = @concept_id;
            call add_concept_set_members (@labresults_concept_id,@set_concept_id,1);
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-201402061215" author="Angshu,RT" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from visit_type where name = 'LAB_RESULTS_IN_ABSENTEE'</sqlCheck>
        </preConditions>
        <comment>Add new visit type LAB_RESULTS_IN_ABSENTEE</comment>
        <sql>
            INSERT INTO visit_type (name, description, creator, uuid, date_created) VALUES ('LAB_RESULTS_IN_ABSENTEE', 'Visit for which results come when patient is not present', 1, uuid(), curdate());
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-201402101443" author="sush" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'app:document-upload'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="app:document-upload"/>
            <column name="description" value="bahmni document upload access privilege"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-clinical-201402111716" author="indraneel,neha" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'app:adt'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="app:adt"/>
            <column name="description" value="bahmni adt access privilege"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-clinical-201402161951" author="Mujir,Vinay" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from visit_type where name = 'DRUG_ORDER'</sqlCheck>
        </preConditions>
        <comment>Creating new visit type DRUG_ORDER</comment>
        <sql>
            INSERT INTO visit_type (name, description, creator, uuid, date_created) VALUES ('DRUG_ORDER', 'Placeholder visit for orders created when no visit is open', 1, uuid(), curdate());
        </sql>
    </changeSet>

    <changeSet id="bahmni-clinical-201402201226" author="Neha,Indraneel" context="rel3">
        <comment>deleting visit types DRUG_ORDER and LAB_RESULTS_IN_ABSENTEE</comment>
        <sql>
            DELETE from visit_type where name in ('DRUG_ORDER','LAB_RESULTS_IN_ABSENTEE');
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-201402201520" author="Angshu" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from global_property where property = 'emr.primaryIdentifierType'</sqlCheck>
        </preConditions>
        <comment>Add global property for emr primary identifier type</comment>
        <sql>
            INSERT INTO global_property (property, uuid, description) values ('emr.primaryIdentifierType', UUID(), 'Primary identifier type for looking up patients, generating barcodes, etc') ON DUPLICATE KEY UPDATE description = 'Primary identifier type for looking up patients, generating barcodes, etc';
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-201402201530" author="Angshu" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">select count(*) from patient_identifier_type where name = 'Bahmni Id'</sqlCheck>
        </preConditions>
        <comment>set global property value for emr primary identifier type</comment>
        <sql>
            update global_property set property_value = (select uuid from patient_identifier_type where name = 'Bahmni Id') where property = 'emr.primaryIdentifierType';
        </sql>
    </changeSet>

    <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.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;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @labresults_concept_id = 0;

            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' GROUP BY concept_id;
            set @set_concept_id = @concept_id;
            call add_concept_set_members (@labresults_concept_id,@set_concept_id,1);

        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-201402281633" author="Indraneel,Neha" context="rel4">
        <comment>Add concept Lab Order Notes</comment>
        <sql>
            insert into concept (retired, short_name, description, datatype_id, class_id, is_set, creator, date_created,
            changed_by, date_changed, uuid)
            values (0, 'Lab Order Notes', 'Lab Order Notes',
            (select concept_datatype_id from concept_datatype where name = 'Text'),
            (select concept_class_id from concept_class where name = 'Misc'),
            0, 1, now(), 1, now(), uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-201402281635" author="Indraneel,Neha" context="rel4">
        <comment>Add concept-name Lab Order Notes</comment>
        <sql>
            insert into concept_name (concept_id, name, locale, locale_preferred, creator, date_created,
            concept_name_type, voided, uuid)
            values ((select concept_id from concept where short_name='Document'),
            'Lab Order Notes', 'en', 1, 1, now(), 'FULLY_SPECIFIED', 0, uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-201403051245" author="Neha" context="rel4">
        <comment>Delete concept Lab Order Notes</comment>
        <sql>
            DELETE from concept where short_name = 'Lab Order Notes';
            DELETE from concept_name where name = 'Lab Order Notes';
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-201403051246" author="Neha">
        <validCheckSum>3:176087fd78dcbd1639ceded0a350687b</validCheckSum>
        <comment>Add new concept to lab order notes</comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;

            set @answer_concept_id = 0;
            call add_concept(@concept_id, @concept_name_short_id,
            @concept_name_full_id,'Lab Order Notes','Lab Order Notes', 'Text', 'Misc', false);
            set @set_concept_id = @concept_id;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201403110603" author="Hemanth">
        <comment>Add new concept for test and panel</comment>
        <sql>
            insert into concept(datatype_id, class_id, is_set, creator, date_created, uuid) values(4, 10, true, 1, now(), uuid());

            select max(concept_id) from concept into @laboratory_concept_id;

            insert into concept_name(concept_id, name, locale, locale_preferred,creator, date_created, concept_name_type, uuid) values (@laboratory_concept_id, 'All_Tests_and_Panels', 'en', true, 1, now(), 'FULLY_SPECIFIED', uuid());
            insert into concept_name(concept_id, name, locale, locale_preferred,creator, date_created, concept_name_type, uuid) values (@laboratory_concept_id, 'A_T_and_P', 'en', false, 1, now(), 'SHORT', uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201403181515" author="Hemanth,Vinay">
        <comment>Add new concept for observation group (XCompoundObservation)</comment>
        <sql>
            insert into concept(datatype_id, class_id, is_set, creator, date_created, uuid) values(4, 10, true, 1, now(), uuid());

            select max(concept_id) from concept into @compound_observation_id;

            insert into concept_name(concept_id, name, locale, locale_preferred,creator, date_created, concept_name_type, uuid) values (@compound_observation_id, 'XCompoundObservation', 'en', true, 1, now(), 'FULLY_SPECIFIED', uuid());

            insert into concept(datatype_id, class_id, is_set, creator, date_created, uuid) values(4, 10, true, 1, now(), uuid());
            select max(concept_id) from concept into @abnormal_id;

            insert into concept_name(concept_id, name, locale, locale_preferred,creator, date_created, concept_name_type, uuid) values (@abnormal_id, 'IS_ABNORMAL', 'en', true, 1, now(), 'FULLY_SPECIFIED', uuid());

            call add_concept_set_members (@compound_observation_id, @abnormal_id,1);

        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201403191725" author="Hemanth,Vinay">
        <comment>Add new concept for observation group (XCompoundObservation)</comment>
        <sql>
            update concept set datatype_id = (select concept_datatype_id from concept_datatype where name = 'Boolean'), class_id = (select concept_class_id from concept_class where name = 'Finding'), is_set = 0 where concept_id = (select concept_id from concept_name where name = 'IS_ABNORMAL' and concept_name_type='FULLY_SPECIFIED');
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201403251424" author="Mujir">
        <validCheckSum>3:a56d649cadef2d0f667a04e1c1bf0db2</validCheckSum>
        <comment>Add new concept for Ruled Out Diagnosis</comment>
        <sql>
            set @concept_id = 0;
            set @answer_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, 'Ruled Out Diagnosis', 'Ruled Out Diagnosis', 'N/A', 'Misc', true);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201404021353" author="Hemanth, Mihir" context="rel4">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM person_attribute_type where name = 'givenNameLocal';
            </sqlCheck>
        </preConditions>
        <comment>adding givenNameLocal person attribute type</comment>
        <sql>
            INSERT INTO person_attribute_type (name, description, format, searchable, creator, date_created, retired, sort_weight, uuid) VALUES ('givenNameLocal', 'givenNameLocal', 'java.lang.String', '0', 1, now(), 0, 3, uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201404021359" author="Hemanth, Mihir" context="rel4">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM person_attribute_type where name = 'familyNameLocal';
            </sqlCheck>
        </preConditions>
        <comment>adding familyNameLocal person attribute type</comment>
        <sql>
            INSERT INTO person_attribute_type (name, description, format, searchable, creator, date_created, retired, sort_weight, uuid) VALUES ('familyNameLocal', 'familyNameLocal', 'java.lang.String', '0', 1, now(), 0, 3, uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201404021400" author="Hemanth, Mihir" context="rel4">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM person_attribute_type where name = 'middleNameLocal';
            </sqlCheck>
        </preConditions>
        <comment>adding middleNameLocal person attribute type</comment>
        <sql>
            INSERT INTO person_attribute_type (name, description, format, searchable, creator, date_created, retired, sort_weight, uuid) VALUES ('middleNameLocal', 'middleNameLocal', 'java.lang.String', '0', 1, now(), 0, 3, uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201404091217" author="sushmitharaos, arathyjan" context="rel4">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM encounter_type where name = 'Patient Document';
            </sqlCheck>
        </preConditions>
        <comment>add encounter type for patient document upload</comment>
        <insert tableName="encounter_type">
            <column name="name" value="Patient Document"/>
            <column name="description" value="Patient Document Encounter Type"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201404081624" author="Vivek, Shruthi">
        <validCheckSum>3:3d0122b224fea11193b83de519fe6bf1</validCheckSum>
        <comment>Adding diagnosis meta data concepts</comment>
        <sql>
            set @concept_id = 0;
            set @answer_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, 'Bahmni Diagnosis Status', 'Bahmni Diagnosis Status', 'Coded', 'Misc', true);
            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Bahmni Initial Diagnosis', 'Bahmni Initial Diagnosis', 'Text', 'Misc', true);
            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Bahmni Diagnosis Revised', 'Bahmni Diagnosis Revised', 'Boolean', 'Misc', true);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201404081612" author="Indraneel, Mihir" context="rel4">
        <validCheckSum>3:bfc6b2f1fa801727c5496ff02c3cf9f3</validCheckSum>
        <comment>Adding Lab Manager Notes Concept</comment>
        <sql>
            set @concept_id = 0;
            set @answer_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, 'Lab Manager Notes', 'Lab Manager Notes', 'N/A', 'Misc', false);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201404081625" author="Indraneel, Mihir" context="rel4">
        <comment>Adding Lab Manager Notes Provider</comment>
        <sql>
            set @puuid = uuid();

            insert into person(birthdate_estimated, dead, creator, date_created, uuid)
            values(0, 0, 1, now(), @puuid);

            insert into users(system_id, creator, date_created, person_id, uuid, username)
            values ('Lab Manager', 1, now(),(select person_id from person where uuid = @puuid) , uuid(), 'Lab Manager');

            insert into provider (person_id, identifier, creator, date_created, uuid, name) values ((select person_id from person where uuid = @puuid), 'LABMANAGER', 1, now(), uuid(), 'Lab Manager');</sql>
    </changeSet>
    <changeSet id="bahmni-core-201404101558" author="Indraneel, Neha" context="rel4">
        <validCheckSum>3:78af611c62a4dad7866a56f48d08d84e</validCheckSum>
        <comment>Adding Accession Uuid Concept</comment>
        <sql>
            set @concept_id = 0;
            set @answer_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, 'Accession Uuid', 'Accession Uuid', 'N/A', 'Misc', false);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201404101600" author="Neha,Indraneel" context="rel4">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM encounter_type where name = 'VALIDATION NOTES';
            </sqlCheck>
        </preConditions>
        <comment>Add Encounter Type Validation Notes</comment>
        <sql>
            insert into encounter_type (name, description, creator, date_created, uuid)
            VALUES ('VALIDATION NOTES', 'Validation Notes encounter', 1, curdate(), uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201404211500" author="RT, Shruthi">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Concept Attribute';
            </sqlCheck>
        </preConditions>
        <comment>add concept class Concept Attribute</comment>
        <insert tableName="concept_class">
            <column name="name" value="Concept Attribute"/>
            <column name="description" value="Concept Attribute class"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="retired" value="0"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201404281212" author="RT, Neha">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT COUNT(*) != 0 FROM concept WHERE datatype_id = 1 AND concept_id NOT IN (SELECT concept_id FROM concept_numeric);
            </sqlCheck>
        </preConditions>
        <comment>add concept numeric feild to all numeric concepts</comment>
        <sql>
            INSERT INTO concept_numeric (concept_id) (SELECT concept_id FROM concept WHERE
            datatype_id  = (SELECT concept_datatype_id FROM concept_datatype WHERE name = 'Numeric')
            AND concept_id NOT IN (SELECT concept_id FROM concept_numeric));
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201404281819" author="RT, Mujir">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Abnormal';
            </sqlCheck>
        </preConditions>
        <comment>add concept class Abnormal</comment>
        <insert tableName="concept_class">
            <column name="name" value="Abnormal"/>
            <column name="description" value="Abnormal class"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="retired" value="0"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201404281820" author="RT, Mujir">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Duration';
            </sqlCheck>
        </preConditions>
        <comment>add concept class Duration</comment>
        <insert tableName="concept_class">
            <column name="name" value="Duration"/>
            <column name="description" value="Duration class"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="retired" value="0"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201404281823" author="RT, Mujir">
        <comment>add concept numeric proc</comment>
        <sqlFile splitStatements="false" path="V1_80__AddConceptNumericProc.sql"/>
    </changeSet>
    <changeSet id="bahmni-core-201404281825" author="RT, Mujir">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Concept Details';
            </sqlCheck>
        </preConditions>
        <comment>add concept class Concept Details</comment>
        <insert tableName="concept_class">
            <column name="name" value="Concept Details"/>
            <column name="description" value="Concept Details class"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="retired" value="0"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201404301204" author="RT, Mujir">
        <validCheckSum>3:0cc74f1871cb1efa7199f4f4ea562a07</validCheckSum>
        <comment>delete Concept Proc</comment>
        <sqlFile splitStatements="false" path="V1_81__DeleteConcept.sql"/>
    </changeSet>
    <changeSet id="bahmni-core-201404301520" author="D3">
        <validCheckSum>3:32a6fc34947fd6ad55898c0d3e600ac2</validCheckSum>
        <validCheckSum>3:95dbc7a307cda404901615be33a3c95d</validCheckSum>
        <comment>Configure EMR API admit and discharge encounter type</comment>
        <sql>
            INSERT INTO global_property(property, property_value, description, uuid)
            VALUES('emr.admissionEncounterType', (Select uuid from encounter_type where name = 'ADMISSION'), 'UUID of the encounter type for admitting a patient', 'c4b94bb1-97a8-4252-bec3-c8b17d72b4b5')
            ON DUPLICATE KEY UPDATE property_value = (Select uuid from encounter_type where name = 'ADMISSION');

            INSERT INTO global_property(property, property_value, description, uuid)
            VALUES('emr.exitFromInpatientEncounterType', (Select uuid from encounter_type where name = 'DISCHARGE'), 'UUID of the encounter type for exiting a patient from inpatient care', 'fdb6b9ea-db33-44cb-b946-cc9e02baf50f')
            ON DUPLICATE KEY UPDATE property_value = (Select uuid from encounter_type where name = 'DISCHARGE');
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201405041511" author="Mujir">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Duration';
            </sqlCheck>
        </preConditions>
        <comment>add concept class Duration</comment>
        <insert tableName="concept_class">
            <column name="name" value="Duration"/>
            <column name="description" value="Duration class"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="retired" value="0"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201405061428" author="vinay">
        <validCheckSum>3:61f1718716d2347542975e019859c062</validCheckSum>
        <comment>Fix delete_concept</comment>
        <sql>DROP PROCEDURE IF EXISTS delete_concept;</sql>
        <sql  splitStatements="false" stripComments="false">
            <![CDATA[
            CREATE  PROCEDURE delete_concept (name_concept VARCHAR(255))
            BEGIN
            DECLARE conceptId INT default 0;
                select concept_id INTO conceptId from concept_name where name = name_concept and locale_preferred = 1;
                delete from concept_set where concept_set = conceptId;
                delete from concept_name where concept_id = conceptId;
                delete from concept_numeric where concept_id = conceptId;
                delete from concept_answer where concept_id = conceptId;
                delete from concept_answer where answer_concept = conceptId;
                delete from concept_reference_map where concept_id = conceptId;
                delete from concept where concept_id = conceptId;
            END;
            ]]>
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201405071329" author="mujir" context="rel4">
        <validCheckSum>3:d0b49ca7745107877d6019920536f0de</validCheckSum>
        <comment>add adt notes data concept set</comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;

            select concept_id INTO @adt_notes_id from concept_name where name='Adt Notes' and locale_preferred = 1;

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Adt Notes Data', 'Adt Notes Data', 'N/A', 'Concept Details', true);
            set @adt_notes_data_id = @concept_id;
            call add_concept_set_members(@adt_notes_data_id, @adt_notes_id, 0);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201405081436" author="mujir" context="rel4">
        <comment>remove adt notes data concept set</comment>
        <sql>
            call delete_concept('Adt Notes Data');
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201405061543" author="mujir">
        <validCheckSum>3:23ca21a6b0be660b4b3fad3505f1b161</validCheckSum>
        <comment>Fix delete_concept. deleting concept set membership for the concept to be deleted.</comment>
        <sql>DROP PROCEDURE IF EXISTS delete_concept;</sql>
        <sql  splitStatements="false" stripComments="false">
            <![CDATA[
            CREATE  PROCEDURE delete_concept (name_concept VARCHAR(255))
            BEGIN
            DECLARE conceptId INT default 0;
                select concept_id INTO conceptId from concept_name where name = name_concept and locale_preferred = 1;
                delete from concept_set where concept_set = conceptId;
                delete from concept_set where concept_id = conceptId;
                delete from concept_name where concept_id = conceptId;
                delete from concept_numeric where concept_id = conceptId;
                delete from concept_answer where concept_id = conceptId;
                delete from concept_answer where answer_concept = conceptId;
                delete from concept_reference_map where concept_id = conceptId;
                delete from concept where concept_id = conceptId;
            END;
            ]]>
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201405091936" author="rohan">
        <comment>Change sort weight for Admit Patients.</comment>
        <sql>
            update concept_answer set sort_weight=10 where answer_concept=(select concept_id from concept_name where name='Admit Patient' limit 1);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201405110939" author="rohan">
        <comment>Change sort weight for Discharge Patients.</comment>
        <sql>
            update concept_answer set sort_weight=100 where answer_concept=(select concept_id from concept_name where name='Discharge Patient' limit 1);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201405110940" author="rohan">
        <comment>Change sort weight for Transfer Patients.</comment>
        <sql>
            update concept_answer set sort_weight=200 where answer_concept=(select concept_id from concept_name where name='Transfer Patient' limit 1);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201405161709" author="d3" context="rel4">
        <validCheckSum>3:955279b9326084c5c0ad3f2df90295e0</validCheckSum>
        <validCheckSum>3:752289f5803016fad52abe864a8278c5</validCheckSum>
        <comment>Update webservices.rest.maxResultsAbsolute to 1000</comment>
        <sql>
            INSERT INTO global_property(property, property_value, description, uuid)
            VALUES('webservices.rest.maxResultsAbsolute', 1000, 'The absolute results limit. If the client requests a larger number of results, then will get an error', '829347ef-1e0d-4368-8681-56f9544a0adc')
            ON DUPLICATE KEY UPDATE property_value = 1000;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201405211239" author="d3" context="rel4">
        <comment>Add global property bahmni.cacheHeadersFilter.expiresDuration</comment>
        <sql>
            INSERT INTO global_property(`property`, `property_value`, `description`, `uuid`)
            VALUES ('bahmni.cacheHeadersFilter.expiresDuration', '0', 'Expires duration in minutes', '672dc790-e0b6-11e3-8b68-0800200c9a66')
            ON DUPLICATE KEY UPDATE property_value = '0';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407011716" author="Crude Oil with our names">
        <comment>Add person name for lab and billing system users</comment>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into person_name (preferred, person_id,given_name, family_name, creator,uuid, date_created)
            select true, person_id, 'Lab', 'System', 1, @uuid, now() from users where username =  'Lab System';

            select uuid() into @uuid;
            insert into person_name (preferred, person_id,given_name, family_name, creator,uuid, date_created)
            select true, person_id, 'Billing', 'System', 1, @uuid, now() from users where username =  'Billing System';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407141716" author="vinay">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM privilege where privilege = 'Get Order Frequencies';
            </sqlCheck>
        </preConditions>
        <comment>New privileges added</comment>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            INSERT INTO `privilege` (`privilege`,`description`,`uuid`) VALUES ('Get Order Frequencies','Able to get Order Frequencies',@uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407141717" author="vinay">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM privilege where privilege = 'Manage Order Frequencies';
            </sqlCheck>
        </preConditions>
        <comment>New privileges added</comment>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            INSERT INTO `privilege` (`privilege`,`description`,`uuid`) VALUES ('Manage Order Frequencies','Able to add/edit/retire Order Frequencies',@uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407141718" author="vinay">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM privilege where privilege = 'Get Care Settings';
            </sqlCheck>
        </preConditions>
        <comment>New privileges added</comment>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            INSERT INTO `privilege` (`privilege`,`description`,`uuid`) VALUES ('Get Care Settings','Able to get Care Settings',@uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407161230" author="Rohan,Indraneel">
        <comment>Global property pointing to the new encounter provider only session matcher</comment>
        <sql>
            insert into global_property
                (`property`,
                `property_value`,
                `description`,
                `uuid`)
            values
                ('emr.encounterProviderMatcher',
                'org.bahmni.module.bahmnicore.matcher.EncounterProviderSessionMatcher',
                'Encountersession matcher which considers only encounter type and provider',
                uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407161630" author="Vinay">
        <comment>Set dosing type and dosing instructions</comment>
        <sql>
            update drug_order
            inner join drug on drug_order.drug_inventory_id = drug.drug_id
            inner join concept_name on drug.dosage_form = concept_name.concept_id and
            concept_name.concept_name_type = 'FULLY_SPECIFIED'
            set drug_order.dosing_instructions = concat(drug_order.dose, ' ', concept_name.name),
            drug_order.dosing_type = 'FREE_TEXT';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407171606" author="Rohan, D3">
        <comment>add concept class Image</comment>
        <insert tableName="concept_class">
            <column name="name" value="Image"/>
            <column name="description" value="Image class"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="retired" value="0"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201407180800" author="Shruthi">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Computed';
            </sqlCheck>
        </preConditions>
        <comment>add concept class Computed</comment>
        <insert tableName="concept_class">
            <column name="name" value="Computed"/>
            <column name="description" value="Computed"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="retired" value="0"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201407221627" author="Rohan, Shruthi">
        <preConditions>
            <sqlCheck expectedResult="1">
                SELECT COUNT(*) FROM global_property where property = 'emr.encounterMatcher'
            </sqlCheck>
        </preConditions>
        <comment>Update custom encounter session matcher</comment>
        <sql>
            update global_property set property_value='org.openmrs.module.bahmniemrapi.encountertransaction.matcher.EncounterSessionMatcher' where property='emr.encounterMatcher' ;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407221628" author="Rohan, Shruthi">
        <preConditions>
            <sqlCheck expectedResult="1">
                SELECT COUNT(*) FROM global_property where property = 'emr.encounterProviderMatcher'
            </sqlCheck>
        </preConditions>
        <comment>Update custom encounter session matcher</comment>
        <sql>
            update global_property set property_value='org.openmrs.module.bahmniemrapi.encountertransaction.matcher.EncounterProviderSessionMatcher' where property='emr.encounterProviderMatcher';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407251510" author="D3">
        <validCheckSum>3:1c02bbb4699963a7c83ea542f2ea9236</validCheckSum>
        <comment>Set quantity for drug orders without this data</comment>
        <sql>
            UPDATE drug_order
            JOIN orders on drug_order.order_id = orders.order_id
            SET quantity = (datediff(auto_expire_date, date_activated) * dose)
            WHERE quantity IS NULL;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407251511" author="D3">
        <comment>Set num_refills for drug orders without this data</comment>
        <sql>
            UPDATE drug_order
            SET num_refills = 0
            WHERE num_refills IS NULL;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407171215" author="Vinay,Indraneel">
        <validCheckSum>3:67ea9e924f423254cfd3658b87c38eed</validCheckSum>
        <comment>Adding concepts and concept set related to dosing units </comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @concept_set_uuid='';
            set @uuid = '';

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

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

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

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

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

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

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

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

            select c.uuid from concept_name cn inner join concept c on cn.concept_id = c.concept_id where cn.name = 'Dosing Units' and cn.concept_name_type = 'FULLY_SPECIFIED' into @concept_set_uuid;
            select uuid() into @uuid;

            insert into global_property
            (`property`,
            `property_value`,
            `description`,
            `uuid`)
            values
            ('order.drugDosingUnitsConceptUuid',
            @concept_set_uuid,
            'Global property pointing to dosing units concept set',
            @uuid)
            ON DUPLICATE KEY UPDATE
            `property_value`=@concept_set_uuid;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407171300" author="Vinay, Indraneel">
        <validCheckSum>3:e9299d5f6a6555c2d7ab498f5a515f80</validCheckSum>
        <comment>Add drug routes and set global property</comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @uuid = '';

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Drug Routes', 'drug routes', 'N/A', 'ConvSet', true);
            set @set_concept_id = @concept_id;

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

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

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Per Os', 'PO', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,1);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Per Vaginal', 'PV', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,1);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Sub Cutaneous', 'SC', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,1);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Per Rectum', 'PR', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,1);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Sub Lingual', 'SL', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,1);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Percutaneous Endoscopic Gastrostomy', 'PEG', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,1);

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

            select c.uuid from concept_name cn inner join concept c on cn.concept_id = c.concept_id where cn.name = 'Drug Routes' and cn.concept_name_type = 'FULLY_SPECIFIED' into @concept_set_uuid;
            select uuid() into @uuid;

            insert into global_property
            (`property`,
            `property_value`,
            `description`,
            `uuid`)
            values
            ('order.drugRoutesConceptUuid',
            @concept_set_uuid,
            'Global property pointing to drug routes concept set',
            @uuid)
            ON DUPLICATE KEY UPDATE
            `property_value`=@concept_set_uuid;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-202305121314" author="Angshu">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(*) from global_property where property = 'order.durationUnitsConceptUuid' and property_value IS NULL;
            </sqlCheck>
        </preConditions>
        <comment>Adding duration unit concepts and setting up associated global property. CIEL dataset should create the actual members. this is replacement of changeset bahmni-core-201906101318</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', 'Coded', 'ConvSet', true);

            update concept set uuid = '1732AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' where concept_id=@concept_id;

            insert into global_property
            (`property`,
             `property_value`,
             `description`,
             `uuid`)
            values
                ('order.durationUnitsConceptUuid',
                 '1732AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
                 'Global property pointing to duration units concept set',
                 @uuid)
            ON DUPLICATE KEY UPDATE `property_value`='1732AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407171715" author="Vinay, Indraneel">
        <validCheckSum>3:0eca0d167cd6e8ae3738ef2dadb1f2b6</validCheckSum>
        <comment></comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @uuid = 0;
            set @now = now();

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Once a day', 'OD', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 1, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Twice a day', 'BD', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 2, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Thrice a day', 'TDS', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 3, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Four times a day', 'QDS', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 4, 1, @now, @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201407291254" author="Vinay, Deepak">
        <validCheckSum>3:b281314578771f23d480ae45d66e38ea</validCheckSum>
        <comment></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, 'Dosing Instructions', 'Dosing Instructions', 'N/A', 'ConvSet', true);
            set @set_concept_id = @concept_id;

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Before meals', 'ac', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,1);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Empty stomach', '', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,2);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'After meals', 'pc', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,3);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'In the morning', 'cm', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,4);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'In the evening', '', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,5);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'At bedtime', 'hs', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,6);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Immediately', 'STAT', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,7);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'As directed', '', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id,@concept_id,8);

            select c.uuid from concept_name cn inner join concept c on cn.concept_id = c.concept_id where cn.name = 'Dosing Instructions' and cn.concept_name_type = 'FULLY_SPECIFIED' into @concept_set_uuid;
            select uuid() into @uuid;

            insert into global_property
            (`property`,
            `property_value`,
            `description`,
            `uuid`)
            values
            ('order.dosingInstructionsConceptUuid',
            @concept_set_uuid,
            'Global property pointing to duration units concept set',
            @uuid)
            ON DUPLICATE KEY UPDATE
            `property_value`=@concept_set_uuid;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201408111300" author="Indraneel" >
        <validCheckSum>3:106fe9b9c492f9d9c0f93d65dd1aa516</validCheckSum>
        <comment>Adding all templates concept set of sets</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, 'All Observation Templates', 'All Observation templates', 'N/A', 'ConvSet', true);
            set @set_concept_id = @concept_id;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-20140814132600" author="Rohan, Vinay" >
        <comment>Update Dosing type from ENUM to Class Name</comment>
        <sql>
            update drug_order set dosing_type='org.openmrs.FreeTextDosingInstructions' where dosing_type='FREE_TEXT';
            update drug_order set dosing_type='org.openmrs.SimpleDosingInstructions' where dosing_type='SIMPLE';
        </sql>
    </changeSet>
    <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">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM global_property where property = 'uploaded.files.directory'
            </sqlCheck>
        </preConditions>
        <comment>Add directory for imported files</comment>
        <sql>
            insert into global_property (`property`, `property_value`, `description`, `uuid`)
            values ('uploaded.files.directory', '/home/bahmni/uploaded-files/mrs/', 'Directory where files uploaded to Bahmni are stored', uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201408251140" author="Sravanthi,Indraneel">
        <comment>
            Introducing Obs relationship type and obs relationship tables
        </comment>
        <sql>
            CREATE TABLE obs_relationship_type(
                obs_relationship_type_id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
                name VARCHAR(50) NOT NULL,
                description VARCHAR(255),
                uuid CHAR(38) NOT NULL,
                creator INT NOT NULL,
                date_created DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
                retired TINYINT DEFAULT 0 NOT NULL,
                date_retired DATETIME,
                retired_by INT,
                retire_reason VARCHAR(255),
                date_changed DATETIME,
                changed_by INT,
                FOREIGN KEY (creator) REFERENCES users (user_id),
                FOREIGN KEY (changed_by) REFERENCES users (user_id),
                FOREIGN KEY (retired_by) REFERENCES users (user_id)
            );
            CREATE UNIQUE INDEX uuid ON obs_relationship_type (uuid);

            CREATE TABLE obs_relationship(
                obs_relationship_id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
                obs_relationship_type_id INT NOT NULL,
                source_obs_id INT NOT NULL,
                target_obs_id INT NOT NULL,
                uuid CHAR(38) NOT NULL,
                date_created DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
                creator INT NOT NULL,
                FOREIGN KEY (obs_relationship_type_id) REFERENCES obs_relationship_type (obs_relationship_type_id),
                FOREIGN KEY (source_obs_id) REFERENCES obs (obs_id),
                FOREIGN KEY (target_obs_id) REFERENCES obs (obs_id),
                FOREIGN KEY (creator) REFERENCES person (person_id)
            );
            CREATE UNIQUE INDEX uuid ON obs_relationship (uuid);
        </sql>
    </changeSet>

    <changeSet id="bahmni-clinical-201408251220" author="D3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'app:admin'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="app:admin"/>
            <column name="description" value="Bahmni admin app access privilege"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>

    <changeSet id="bahmni-core-201408251455" author="Rohan">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'URL';
            </sqlCheck>
        </preConditions>
        <comment>add concept class URL</comment>
        <insert tableName="concept_class">
            <column name="name" value="URL"/>
            <column name="description" value="URL"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="retired" value="0"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <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;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @labresults_concept_id = 0;

            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' GROUP BY concept_id;
            set @set_concept_id = @concept_id;
            call add_concept_set_members (@labresults_concept_id,@set_concept_id,1);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409091224" author="Mihir, Shruthi">
        <comment>Removing global property for encounter provider matcher</comment>
        <sql>
            delete from global_property where property='emr.encounterProviderMatcher';
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201409081432" author="Rohan, Vinay">
        <comment>rel2</comment>
        <sql>
            DROP PROCEDURE IF EXISTS add_concept;
        </sql>
        <sqlFile splitStatements="false" path="V1_82__ChangeAddConceptProc.sql"/>
    </changeSet>

    <changeSet id="bahmni-core-201409111200" author="Rohan, Vinay">
        <comment>Adding tablet and capsule concepts to dosing units</comment>
        <sql>
            set @tablet_concept_id = 0;
            set @capsule_concept_id = 0;
            set @concept_set_id=0;

            select concept_id from concept_name where name = 'Dosing Units' and concept_name_type = 'FULLY_SPECIFIED' into @set_concept_id;
            select concept_id from concept_name where name = 'Tablet' and concept_name_type = 'FULLY_SPECIFIED' into @tablet_concept_id;
            select concept_id from concept_name where name = 'Capsule' and concept_name_type = 'FULLY_SPECIFIED' into @capsule_concept_id;

            call add_concept_set_members (@set_concept_id,@tablet_concept_id,1);

            call add_concept_set_members (@set_concept_id,@capsule_concept_id,1);
        </sql>
    </changeSet>
    <changeSet id="bahmnimapping-201409121125" author="Chethan, D3">
        <preConditions onFail="MARK_RAN">
            <not><tableExists tableName="location_encounter_type_map"/></not>
        </preConditions>
        <createTable tableName="location_encounter_type_map">
            <column autoIncrement="true" name="id" type="int"> <constraints nullable="false" primaryKey="true"/> </column>
            <column name="location_id" type="int"> <constraints nullable="false"/> </column>
            <column name="encounter_type_id" type="int"> <constraints nullable="false"/> </column>
            <column name="creator" type="int"> <constraints nullable="false"/> </column>
            <column name="date_created" type="DATETIME"> <constraints nullable="false"/> </column>
            <column name="changed_by" type="int"/>
            <column name="date_changed" type="DATETIME"/>
            <column name="uuid" type="char(38)" />
            <column defaultValueBoolean="false" name="voided" type="BOOLEAN"><constraints nullable="false" /></column>
            <column name="date_voided" type="datetime" />
            <column name="voided_by" type="int" />
            <column name="void_reason" type="varchar(255)" />
        </createTable>
        <addForeignKeyConstraint constraintName="location_encounter_type_map_location_id_fk"
                                 baseTableName="location_encounter_type_map" baseColumnNames="location_id"
                                 referencedTableName="location" referencedColumnNames="location_id" />
        <addForeignKeyConstraint constraintName="location_encounter_type_map_encounter_type_id_fk"
                                 baseTableName="location_encounter_type_map" baseColumnNames="encounter_type_id"
                                 referencedTableName="encounter_type" referencedColumnNames="encounter_type_id" />
        <addForeignKeyConstraint constraintName="location_encounter_type_map_creator_fk"
                                 baseTableName="location_encounter_type_map" baseColumnNames="creator"
                                 referencedTableName="users" referencedColumnNames="user_id" />
        <addForeignKeyConstraint constraintName="location_encounter_type_map_changed_by_fk"
                                 baseTableName="location_encounter_type_map" baseColumnNames="changed_by"
                                 referencedTableName="users" referencedColumnNames="user_id" />
        <addForeignKeyConstraint constraintName="location_encounter_type_map_voided_by_fk"
                                 baseTableName="location_encounter_type_map" baseColumnNames="voided_by"
                                 referencedTableName="users" referencedColumnNames="user_id" />
    </changeSet>
    <changeSet id="bahmni-core-20140908172845" author="Indraneel, Hemanth">
        <validCheckSum>3:443fc5590784d91c87f4551ca782b7f1</validCheckSum>
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                select count(*) from concept_name where name = 'Impression';
            </sqlCheck>
        </preConditions>
        <comment>Add Impression concept</comment>
        <sql>
            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Impression', 'Impression', 'Text', 'Misc', false);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409161415" author="Indraneel">
        <comment>
            Adding obs relationship type : qualified-by
        </comment>
        <sql>
            INSERT INTO obs_relationship_type (name, description, uuid, creator)
            VALUES ('qualified-by', 'target is qualified by source', 'dbde17aa-3d7e-11e4-8782-164230d1df67', 1);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201409171047" author="Rohan, Hemanth">
        <comment>Fix the new add_concept procedure</comment>
        <sql>
            DROP PROCEDURE IF EXISTS add_concept;
        </sql>
        <sqlFile splitStatements="false" path="V1_83__FixAddConceptProc.sql"/>
    </changeSet>
    <changeSet id="bahmni-core-201409171530" author="D3">
        <comment>Rename OPD encounter type to Consultation</comment>
        <update tableName="encounter_type">
            <column name="name" value="Consultation"/>
            <column name="description" value="Consultation encounter"/>
            <where>name = 'OPD'</where>
        </update>
    </changeSet>
    <changeSet id="bahmni-core-201409241126" author="Hemanth">
        <comment>Update hl7_code for concept reference source 'ISO 8601 Duration'</comment>
        <sql>
            update concept_reference_source set hl7_code = 'SCT' where name='ISO 8601 Duration';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409241137" author="Hemanth">
        <comment>Update code for concept reference term 'Second(s)'</comment>
        <sql>
            update concept_reference_term set code='257997001' where name='Second(s)';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409241138" author="Hemanth">
        <comment>Update code for concept reference term 'Minute(s)'</comment>
        <sql>
            update concept_reference_term set code='258701004' where name='Minute(s)';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409241139" author="Hemanth">
        <comment>Update code for concept reference term 'Hour(s)'</comment>
        <sql>
            update concept_reference_term set code='258702006' where name='Hour(s)';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409241140" author="Hemanth">
        <comment>Update code for concept reference term 'Day(s)'</comment>
        <sql>
            update concept_reference_term set code='258703001' where name='Day(s)';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409241141" author="Hemanth">
        <comment>Update code for concept reference term 'Week(s)'</comment>
        <sql>
            update concept_reference_term set code='258705008' where name='Week(s)';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409241142" author="Hemanth">
        <comment>Update code for concept reference term 'Month(s)'</comment>
        <sql>
            update concept_reference_term set code='258706009' where name='Month(s)';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409241143" author="Hemanth">
        <comment>Update code for concept reference term 'Year(s)'</comment>
        <sql>
            update concept_reference_term set code='258707000' where name='Year(s)';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409241144" author="Hemanth">
        <comment>Update code for concept reference term 'Time(s)'</comment>
        <sql>
            update concept_reference_term set code='252109000' where name='Time(s)';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409241241" author="Hemanth">
        <comment>Update name for concept reference source 'ISO 8601 Duration'</comment>
        <sql>
            update concept_reference_source set name='SNOMED', description='SNOMED Duration Source' where name='ISO 8601 Duration';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409242241" author="Mihir">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Sample';
            </sqlCheck>
        </preConditions>
        <comment>Add concept class for lab samples</comment>
        <sql>
            set @uuid = '';
            set @date = '';
            select uuid() into @uuid;
            select curdate() into @date;
            select @uuid;
            insert into concept_class (name, description, creator, date_created, retired, uuid)
            values ('Sample', 'Lab Samples Concept Class', 1, @date, 0, @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409242242" author="Mihir">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Department';
            </sqlCheck>
        </preConditions>
        <comment>Add concept class for lab samples</comment>
        <sql>
            set @uuid = '';
            set @date = '';
            select uuid() into @uuid;
            select curdate() into @date;
            select @uuid;
            insert into concept_class (name, description, creator, date_created, retired, uuid)
            values ('Department', 'Lab Departments Concept Class', 1, @date, 0, @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409242248" author="Mihir">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT COUNT(*) FROM concept_class where name = 'Sample';
            </sqlCheck>
        </preConditions>
        <comment>Migrate sample concepts to concept class sample</comment>
        <sql>
            UPDATE concept SET class_id = (SELECT concept_class_id FROM concept_class WHERE name = 'Sample') WHERE concept_id IN (SELECT concept_id FROM concept_set WHERE concept_set = (SELECT distinct concept_id FROM concept_name WHERE name = 'Laboratory'));
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409242256" author="Mihir">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT COUNT(*) FROM concept_class where name = 'Department';
            </sqlCheck>
        </preConditions>
        <comment>Migrate department concepts to concept class department</comment>
        <sql>
            UPDATE concept SET class_id = (SELECT concept_class_id FROM concept_class WHERE name = 'Department') WHERE concept_id IN (SELECT concept_id FROM concept_set WHERE concept_set = (SELECT distinct concept_id FROM concept_name WHERE name = 'Lab Departments'));
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409242259" author="Mihir">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM concept_name where name='Laboratory' and concept_name_type='FULLY_SPECIFIED';
            </sqlCheck>
        </preConditions>
        <comment>Rename Laboratory concept to Lab Samples</comment>
        <sql>
            update concept_name set name='Lab Samples' where name='Laboratory' and concept_name_type='FULLY_SPECIFIED';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409291830" author="Indraneel">
        <validCheckSum>3:59227f59b0dc69aedb429642ea0c528a</validCheckSum>
        <comment>Adding All Disease Templates Concept Set</comment>
        <sql>
            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'All Disease Templates', 'All Disease Templates', 'N/A', 'ConvSet', true);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409291027" author="Chethan,Banka">
        <validCheckSum>3:4d2eac86ae2e3719506593f3446ce962</validCheckSum>
        <comment>Adding concepts and concept set related to dosing units</comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;

            select concept_id into @set_concept_id from concept_name where name = 'Dosing Units' and concept_name_type = 'FULLY_SPECIFIED';

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

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Unit(s)', 'unit(s)', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id, @concept_id, 1);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409291037" author="Chethan, Banka">
        <validCheckSum>3:8b1b389e659dd0b96682abd8769b64c5</validCheckSum>
        <comment>Adding order frequencies</comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @uuid = 0;
            set @now = now();

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Every Hour', 'QH', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 24, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Every 2 hours', 'Q2H', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 12, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Every 3 hours', 'Q3H', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 8, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Every 4 hours', 'Q4H', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 6, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Every 6 hours', 'Q6H', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 4, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Every 8 hours', 'Q8H', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 3, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Every 12 hours', 'Q12H', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 2, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'On alternate days', 'A/D', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 1/2, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Once a week', '', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 1/7, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Twice a week', '', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 2/7, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Thrice a week', '', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 3/7, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Every 2 weeks', '', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 1/14, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Every 3 weeks', '', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 1/21, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Once a month', '', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 1/30, 1, @now, @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409291106" author="Chethan,Banka">
        <validCheckSum>3:e16e8fe4446e38963a84a7a9681b9c54</validCheckSum>
        <comment>Add drug routes and delete Percutaneous Endoscopic Gastrostomy</comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @uuid = '';

            select concept_id into @set_concept_id from concept_name where name = 'Drug Routes' and concept_name_type = 'FULLY_SPECIFIED';

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

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

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

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

            call delete_concept('Percutaneous Endoscopic Gastrostomy');
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-202304192144" author="Angshu">
        <comment>Removing update of Duration Units concept member name. Replacement of changeset bahmni-core-201409291704. Also only checking for dosing unit Oral</comment>
        <sql>
            UPDATE concept_name SET name='Oral' where name='Per Os' and concept_name_type='FULLY_SPECIFIED';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201409291720" author="Chethan,Banka">
        <comment>Changing sort order for dose units</comment>
        <sql>
            select concept_id into @dosing_units_concept_id from concept_name where name = 'Dosing Units' and concept_name_type = 'FULLY_SPECIFIED';

            UPDATE concept_set, concept_name SET concept_set.sort_weight = 1 where concept_set.concept_id = concept_name.concept_id and concept_name.name = 'Tablet(s)' and concept_set.concept_set = @dosing_units_concept_id;
            UPDATE concept_set, concept_name SET concept_set.sort_weight = 2 where concept_set.concept_id = concept_name.concept_id and concept_name.name = 'Capsule(s)' and concept_set.concept_set = @dosing_units_concept_id;
            UPDATE concept_set, concept_name SET concept_set.sort_weight = 3 where concept_set.concept_id = concept_name.concept_id and concept_name.name = 'ml' and concept_set.concept_set = @dosing_units_concept_id;
            UPDATE concept_set, concept_name SET concept_set.sort_weight = 4 where concept_set.concept_id = concept_name.concept_id and concept_name.name = 'mg' and concept_set.concept_set = @dosing_units_concept_id;
            UPDATE concept_set, concept_name SET concept_set.sort_weight = 5 where concept_set.concept_id = concept_name.concept_id and concept_name.name = 'IU' and concept_set.concept_set = @dosing_units_concept_id;
            UPDATE concept_set, concept_name SET concept_set.sort_weight = 6 where concept_set.concept_id = concept_name.concept_id and concept_name.name = 'Drop' and concept_set.concept_set = @dosing_units_concept_id;
            UPDATE concept_set, concept_name SET concept_set.sort_weight = 7 where concept_set.concept_id = concept_name.concept_id and concept_name.name = 'Tablespoon' and concept_set.concept_set = @dosing_units_concept_id;
            UPDATE concept_set, concept_name SET concept_set.sort_weight = 8 where concept_set.concept_id = concept_name.concept_id and concept_name.name = 'Teaspoon' and concept_set.concept_set = @dosing_units_concept_id;
            UPDATE concept_set, concept_name SET concept_set.sort_weight = 9 where concept_set.concept_id = concept_name.concept_id and concept_name.name = 'Unit(s)' and concept_set.concept_set = @dosing_units_concept_id;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201410071237" author="D3,Arun">
        <comment>Add index for orders date_activated</comment>
        <sql>
            CREATE INDEX bahmni_orders_date_activated ON orders(date_activated);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201410061440" author="Chethan, Banka">
        <preConditions onFail="CONTINUE">
            <sqlCheck expectedResult="1">select count(*) from global_property where property = 'encounter.feed.publish.url'</sqlCheck>
        </preConditions>
        <comment>Updating GP encounter feed publish url to publish BahmniEncounterTransaction</comment>
        <update tableName="global_property">
            <column name="property_value" value="/openmrs/ws/rest/v1/bahmnicore/bahmniencounter/%s?includeAll=true"/>
            <where>property='encounter.feed.publish.url'</where>
        </update>
    </changeSet>
    <changeSet id="bahmni-core-201410101048" author="Rohan, Chethan">
        <comment>Remove class name of reference data feed task and failed event task.</comment>
        <sql>
            delete from scheduler_task_config WHERE name = 'Reference Data Task';
            delete from scheduler_task_config WHERE name = 'Reference Data Failed Event Task';
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201410151525" author="Rohan, Hemanth">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='app:clinical:history'</sqlCheck>
        </preConditions>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('app:clinical:history', 'Bahmni observation history view and edit', @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201410151526" author="Rohan, Hemanth">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='app:clinical:diagnosisTab'</sqlCheck>
        </preConditions>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('app:clinical:diagnosisTab', 'View and Edit Diagnosis tab', @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201410151527" author="Rohan, Hemanth">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='app:clinical:dispositionTab'</sqlCheck>
        </preConditions>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('app:clinical:dispositionTab', 'View Disposition tab', @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201410151528" author="Rohan, Hemanth">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='app:clinical:observationTab'</sqlCheck>
        </preConditions>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('app:clinical:observationTab', 'View Observation tab', @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201410151529" author="Rohan, Hemanth">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='app:clinical:consultationTab'</sqlCheck>
        </preConditions>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('app:clinical:consultationTab', 'View Consultation tab', @uuid);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201511121343" author="goodrich">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='View Providers'</sqlCheck>
        </preConditions>
        <comment>Workaround for adding missing View Providers privlege</comment>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('View Providers', 'Able to view Provider', @uuid);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201511121200" author="goodrich">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='View Visit Types'</sqlCheck>
        </preConditions>
        <comment>Workaround for adding missing View Providers privlege</comment>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('View Visit Types', 'Able to view Visit Types', @uuid);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201511121201" author="goodrich">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='View Visits'</sqlCheck>
        </preConditions>
        <comment>Workaround for adding missing View Providers privlege</comment>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('View Visits', 'Able to view Visits', @uuid);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201511121245" author="goodrich">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='View Visit Attribute Types'</sqlCheck>
        </preConditions>
        <comment>Workaround for adding missing View Visit Attribute Types privlege</comment>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('View Visit Attribute Types', 'Able to view Visit Attribute Types', @uuid);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201410151040" author="Mihir, Bharti">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM concept_name where name='Lab Samples' and concept_name_type='FULLY_SPECIFIED';
            </sqlCheck>
        </preConditions>
        <comment>Rename Laboratory concept to Lab Samples</comment>
        <sql>
            UPDATE concept
            SET class_id = (SELECT
            concept_class_id
            FROM concept_class
            WHERE uuid = '8d492594-c2cc-11de-8d13-0010c6dffd0f')
            WHERE concept_id = (SELECT
            concept_id
            FROM concept_name
            WHERE name = 'Lab Samples' AND concept_name_type = 'FULLY_SPECIFIED');
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201410211423" author="d3, rohan">
        <comment>Set global property default_locale to en</comment>
        <sql>
            INSERT INTO global_property(`property`, `property_value`, `description`, `uuid`)
            VALUES ('default_locale', 'en', 'Specifies the default locale. You can specify both the language code(ISO-639) and the country code(ISO-3166), e.g. \'en_GB\' or just country: e.g. \'en\'', 'ffc74409-b8e1-48e7-a318-8810a2f452da')
            ON DUPLICATE KEY UPDATE property_value = 'en';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201410301713" author="Vinay">
        <validCheckSum>3:6188bf0917228defa2c058eb141f90df</validCheckSum>
        <comment>Fix the new add_concept procedure</comment>
        <sql>
            DROP PROCEDURE IF EXISTS add_concept;
        </sql>
        <sqlFile splitStatements="false" path="V1_84__FixAddConceptProc.sql"/>
    </changeSet>
    <changeSet id="bahmni-core-201411031108" author="Vinay, sravanthi">
        <validCheckSum>3:9d7ca5167308aeea04c82a867098154e</validCheckSum>
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM concept_name where name='Tablet' and concept_name_type='FULLY_SPECIFIED';
            </sqlCheck>
        </preConditions>
        <comment>Adding new concept for Tablet as drug form</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, 'Tablet', 'tablet', 'N/A', 'Misc', false);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201411031129" author="Vinay, sravanthi">
        <validCheckSum>3:5db567592d0dfe203c5a3a6a159c7c61</validCheckSum>
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM concept_name where name='Capsule' and concept_name_type='FULLY_SPECIFIED';
            </sqlCheck>
        </preConditions>
        <comment>Adding new concept for Capsule as drug form</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, 'Capsule', 'capsule', 'N/A', 'Misc', false);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201411031131" author="Vinay, sravanthi">
        <comment>Update drug table to use the new drug forms created</comment>
        <sql>
            select distinct concept_id from concept_name where name = 'Tablet(s)' and concept_name_type = 'FULLY_SPECIFIED' into @tablets_concept_id;
            select distinct concept_id from concept_name where name = 'Tablet' and concept_name_type = 'FULLY_SPECIFIED'  into @tablet_concept_id;

            update drug set dosage_form = @tablet_concept_id where dosage_form = @tablets_concept_id;

            select distinct concept_id from concept_name where name = 'Capsule(s)' and concept_name_type = 'FULLY_SPECIFIED'  into @capsules_concept_id;
            select distinct concept_id from concept_name where name = 'Capsule' and concept_name_type = 'FULLY_SPECIFIED'  into @capsule_concept_id;

            update drug set dosage_form = @capsule_concept_id where dosage_form = @capsules_concept_id;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201411041237" author="Vinay">
        <comment>Ensure drug orders are always in units</comment>
        <sql>
            select distinct concept_id from concept_name where name = 'Unit(s)' and concept_name_type = 'FULLY_SPECIFIED'  into @units_concept_id;

            update drug_order set quantity_units = @units_concept_id;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201411041711" author="Vinay">
        <comment>Make sure doseUnits and dosingInstructions for reverse synced drug orders are sane</comment>
        <sql>
            update drug_order set dose = null where dose_units is null;

            update drug_order set dosing_instructions = replace(dosing_instructions, 'Tablet', 'Tablet(s)') where dosing_instructions not like '%Tablet(s)%';

            update drug_order set dosing_instructions = replace(dosing_instructions, 'Capsule', 'Capsule(s)') where dosing_instructions not like '%Capsule(s)%';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201411051148" author="Rohan">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'LabTest';
            </sqlCheck>
        </preConditions>
        <comment>Add concept class LabTest</comment>
        <sql>
            set @uuid = '';
            set @date = '';
            select uuid() into @uuid;
            select curdate() into @date;
            select @uuid;
            insert into concept_class (name, description, creator, date_created, retired, uuid)
            values ('LabTest', 'Lab Tests', 1, @date, 0, @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201411051149" author="Rohan">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Radiology';
            </sqlCheck>
        </preConditions>
        <comment>Add concept class Radiology</comment>
        <sql>
            set @uuid = '';
            set @date = '';
            select uuid() into @uuid;
            select curdate() into @date;
            select @uuid;
            insert into concept_class (name, description, creator, date_created, retired, uuid)
            values ('Radiology', 'Radiology Orders', 1, @date, 0, @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201411061606" author="Vinay, Mihir">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from chunking_history;</sqlCheck>
        </preConditions>
        <comment>Default chunking history entry if doesn't exist.</comment>
        <insert tableName="chunking_history">
            <column name="chunk_length" valueNumeric="5"/>
            <column name="start" valueNumeric="1"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201411131512" author="D3">
        <validCheckSum>3:809bb2af1d4d95755dcf48f62c3a1840</validCheckSum>
        <comment>Add drug routes Topical, Nasal, Inhalation</comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;

            select concept_id into @set_concept_id from concept_name where name = 'Drug Routes' and concept_name_type = 'FULLY_SPECIFIED';

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

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

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Inhalation', 'RESPIR', 'N/A', 'Misc', false);
            call add_concept_set_members (@set_concept_id, @concept_id, 1);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201411141310" author="D3">
        <comment>Fix the new add_concept procedure</comment>
        <sql>
            DROP PROCEDURE IF EXISTS add_concept;
        </sql>
        <sqlFile splitStatements="false" path="V1_85__FixAddConceptProc.sql"/>
    </changeSet>
    <changeSet id="bahmni-core-201411141315" author="D3">
        <comment>Fix concepts created in liquibase without uuid</comment>
        <sql>
            select concept_id into @concept_id from concept_name where name = 'Tablet' and concept_name_type = 'FULLY_SPECIFIED';
            SELECT uuid() into @uuid;
            UPDATE concept set uuid = @uuid where concept_id = @concept_id;

            select concept_id into @concept_id from concept_name where name = 'Capsule' and concept_name_type = 'FULLY_SPECIFIED';
            SELECT uuid() into @uuid;
            UPDATE concept set uuid = @uuid where concept_id = @concept_id;

            select concept_id into @concept_id from concept_name where name = 'Topical' and concept_name_type = 'FULLY_SPECIFIED';
            SELECT uuid() into @uuid;
            UPDATE concept set uuid = @uuid where concept_id = @concept_id;

            select concept_id into @concept_id from concept_name where name = 'Nasal' and concept_name_type = 'FULLY_SPECIFIED';
            SELECT uuid() into @uuid;
            UPDATE concept set uuid = @uuid where concept_id = @concept_id;

            select concept_id into @concept_id from concept_name where name = 'Inhalation' and concept_name_type = 'FULLY_SPECIFIED';
            SELECT uuid() into @uuid;
            UPDATE concept set uuid = @uuid where concept_id = @concept_id;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201412031050" author="Swathi">
        <validCheckSum>3:d1ca4fa7639c189ed9602242e4f2bd0e</validCheckSum>
        <comment></comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @uuid = 0;
            set @now = now();

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Five times a day', '', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 5, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Four days a week', '', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 4/7, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Five days a week', '', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 5/7, 1, @now, @uuid);

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Six days a week', '', 'N/A', 'Frequency', false);
            select uuid() into @uuid;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 6/7, 1, @now, @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201412132014" author="Mihir">
        <comment>Adding Immediately as Order Frequency</comment>
        <sql>
            set @concept_id = 0;
            set @uuid = 0;
            set @now = now();
            select concept_id from concept_name where name='Immediately' and concept_name_type='FULLY_SPECIFIED' into @concept_id;
            insert into order_frequency(concept_id, frequency_per_day, creator, date_created, uuid) values(@concept_id, 1, 1, @now, @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201412051745" author="Rohan">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Computed/Editable';
            </sqlCheck>
        </preConditions>
        <comment>Add concept class Computed/Editable</comment>
        <sql>
            set @uuid = '';
            set @date = '';
            select uuid() into @uuid;
            select curdate() into @date;
            select @uuid;
            insert into concept_class (name, description, creator, date_created, retired, uuid)
            values ('Computed/Editable', 'Computed/Editable', 1, @date, 0, @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201412171832" author="Mujir, Mihir">
        <validCheckSum>3:ff3f26723a22f34131d082f64923f708</validCheckSum>
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(*) from concept_name where name='Admission' and concept_name_type='FULLY_SPECIFIED';
            </sqlCheck>
        </preConditions>
        <comment>Adding Admission Decision concept reference term and mapping for close visit task</comment>
        <sql>
            set @concept_id = 0;
            set @concept_map_type_id = 0;
            set @concept_reference_term_id = 0;

            set @uuid = 0;
            set @emr_source_id = 0;
            set @current_date = 0;

            select uuid() into @uuid;
            select now() into @current_date;
            select concept_source_id from concept_reference_source where name='org.openmrs.module.emrapi' into @emr_source_id;

            insert into concept_reference_term(concept_source_id, name, code, description, creator, date_created, uuid)
            values(@emr_source_id, 'Admission Decision', 'Admission Decision', '', 1, @current_date, @uuid);

            select concept_reference_term_id from concept_reference_term where name='Admission Decision' into @concept_reference_term_id;
            select concept_map_type_id from concept_map_type where name='SAME-AS' into @concept_map_type_id;
            select concept_id from concept_name where name='Admission' and concept_name_type='FULLY_SPECIFIED' into @concept_id;

            select uuid() into @uuid;
            insert into concept_reference_map (concept_reference_term_id, concept_map_type_id, concept_id, date_created, creator, uuid) values (
            @concept_reference_term_id , @concept_map_type_id, @concept_id, @current_date, 1, @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201412171835" author="Mujir, Mihir">
        <validCheckSum>3:8dab05861bd023ac8ce19d56224d6576</validCheckSum>
        <validCheckSum>3:ba27b100100f1dc0f5d2d0afdf9d29e9</validCheckSum>
        <comment>Adding Deny Admission concept reference term and mapping for close visit task</comment>
        <sql>
            set @concept_id = 0;
            set @concept_map_type_id = 0;
            set @concept_reference_term_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;

            set @uuid = 0;
            set @emr_source_id = 0;
            set @current_date = 0;

            select uuid() into @uuid;
            select now() into @current_date;
            select concept_source_id from concept_reference_source where name='org.openmrs.module.emrapi' into @emr_source_id;

            insert into concept_reference_term(concept_source_id, name, code, description, creator, date_created, uuid)
            values(@emr_source_id, 'Deny Admission', 'Deny Admission', 'Deny Admission', 1, @current_date, @uuid);

            select concept_reference_term_id from concept_reference_term where name='Deny Admission' into @concept_reference_term_id;
            select concept_map_type_id from concept_map_type where name='SAME-AS' into @concept_map_type_id;

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Deny Admission','Deny Admission', 'N/A', 'Misc', false);

            select uuid() into @uuid;
            insert into concept_reference_map (concept_reference_term_id, concept_map_type_id, concept_id, date_created, creator, uuid) values (
            @concept_reference_term_id , @concept_map_type_id, @concept_id, @current_date, 1, @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201412181423" author="Rohan">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM global_property where property = 'encounterModifier.groovy.allowCaching'
            </sqlCheck>
        </preConditions>
        <comment>Set global property allow_groovy_caching to true</comment>
        <sql>
            INSERT INTO global_property(`property`, `property_value`, `description`, `uuid`)
            VALUES ('encounterModifier.groovy.allowCaching', 'true', 'Allow Groovy Caching', 'e16605a1-266a-47cb-8385-d07742646640');
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201412311031" author="Mihir">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM location_tag where name='Login Location';
            </sqlCheck>
        </preConditions>
        <comment>Add Login Location Tag if not already added.</comment>
        <sql>
            set @current_date = 0;
            select now() into @current_date;

            INSERT INTO location_tag (name, description, creator, date_created, uuid) VALUES
            ('Login Location',
            'When a user logs in and chooses a session location, they may only choose one with this tag',
            1,
            @current_date,
            'b8bbf83e-645f-451f-8efe-a0db56f09676');
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201501071717" author="Vikash,Indraneel">
        <validCheckSum>3:f9ed5a94595e1affa2778dce8f39f6a8</validCheckSum>
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_name where name='Order Attributes' and concept_name_type='FULLY_SPECIFIED' and voided=0;
            </sqlCheck>
        </preConditions>
        <comment>Adding Order Attributes concept set</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,'Order Attributes','Order Attributes', 'N/A', 'Misc', true);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201501192149" author="Sravanthi">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Case Intake';
            </sqlCheck>
        </preConditions>
        <comment>add concept class Case Intake</comment>
        <insert tableName="concept_class">
            <column name="name" value="Case Intake"/>
            <column name="description" value="Case Intake class"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="retired" value="0"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-clinical-retrospective-201501221417" author="Vikash, Sravanthi">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'app:clinical:retrospective'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="app:clinical:retrospective"/>
            <column name="description" value="Bahmni clinical app retrospective access privilege"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-clinical-201502091501" author="Charles, Banka">
        <validCheckSum>3:83d50d47fd5091b289483c66a54e3ac9</validCheckSum>
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from concept_name where name = 'Undo Discharge'  and concept_name_type='FULLY_SPECIFIED'</sqlCheck>
        </preConditions>
        <comment>Adding Undo Discharge disposition</comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @concept_source_id = 0;
            set @concept_map_type_id = 0;
            set @disposition_concept_id = 0;

            SELECT concept_source_id INTO @concept_source_id FROM concept_reference_source where name = 'org.openmrs.module.emrapi';
            SELECT concept_id INTO @disposition_concept_id FROM concept_name where name = 'Disposition' and concept_name_type='FULLY_SPECIFIED';
            SELECT concept_map_type_id INTO @concept_map_type_id FROM concept_map_type where name = 'SAME-AS';


            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Undo Discharge', 'Undo Discharge', 'N/A', 'misc', false);
            call add_concept_reference_map (@concept_id, @concept_source_id, 'UNDO_DISCHARGE',@concept_map_type_id);
            set @child1_concept_id = @concept_id;

            call add_concept_answer(@disposition_concept_id, @child1_concept_id, 3);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201503101702" author="Sravanthi, Charles" context="rel3" runOnChange="true">
        <comment>Sql file for getting all wards, beds and related patients info</comment>
        <sqlFile path="V1_86__WardsListSql.sql"/>
    </changeSet>
    <changeSet id="bahmni-core-201503270552" author="Sandeep, Hemanth">
        <comment>Adding privilege for dispensing drug orders.</comment>
        <insert tableName="privilege">
            <column name="privilege" value="bahmni:clinical:dispense"/>
            <column name="description" value="Bahmni drug order dispensing privilege"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201503270603" author="Sandeep, Hemanth">
        <validCheckSum>3:9dc0f97f859e8d26392fb7dbb48e980d</validCheckSum>
        <comment>Adding dispensed drug order attribute</comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @set_concept_id = 0;

            select concept_id from concept_name where name = 'Order Attributes' and concept_name_type = 'FULLY_SPECIFIED' into @set_concept_id;

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Dispensed', 'D', 'Boolean', 'Misc', false);

            call add_concept_set_members(@set_concept_id,@concept_id,1);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201504031424" author="Banka, Preethi">
        <comment>Chaning colume type of property_value in user_property to text</comment>
        <sql>
            alter table user_property modify property_value text
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201504061124" author="Charles, Swathi">
        <comment>Adding privilege for bi-directional navigation between registration and consultation.</comment>
        <insert tableName="privilege">
            <column name="privilege" value="app:common:registration_consultation_link"/>
            <column name="description" value="Adding Registration to/from Consultation Link"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201504070220" author="Preethi, Hemanth">
        <comment>Creating Visit Status as visit attribute</comment>
        <sql>
            INSERT INTO visit_attribute_type (name, datatype, creator, date_created, uuid, min_occurs)
            VALUES ('Visit Status', 'org.openmrs.customdatatype.datatype.FreeTextDatatype', 1, now(), uuid(), 0);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201504131627" author="Soumya, Charles">
        <comment>Adding Close Visit Privilege</comment>
        <insert tableName="privilege">
            <column name="privilege" value="app:common:closeVisit"/>
            <column name="description" value="Adding close visit privilege"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201504231857" author="Charles, JP">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'app:orders'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="app:orders"/>
            <column name="description" value="Bahmni Orders App Access Privilege"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201505081250" author="JP">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'app:clinical:deleteDiagnosis'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
                <column name="privilege" value="app:clinical:deleteDiagnosis"/>
            <column name="description" value="Bahmni delete diagnosis privilege"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201505080200" author="Hemanth">
        <comment>Creating Admission Status as visit attribute</comment>
        <sql>
            INSERT INTO visit_attribute_type (name, datatype, creator, date_created, uuid, min_occurs)
            VALUES ('Admission Status', 'org.openmrs.customdatatype.datatype.FreeTextDatatype', 1, now(), uuid(), 0);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201505121055" author="Vikash, Achinta">
        <comment>Adding privilege for provider.</comment>
        <insert tableName="privilege">
            <column name="privilege" value="app:clinical:grantProviderAccess"/>
            <column name="description" value="Bahmni clinical app grant access for other Provider"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-core-201505171743" author="Bharat">
        <comment>Associating LabSet and LabTest concept classes to Lab Order order type</comment>
        <sql>
            set @order_type_id = '';
            set @lab_set = '';
            set @lab_test = '';

            select order_type_id into @order_type_id from order_type where name = 'Lab Order';
            select concept_class_id into @lab_set from concept_class where name = 'LabSet';
            select concept_class_id into @lab_test from concept_class where name = 'LabTest';
            insert into order_type_class_map(order_type_id, concept_class_id) values(@order_type_id,@lab_set);
            insert into order_type_class_map(order_type_id, concept_class_id) values(@order_type_id,@lab_test);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201505171755" author="Bharat">
        <validCheckSum>3:24754f616857125b862150154fb85150</validCheckSum>
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                select count(*) from concept_name where name='All Orderables' and concept_name_type='FULLY_SPECIFIED';
            </sqlCheck>
        </preConditions>
        <comment>Adding 'All Orderables' concept set and associating Lab Samples to it.</comment>
        <sql>
            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'All Orderables', 'All Orderables', 'N/A', 'ConvSet', true);

            select concept_id into @labsamples_concept_id from concept_name where name = 'Lab Samples' and concept_name_type = 'FULLY_SPECIFIED';
            call add_concept_set_members (@concept_id,@labsamples_concept_id,1);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201505171808" author="Bharat">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                select count(*) from concept_name where name='Lab Orders' and concept_name_type='SHORT' and voided=0;
            </sqlCheck>
        </preConditions>
        <comment>Adding a display name for Lab Samples concept on UI </comment>
        <sql>
            select concept_id into @labsamples_concept_id from concept_name where name like 'Lab Samples' and concept_name_type = 'FULLY_SPECIFIED';

            insert into concept_name (concept_id, name, locale, locale_preferred, creator, date_created,concept_name_type, voided, uuid) values (@labsamples_concept_id,'Lab Orders', 'en', 0, 1, now(), 'SHORT', 0, uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201505251642" author="Ranganathan">
        <validCheckSum>3:b92570973c3eb23083225d3dd889d0f9</validCheckSum>
        <comment>Adding gender values and codes used across MRS</comment>
        <sql>
            select uuid() into @uuid;
            INSERT INTO global_property(property, property_value, description, uuid)
            VALUES('mrs.genders', '{"M":"Male", "F":"Female","O":"Other"}', 'List of gender and gender codes used across MRS', @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmniconfig-201505252028" author="Mihir">
        <preConditions onFail="MARK_RAN">
            <not><tableExists tableName="bahmni_config"/></not>
        </preConditions>
        <createTable tableName="bahmni_config">
            <column autoIncrement="true" name="config_id" type="int"> <constraints nullable="false" primaryKey="true"/> </column>
            <column name="config_name" type="varchar(255)"> <constraints nullable="false"/> </column>
            <column name="app_name" type="varchar(255)"> <constraints nullable="false"/> </column>
            <column name="config" type="longtext"> <constraints nullable="false"/> </column>
            <column name="creator" type="int"> <constraints nullable="false"/> </column>
            <column name="date_created" type="DATETIME"> <constraints nullable="false"/> </column>
            <column name="changed_by" type="int"/>
            <column name="date_changed" type="DATETIME"/>
            <column name="uuid" type="char(38)" />
        </createTable>
        <addForeignKeyConstraint constraintName="bahmni_config_creator_fk"
                                 baseTableName="bahmni_config" baseColumnNames="creator"
                                 referencedTableName="users" referencedColumnNames="user_id" />
        <addForeignKeyConstraint constraintName="bahmni_config_changed_by_fk"
                                 baseTableName="bahmni_config" baseColumnNames="changed_by"
                                 referencedTableName="users" referencedColumnNames="user_id" />
        <addUniqueConstraint columnNames="config_name, app_name"
                             constraintName="bahmni_config_unique_app_config_name"
                             tableName="bahmni_config"/>
        <addUniqueConstraint columnNames="uuid"
                             constraintName="bahmni_config_unique_uuid"
                             tableName="bahmni_config"/>
    </changeSet>
    <changeSet id="bahmniconfig-201505252128" author="Mihir">
        <preConditions onFail="MARK_RAN">
            <not><tableExists tableName="bahmni_config_version"/></not>
        </preConditions>
        <createTable tableName="bahmni_config_version">
            <column autoIncrement="true" name="config_version_id" type="int"> <constraints nullable="false" primaryKey="true"/> </column>
            <column name="config_uuid" type="char(38)"> <constraints nullable="false"/> </column>
            <column name="config_diff" type="BLOB"><constraints nullable="false"/> </column>
            <column name="date_created" type="DATETIME"> <constraints nullable="false"/> </column>
            <column name="version_name" type="VARCHAR(255)"> <constraints nullable="false"/> </column>
            <column name="uuid" type="char(38)" />
        </createTable>
        <addForeignKeyConstraint constraintName="bahmni_config_uuid_fk"
                                 baseTableName="bahmni_config_version" baseColumnNames="config_uuid"
                                 referencedTableName="bahmni_config" referencedColumnNames="uuid" />
        <addUniqueConstraint columnNames="version_name"
                             constraintName="bahmni_config_unique_version_name"
                             tableName="bahmni_config_version"/>
        <addUniqueConstraint columnNames="uuid"
                             constraintName="bahmni_config_version_unique_uuid"
                             tableName="bahmni_config_version"/>
    </changeSet>
    <changeSet id="bahmni-core-201506011729" author="Preethi, Gautam">
        <comment>Changing short name for Lab Samples concept on UI </comment>
        <sql>
            select concept_id into @labsamples_concept_id from concept_name where name like 'Lab Samples' and concept_name_type = 'FULLY_SPECIFIED';

            update concept_name set name = 'Laboratory' where concept_id = @labsamples_concept_id and concept_name_type = 'SHORT';
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201506011804" author="Preethi, Gautam">
        <comment>Changing description for LabSet concept class to Panels</comment>
        <sql>
            update concept_class set description = 'Panels' where name = 'LabSet';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201506180200" author="Chethan, Preethi">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM global_property where property = 'bahmni.encounterType.default'
            </sqlCheck>
        </preConditions>
        <comment>Global property for default encounter type.</comment>
        <sql>
            insert into global_property (`property`, `property_value`, `description`, `uuid`)
            values ('bahmni.encounterType.default',
            'Consultation',
            'Default Encounter Type',
            uuid()
            );
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201506221230" author="Hemanth, Preethi">
        <comment>Getting rid of the revese sync schedulers for Drug.</comment>
        <sql>
            delete from scheduler_task_config where name='OpenERP Feed Task';
            delete from scheduler_task_config where name='OpenERP Failed Feed Task';
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201506251230" author="Ranganathan, Charles">
        <comment>Cleaning up relationships types for the relationships.</comment>
        <sql>
            SET FOREIGN_KEY_CHECKS = 0;
            truncate relationship_type;
            SET FOREIGN_KEY_CHECKS = 1;
        </sql>
    </changeSet>

    <changeSet id="bahmni-PatientSearch-Update-201507031840" author="Vikash, Achinta" context="rel3">
        <comment>rel3</comment>
        <sqlFile path="V1_87_PatientSearchSql.sql"/>
    </changeSet>

    <changeSet id="bahmni-PatientSearch-Update-201507071330" author="Vikash, Chethan" context="rel3">
        <comment>rel3</comment>
        <sqlFile path="V1_88_PatientSearchSql.sql"/>
    </changeSet>

    <changeSet id="bahmni-core-201507161455" author="Abishek, Vikash">
        <comment>Moving to order from test_order</comment>
        <sql>
            UPDATE `order_type` SET `java_class_name` = 'org.openmrs.Order' WHERE name ='Lab Order';
            UPDATE `order_type` SET `java_class_name` = 'org.openmrs.Order' WHERE name ='Radiology Order';
            UPDATE `order_type` SET `name` = 'Order' WHERE name ='Lab Order';
            DELETE FROM `test_order`;
        </sql>
    </changeSet>


    <changeSet id="bahmni-PatientSearch-Update-201507161455" author="Abishek" context="rel3">
        <comment>Updating sql to use order instead of lab order as order type name</comment>
        <sqlFile path="V1_89_PatientSearchSql.sql"/>
    </changeSet>

    <changeSet id="bahmni-core-201507161455" author="Abishek">
        <comment>Associating LabSet and LabTest concept classes to Order order type</comment>
        <sql>
            set @order_type_id = '';
            set @lab_set = '';
            set @lab_test = '';

            delete from order_type_class_map;
            select order_type_id into @order_type_id from order_type where name = 'Order';
            select concept_class_id into @lab_set from concept_class where name = 'LabSet';
            select concept_class_id into @lab_test from concept_class where name = 'LabTest';
            insert into order_type_class_map(order_type_id, concept_class_id) values(@order_type_id,@lab_set);
            insert into order_type_class_map(order_type_id, concept_class_id) values(@order_type_id,@lab_test);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201507271600" author="Swathi, Charles" context="rel4">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM person_attribute_type where name = 'Telephone Number';
            </sqlCheck>
        </preConditions>
        <comment>Adding Telephone Number person attribute type</comment>
        <sql>
            INSERT INTO person_attribute_type (name, description, format, searchable, creator, date_created, retired, sort_weight, uuid) VALUES ('Telephone Number', 'Telephone Number', 'java.lang.String', '0', 1, now(), 0, 3, uuid());
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201507271605" author="Swathi, Charles" context="rel4">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM person_attribute_type where name = 'Unknown patient';
            </sqlCheck>
        </preConditions>
        <comment>Adding Unknown patient person attribute type</comment>
        <sql>
            INSERT INTO person_attribute_type (name, description, format, searchable, creator, date_created, retired, sort_weight, uuid) VALUES ('Unknown patient', 'Unknown Patient', 'java.lang.String', '0', 1, now(), 0, 3, uuid());
        </sql>
    </changeSet>

    <changeSet id="bahmni-PatientSearch-Update-201507271745" author="JP, Sravanthi" context="rel3">
        <comment>Updating high risk patient sql to consider latest test value</comment>
        <sqlFile path="V1_90_PatientSearchSql.sql"/>
    </changeSet>

    <changeSet id="bahmni-core-201507311820" author="Hemanth" context="rel3">
        <comment>Optimised the high risk patient sql to consider latest test value</comment>
        <sqlFile path="V1_91_PatientSearchSql.sql"/>
    </changeSet>

    <changeSet id="bahmni-core-201508180000" author="Banka, Swathi">
        <comment>Changing the OrderType name for lab order from Order to Lab Order</comment>
        <sql>
            UPDATE `order_type` SET `name` = 'Lab Order' WHERE name ='Order';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201508181421" author="Padma, Shireesha">
        <comment>Adding global property for Reason for death</comment>
        <sql>
            insert into global_property
            (`property`,
            `property_value`,
            `description`,
            `uuid`)
            values
            ('concept.reasonForDeath',
            '',
            'Concept id of the REASON FOR DEATH Concept Set',
            uuid())
            ON DUPLICATE KEY UPDATE
            `property_value`=@concept_set_uuid;
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201508211600" author="Vikash, Abishek">
        <comment>Updating column stage_name of import_status table </comment>
        <sql>
            ALTER TABLE import_status MODIFY stage_name varchar(30);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201508310334" author="Padma">
        <comment>Deleting bahmnicore.relationshipTypeMap from global property</comment>
        <sql>
            delete ignore from global_property where property='bahmnicore.relationshipTypeMap';
        </sql>
    </changeSet>


    <changeSet id="bahmni-mapping-201508200613" author="Gautham, Sudhakar" context="rel0.75">
        <comment>Entity mapping table</comment>
        <createTable tableName="entity_mapping_type">
            <column autoIncrement="true" name="id" type="int"><constraints nullable="false" primaryKey="true"/></column>
            <column name="name" type="varchar(100)"><constraints nullable="false"/></column>
            <column name="uuid" type="char(38)"><constraints nullable="false"/></column>
            <column name="entity1_type" type="text"><constraints nullable="false"/></column>
            <column name="entity2_type" type="text"><constraints nullable="false"/></column>
            <column name="date_created" type="DATETIME"> <constraints nullable="false"/> </column>
        </createTable>
        <createTable tableName="entity_mapping">
            <column autoIncrement="true" name="id" type="int"> <constraints nullable="false" primaryKey="true"/> </column>
            <column name="uuid" type="char(38)"><constraints nullable="false"/></column>
            <column name="entity_mapping_type_id" type="int"> <constraints nullable="false"/> </column>
            <column name="entity1_uuid" type="char(38)"> <constraints nullable="false"/> </column>
            <column name="entity2_uuid" type="char(38)"> <constraints nullable="false"/> </column>
            <column name="date_created" type="DATETIME"> <constraints nullable="false"/> </column>
        </createTable>
        <addForeignKeyConstraint constraintName="entity_mapping_entity_mapping_type_fk"
                                 baseTableName="entity_mapping" baseColumnNames="entity_mapping_type_id"
                                 referencedTableName="entity_mapping_type" referencedColumnNames="id" />
    </changeSet>

    <changeSet id="bahmni-mapping-201508271719" author="Gautam, Shan" context="rel0.75">
        <comment>Inserting Program Obstemplate Mapping type</comment>
        <insert tableName="entity_mapping_type">
            <column name="name" value="program_obstemplate"/>
            <column name="uuid" valueComputed="uuid()"/>
            <column name="entity1_type" value="org.openmrs.Program"></column>
            <column name="entity2_type" value="org.openmrs.Concept"></column>
            <column name="date_created" valueComputed="now()"></column>
        </insert>
    </changeSet>

    <changeSet id="bahmni-mapping-201508271736" author="Shan, Gautam" context="rel0.75">
        <comment>Introducing constraint unique key to name column in the entity_mapping_type table</comment>
        <addUniqueConstraint constraintName="unique_entity_mapping_type_name"
                             columnNames="name"
                             tableName="entity_mapping_type"/>
    </changeSet>

    <changeSet id="bahmni-mapping-201509021719" author="Shruthi, Padma" context="rel0.76">
        <comment>Inserting Program EncounterType Mapping</comment>
        <insert tableName="entity_mapping_type">
            <column name="name" value="program_encountertype"/>
            <column name="uuid" valueComputed="uuid()"/>
            <column name="entity1_type" value="org.openmrs.Program"></column>
            <column name="entity2_type" value="org.openmrs.EncounterType"></column>
            <column name="date_created" valueComputed="now()"></column>
        </insert>
    </changeSet>

    <changeSet id="bahmni-core-201509231746" author="Swathi, Jaswanth" context="rel0.76">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM person_attribute_type WHERE name = 'Telephone Number'
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM person_attribute JOIN person_attribute_type ON person_attribute.person_attribute_type_id = person_attribute_type.person_attribute_type_id where name = 'Telephone Number'
            </sqlCheck>
        </preConditions>
        <comment>Deleting Telephone Number person attribute type</comment>
        <sql>
            DELETE FROM person_attribute_type WHERE name = 'Telephone Number';
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201509231749" author="Swathi, Jaswanth" context="rel0.76">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM person_attribute_type WHERE name = 'Unknown patient'
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM person_attribute JOIN person_attribute_type ON person_attribute.person_attribute_type_id = person_attribute_type.person_attribute_type_id where name = 'Unknown patient'
            </sqlCheck>
        </preConditions>
        <comment>Deleting Unknown patient person attribute type</comment>
        <sql>
            DELETE FROM person_attribute_type WHERE name = 'Unknown patient';
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201509301203" author="Chethan, Sourav" context="rel0.76">
        <sql>
            set @concept_source_id = 0;
            set @concept_reference_term_id = 0;
            set @set_concept_id = 0;
            set @bahmni_initial_diagnosis_concept_id = 0;
            set @bahmni_diagnosis_revised_concept_id = 0;
            set @bahmni_diagnosis_status_concept_id = 0;

            select concept_source_id into @concept_source_id from concept_reference_source where name = "org.openmrs.module.emrapi";

            select concept_reference_term_id into @concept_reference_term_id from concept_reference_term where code = 'Diagnosis Concept Set' and concept_source_id = @concept_source_id;

            select concept_id into @set_concept_id from concept_reference_map where concept_reference_term_id = @concept_reference_term_id;

            select concept_id into @bahmni_initial_diagnosis_concept_id from concept_name where name = 'Bahmni Initial Diagnosis' and concept_name_type='FULLY_SPECIFIED' ;

            select concept_id into @bahmni_diagnosis_revised_concept_id from concept_name where name = 'Bahmni Diagnosis Revised' and concept_name_type='FULLY_SPECIFIED';

            select concept_id into @bahmni_diagnosis_status_concept_id from concept_name where name = 'Bahmni Diagnosis Status' and concept_name_type='FULLY_SPECIFIED';

            call add_concept_set_members (@set_concept_id,@bahmni_initial_diagnosis_concept_id,1);
            call add_concept_set_members (@set_concept_id,@bahmni_diagnosis_revised_concept_id,1);
            call add_concept_set_members (@set_concept_id,@bahmni_diagnosis_status_concept_id,1);

        </sql>
    </changeSet>

    <changeSet id="bahmni-atomfeed-add-event-records-category-index" author="Achinta, Sudhakar" context="rel0.75">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_NAME = 'event_records' AND INDEX_NAME = 'event_records_category_idx'
            </sqlCheck>
        </preConditions>
        <comment>Add index to the category column in event_records table for performance (if it is not already present)</comment>
        <createIndex tableName="event_records" indexName="event_records_category_idx">
            <column name="category"/>
        </createIndex>
    </changeSet>

    <changeSet id="bahmni-reg-201401171330" author="banka-tw" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'app:registration'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="app:registration"/>
            <column name="description" value="Bahmni registration app access privilege"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>

    <changeSet id="bahmni-reg-201402141455" author="neha" context="rel3">
        <comment>Add emrgency app role</comment>
        <sql>
            INSERT INTO privilege(privilege, description, uuid) VALUES('app:emergency', 'bahmni emergency app access privilege', uuid()) ON DUPLICATE KEY UPDATE privilege = 'app:emergency';
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201510161510" author="Vikash, Shashi" context="rel0.77">
        <comment>Add relationship between orderType and conceptClass</comment>
        <sql>
            insert into order_type_class_map values((select order_type_id from order_type where name='Drug Order'), (select concept_class_id from concept_class where name='Drug'));
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201510271500" author="Shan, Sourav" context="rel0.77">
        <comment>SQL query to get list of active patients by location</comment>
        <sqlFile path="V1_92_PatientSearch.sql"/>
    </changeSet>

    <changeSet id="bahmni-core-201510291400" author="Shan" context="rel0.77">
        <comment>Remove the SQL query to get list of active patients by location</comment>
        <sql>
            DELETE FROM global_property WHERE property IN ('emrapi.sqlSearch.activePatientsByLocation');
        </sql>
    </changeSet>

    <changeSet id="bahmni-reg-1" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile path="V1_11__CreateConceptSetForRegistrationConcepts.sql" />
    </changeSet>

    <changeSet id="bahmni-reg-3" author="tw" context="rel2">
        <comment>rel2</comment>
        <sqlFile path="V1_25__RegistrationConceptSetFix.sql" />
    </changeSet>

    <changeSet id="bahmni-reg-4" author="tw" context="rel3">
        <comment>rel3</comment>
        <sqlFile path="V1_79__AddressTemplateWithAllFields.sql" />
    </changeSet>

    <changeSet id="bahmni-reg-5" author="vivek-tw" context="rel3">
        <comment>rel3</comment>
        <sql>update patient_identifier_type set name = 'Bahmni Id' where name = 'JSS'</sql>
    </changeSet>

    <changeSet id="bahmni-core-201511180200" author="Swathi">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                select count(*) from concept where concept_id in (select concept_id from concept_name where name='DrugOther' and concept_name_type='FULLY_SPECIFIED')
            </sqlCheck>
        </preConditions>
        <comment>Adding 'DrugOther' concept.</comment>
        <sql>
            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'DrugOther', 'DrugOther', 'N/A', 'Misc', false);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201511251218" author="Jaya, Sravanthi">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM global_property where property = 'drugOrder.drugOther'
            </sqlCheck>
        </preConditions>
        <comment>Add drug other global property</comment>
        <sql>
            insert into global_property (property, property_value, description, uuid)
            values ('drugOrder.drugOther', '', 'Specifies the uuid of the concept which represents drug other non coded', uuid());
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201511180201" author="Swathi">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">select count(*) from global_property where property='drugOrder.drugOther'</sqlCheck>
        </preConditions>
        <comment>Setting 'DrugOther' concept uuid as value for 'drugOrder.drugOther' globalProperty.</comment>
        <sql>
            select uuid into @uuid from concept where concept_id in (select concept_id from concept_name where name='DrugOther' and concept_name_type='FULLY_SPECIFIED');
            UPDATE global_property set property_value = @uuid where property='drugOrder.drugOther';
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201511181738" author="Padma">
        <preConditions onFail="CONTINUE">
            <sqlCheck expectedResult="1">select count(*) from global_property where property='concept.reasonForDeath'</sqlCheck>
        </preConditions>
        <comment>Changing description for reason for death global property</comment>
        <sql>
            UPDATE global_property set description='Fully Specified name of the Concept Set created as Reasons for death' where property='concept.reasonForDeath';
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201511180931" author="Vinay">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='app:reports'</sqlCheck>
        </preConditions>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('app:reports', 'View Reports', @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201511250237" author="Hanisha">
        <comment>Adding new loginLocationToVisitTypeMapping in entityMappingType table</comment>
        <sql>
            insert into entity_mapping_type(name ,uuid ,entity1_type , entity2_type , date_created) values('loginlocation_visittype', uuid() , 'org.openmrs.Location' , 'org.openmrs.VisitType' , '2015-11-25 18:54:23.0');
        </sql>
    </changeSet>
    <changeSet id="bahmni-clinical-201511251240" author="Shireesha">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from concept_name where name in ('Stopped Order Reason','Refused To Take')  and concept_name_type='FULLY_SPECIFIED'</sqlCheck>
        </preConditions>
        <comment>Adding Stopped Order Reason and answers</comment>
        <sql>
            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @stopped_order_reason_concept_id = 0;


            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Stopped Order Reason', 'Stopped Order Reason', 'Coded', 'Question', false);

            select concept_id into @stopped_order_reason_concept_id from concept_name where name = 'Stopped Order Reason' and concept_name_type = 'FULLY_SPECIFIED';

            set @concept_id = 0;
            set @concept_name_short_id = 0;
            set @concept_name_full_id = 0;
            set @refused_to_take_concept_id = 0;

            call add_concept(@concept_id, @concept_name_short_id, @concept_name_full_id, 'Refused To Take', 'Refused To Take', 'N/A', 'Misc', false);
            select concept_id into @refused_to_take_concept_id from concept_name where name = 'Refused To Take' and concept_name_type = 'FULLY_SPECIFIED';
            call add_concept_answer(@stopped_order_reason_concept_id, @refused_to_take_concept_id, 1);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201412281000" author="Santhosh">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from concept_reference_source where name='Abbreviation'</sqlCheck>
        </preConditions>
        <comment>Insert concept reference source for Abbreviation</comment>
        <sql>
            set @uuid = 0;
            select uuid() into @uuid;

            insert into concept_reference_source (name, description, hl7_code, creator, date_created, uuid)
            values('Abbreviation', 'Custom dictionary for storing abbreviation of concepts', null, 1, now(), @uuid);
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201512291400" author="Shashi, Hanisha">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Unknown';
            </sqlCheck>
        </preConditions>
        <comment>add concept class Unknown</comment>
        <insert tableName="concept_class">
            <column name="name" value="Unknown"/>
            <column name="description" value="Unknown class"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="retired" value="0"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>

    <changeSet id="bahmni-clinical-201601111633" author="Sourav,Preethi" context="rel4">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from entity_mapping_type where name='location_encountertype'</sqlCheck>
        </preConditions>
        <comment>Add entity mapping type for location_encountertype</comment>
        <sql>
            insert into entity_mapping_type (name, uuid, entity1_type, entity2_type, date_created)
            values ('location_encountertype', uuid(), "org.openmrs.Location", "org.openmrs.EncounterType", now());
        </sql>

    </changeSet>
    <changeSet id="20151218-1530-create-program_attribute_type-table" author="Rahul,Swathi" dbms="mysql">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="program_attribute_type" />
            </not>
        </preConditions>
        <comment>Creating program_attribute_type table</comment>
        <createTable tableName="program_attribute_type">
            <column name="program_attribute_type_id" type="int" autoIncrement="true">
                <constraints primaryKey="true" nullable="false" />
            </column>
            <column name="name" type="varchar(255)">
                <constraints nullable="false"  unique="true"/>
            </column>
            <column name="description" type="varchar(1024)" />
            <column name="datatype" type="varchar(255)" />
            <column name="datatype_config" type="text" />
            <column name="preferred_handler" type="varchar(255)" />
            <column name="handler_config" type="text" />
            <column name="min_occurs" type="int">
                <constraints nullable="false" />
            </column>
            <column name="max_occurs" type="int"></column>
            <column name="creator" type="int">
                <constraints nullable="false" />
            </column>
            <column name="date_created" type="datetime">
                <constraints nullable="false" />
            </column>
            <column name="changed_by" type="int" />
            <column name="date_changed" type="datetime" />
            <column name="retired" type="smallint" defaultValueNumeric="0">
                <constraints nullable="false" />
            </column>
            <column name="retired_by" type="int(11)" />
            <column name="date_retired" type="datetime" />
            <column name="retire_reason" type="varchar(255)" defaultValue="null" />
            <column name="uuid" type="char(38)">
                <constraints nullable="false" unique="true" />
            </column>
        </createTable>
        <addForeignKeyConstraint constraintName="program_attribute_type_creator_fk"
                                 baseTableName="program_attribute_type" baseColumnNames="creator"
                                 referencedTableName="users" referencedColumnNames="user_id" />
        <addForeignKeyConstraint constraintName="program_attribute_type_changed_by_fk"
                                 baseTableName="program_attribute_type" baseColumnNames="changed_by"
                                 referencedTableName="users" referencedColumnNames="user_id" />
        <addForeignKeyConstraint constraintName="program_attribute_type_retired_by_fk"
                                 baseTableName="program_attribute_type" baseColumnNames="retired_by"
                                 referencedTableName="users" referencedColumnNames="user_id" />
    </changeSet>
    <changeSet id="20151218-1530" author="Rahul,Swathi">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="patient_program_attribute" />
            </not>
        </preConditions>
        <createTable tableName="patient_program_attribute">
            <column name="patient_program_attribute_id" type="int" autoIncrement="true">
                <constraints primaryKey="true" nullable="false" />
            </column>
            <column name="patient_program_id" type="int"><constraints nullable="false" /></column>
            <column name="attribute_type_id" type="int"><constraints nullable="false" /></column>
            <column name="value_reference" type="text"><constraints nullable="false" /></column>
            <column name="uuid" type="char(38)"><constraints nullable="false" unique="true" /></column>
            <column name="creator" type="int"><constraints nullable="false"/></column>
            <column name="date_created" type="datetime"><constraints nullable="false"/></column>
            <column name="changed_by" type="int"/>
            <column name="date_changed" type="datetime" />
            <column name="voided" type="boolean" defaultValueBoolean="false">
                <constraints nullable="false"/>
            </column>
            <column name="voided_by" type="int" />
            <column name="date_voided" type="datetime" />
            <column name="void_reason" type="varchar(255)" defaultValue="null"/>
        </createTable>
        <addForeignKeyConstraint constraintName="patient_program_attribute_programid_fk"
                                 baseTableName="patient_program_attribute" baseColumnNames="patient_program_id"
                                 referencedTableName="patient_program" referencedColumnNames="patient_program_id" />
        <addForeignKeyConstraint constraintName="patient_program_attribute_attributetype_fk"
                                 baseTableName="patient_program_attribute" baseColumnNames="attribute_type_id"
                                 referencedTableName="program_attribute_type" referencedColumnNames="program_attribute_type_id" />
        <addForeignKeyConstraint constraintName="patient_program_attribute_creator_fk"
                                 baseTableName="patient_program_attribute" baseColumnNames="creator"
                                 referencedTableName="users" referencedColumnNames="user_id" />
        <addForeignKeyConstraint constraintName="patient_program_attribute_changed_by_fk"
                                 baseTableName="patient_program_attribute" baseColumnNames="changed_by"
                                 referencedTableName="users" referencedColumnNames="user_id" />
    </changeSet>
    <changeSet author="vinay" id="20160302-1822">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT COUNT(*) FROM global_property where property = 'emr.encounterMatcher'
                and property_value = 'org.openmrs.module.bahmniemrapi.encountertransaction.matcher.EncounterSessionMatcher'
            </sqlCheck>
        </preConditions>
        <comment>Update custom encounter session matcher</comment>
        <sql>
            update global_property set property_value='org.bahmni.module.bahmnicore.matcher.EncounterSessionMatcher' where property='emr.encounterMatcher' ;
        </sql>
    </changeSet>

    <changeSet id="20160302-1225" author="Shan,Hanisha">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'Manage Program Attribute Types'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="Manage Program Attribute Types"/>
            <column name="description" value="Access to enter,edit and view program attributes"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>

    <changeSet id="20160302-1226" author="Shan,Hanisha">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'View Program Attribute Types'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="View Program Attribute Types"/>
            <column name="description" value="Access to only view program attributes"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>

    <changeSet id="20160302-1230" author="Shan,Hanisha">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege = 'Purge Program Attribute Types'</sqlCheck>
        </preConditions>
        <insert tableName="privilege">
            <column name="privilege" value="Purge Program Attribute Types"/>
            <column name="description" value="Access to purge program attribute types"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>

    <changeSet id="20160322153797" author="Jaswanth, Hemanth">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
                WHERE table_schema='openmrs' AND table_name='bed_patient_assignment_map' AND
                column_name='date_stopped';
            </sqlCheck>
        </preConditions>
        <comment>Add index on date_stopped column for bed_patient_assignment_map table</comment>
        <createIndex indexName="bed_patient_assignment_map_date_stopped"
                     tableName="bed_patient_assignment_map">
            <column name="date_stopped"/>
        </createIndex>
    </changeSet>

    <changeSet id="201603221630968" author="Jaswanth, Hemanth">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
                WHERE table_schema='openmrs' AND table_name='visit' AND
                column_name='date_stopped';
            </sqlCheck>
        </preConditions>
        <comment>Add index on date_stopped column for visit table</comment>
        <createIndex indexName="visit_date_stopped"
                     tableName="visit">
            <column name="date_stopped"/>
        </createIndex>
    </changeSet>

    <changeSet id="201604261630" author="Gautam">
        <comment>SQL query to get list of active patients by location</comment>
        <sqlFile path="V1_92_PatientSearch.sql"/>
    </changeSet>

    <changeSet author="Pankaj, Achinta" id="20160510-999">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM privilege WHERE privilege='app:clinical:locationpicker';
            </sqlCheck>
        </preConditions>
        <comment>Creating Location Picker Privilege</comment>
        <sql>
            INSERT INTO privilege (privilege, description, uuid) VALUES ('app:clinical:locationpicker', 'View Location Picker option', uuid());
        </sql>
    </changeSet>

    <changeSet author="Pankaj, Achinta" id="201605101601-999">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM privilege WHERE privilege='app:clinical:onbehalf';
            </sqlCheck>
        </preConditions>
        <comment>Creating On Behalf Of Privilege</comment>
        <sql>
            INSERT INTO privilege (privilege, description, uuid) VALUES ('app:clinical:onbehalf', 'View On behalf of option', uuid());
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201606291787" author="Pankaj, Hanisha">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM location_tag where name='Visit Location';
            </sqlCheck>
        </preConditions>
        <comment>Add Visit Location Tag if not already added.</comment>
        <sql>
            set @current_date = 0;
            select now() into @current_date;

            INSERT INTO location_tag (name, description, creator, date_created, uuid) VALUES
            ('Visit Location',
            'Visit Location',
            1,
            @current_date,
            uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201608011234" author="Hanisha, Vinay">
        <preConditions onFail="HALT">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM visit where location_id is null;
            </sqlCheck>
        </preConditions>
        <comment>Visits should not have location null. Please refer to release notes 0.83</comment>
    </changeSet>

    <changeSet id="bahmni-PatientSearch-Update-201607151835" author="Lavanya, Shashi">
        <comment>update the search query to consider visit location</comment>
        <sqlFile path="V1_93_PatientSearchSql.sql"/>
    </changeSet>

    <changeSet id="201607281228" author="Preethi, Gaurav">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM  INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME='patient_identifier' AND CONSTRAINT_NAME='unique_patient_identifier';
            </sqlCheck>
        </preConditions>
        <comment>Drop unique constraint on identifier column in patient_identifier table</comment>
        <sql>
            ALTER TABLE patient_identifier DROP INDEX unique_patient_identifier;
        </sql>
    </changeSet>
    <changeSet id="201607291555" author="Preethi">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(*) from patient_identifier_type where name = 'Bahmni Id';
            </sqlCheck>
        </preConditions>
        <comment>Renaming Bahmni Id to Patient Identifer in patient_identifier_type table</comment>
        <sql>
            update patient_identifier_type set name = 'Patient Identifier' where name = 'Bahmni Id'
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201608081535" author="Chethan, Yugesh">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Video';
            </sqlCheck>
        </preConditions>
        <comment>Add Concept Class Video</comment>
        <insert tableName="concept_class">
            <column name="name" value="Video"/>
            <column name="description" value="Video class"/>
            <column name="creator" value="1"/>
            <column name="date_created" valueComputed="curdate()"/>
            <column name="retired" value="0"/>
            <column name="uuid" valueComputed="uuid()"/>
        </insert>
    </changeSet>
    <changeSet id="bahmni-PatientSearch-Update-201608121039" author="Preethi, Hanisha">
        <comment>update the search query to consider multiple identifiers</comment>
        <sqlFile path="V1_94_PatientSearchSql.sql"/>
    </changeSet>
    <changeSet id="bahmni-WardsList-Update-201609011124" author="Jaswanth">
        <comment>Update the wards list sql to use left join for patient address</comment>
        <sqlFile path="V1_95_WardsListSql.sql"/>
    </changeSet>
    <changeSet id="bahmni-core-2016092714-possible-75" author="Panakaj, Hanisha">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                select count(*) from concept_name where name='Cured Diagnosis' AND concept_name_type = 'FULLY_SPECIFIED';
            </sqlCheck>
        </preConditions>
        <comment>Add new concept for Cured Diagnosis</comment>
        <sql>
            set @concept_id = 0;
            set @answer_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, 'Cured Diagnosis', 'Cured Diagnosis', 'N/A', 'Misc', true);
        </sql>
    </changeSet>
    <changeSet id="bahmni-new-roles-and-privileges" author="Jaswanth, Ravindra">
        <validCheckSum>3:14239025d1eeb1a927e6ab5e0bb85e08</validCheckSum>
        <comment>New roles and privileges for bahmni</comment>
        <sqlFile path="V1_96_NewRolesAndPrivileges.sql"/>
    </changeSet>
    <changeSet id="bahmni-core-201906201151" author="Samuel34">
    	<preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                select count(*) from users where system_id='superman' or username='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 system_id='admin' into @id;
            INSERT IGNORE INTO `user_role` VALUES (@id,'Provider'),(@id,'System Developer');

            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">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(*) from users where username = 'automation'
            </sqlCheck>
        </preConditions>
        <comment>Assign role to automation user</comment>
        <sql>
            set @id = NULL;
            select user_id from users where username='automation' into @id;
            INSERT INTO `user_role` VALUES (@id, 'SuperAdmin');
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201610211440" author="Gaurav">

        <comment>Change data type of REFERRED_OUT concept to boolean</comment>
        <sql>
            UPDATE concept
            SET datatype_id =
            (SELECT concept_datatype_id
            FROM concept_datatype
            WHERE name = 'Boolean')
            WHERE concept_id IN (SELECT concept_id
            FROM concept_name
            WHERE name = 'REFERRED_OUT');
        </sql>
    </changeSet>
    <changeSet id="add-correct-description-for-internal-roles" author="Jaswanth">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(*) from role where role = 'Bahmni-App-User-Login'
            </sqlCheck>
        </preConditions>
        <comment>Add correct description for internal roles</comment>
        <sql>
           update role set description = 'Will give ability to login to the application and used internally, should not be assigned to user directly.' where role = 'Bahmni-App-User-Login';
           update role set description = 'Will have save privileges used by other Clinical roles and used internally, should not be assigned to user directly.' where role = 'Clinical-App-Save';
           update role set description = 'Will have common privileges used by other Clinical roles and used internally, should not be assigned to user directly.' where role = 'Clinical-App-Common';
           update role set description = 'Role if assigned disables two factor authentication for that user and used internally, should not be assigned to user directly.' where role = 'bypass2FA';
        </sql>
    </changeSet>

    <changeSet id="add-clincal-app-role-for-program-app-201610261552" author="Kaustav, Hanisha">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="2">
                select count(*) from role where role in ('Clinical-App','Programs-App')
            </sqlCheck>
        </preConditions>
        <comment>Add Clinical-app role as sub role to Programs-app role</comment>
        <sql>
            insert into role_role values('Clinical-App', 'Programs-App');
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201611101133" author="Gaurav">
        <comment>Updating Referred out obs to have value coded as true </comment>
        <sql>
            UPDATE obs
            SET value_coded = (SELECT concept_id
            FROM concept_name
            WHERE name = 'True' AND concept_name_type = 'FULLY_SPECIFIED')
            WHERE concept_id IN (SELECT concept_id
            FROM concept_name
            WHERE name = 'REFERRED_OUT' AND concept_name_type = 'FULLY_SPECIFIED') AND value_coded IS NULL;
        </sql>
    </changeSet>

    <changeSet id="add-privileges-to-roles-20161111" author="Ravindra">
        <comment>Add privileges to roles Clinical-App-Common(Get Order Sets), Registration-App(Delete Visits) </comment>
        <sql>
            INSERT IGNORE INTO role_privilege (role, privilege) SELECT * FROM (SELECT 'Clinical-App-Common', 'Get Order Sets') AS tmp WHERE EXISTS ( SELECT role FROM role WHERE role = 'Clinical-App-Common' );
            INSERT IGNORE INTO role_privilege (role, privilege) SELECT * FROM (SELECT 'Registration-App', 'Delete Visits') AS tmp WHERE EXISTS ( SELECT role FROM role WHERE role = 'Registration-App' );
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201612051010" author="Gaurav">
        <comment>Add 'Get Concept Sources' privilege to all roles containing 'Get Concepts'
            privilege
        </comment>
        <sql>
            INSERT INTO role_privilege (
            SELECT DISTINCT
            role,
            'Get Concept Sources'
            FROM
            ( SELECT DISTINCT role
            FROM role_privilege
            WHERE privilege IN ('Get Concepts')) tmp
            WHERE (role, 'Get Concept Sources') NOT IN ( SELECT *
            FROM role_privilege));
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201612051015" author="Gaurav">
        <comment>Add 'Add Encounters' privilege to all roles containing 'Add Visits' or 'Edit Visits'
            privilege
        </comment>
        <sql>
            INSERT INTO role_privilege (
            SELECT DISTINCT
            role,
            'Add Encounters'
            FROM
            ( SELECT DISTINCT role
            FROM role_privilege
            WHERE privilege IN ('Add Visits','Edit Visits')) tmp
            WHERE (role, 'Add Encounters') NOT IN ( SELECT *
            FROM role_privilege));
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201612051020" author="Gaurav">
        <comment>Add 'Edit Encounters' privilege to all roles containing 'Add Visits'or 'Edit Visits'
            privilege
        </comment>
        <sql>
            INSERT INTO role_privilege (
            SELECT DISTINCT
            role,
            'Edit Encounters'
            FROM
            ( SELECT DISTINCT role
            FROM role_privilege
            WHERE privilege IN ('Add Visits','Edit Visits')) tmp
            WHERE (role, 'Edit Encounters') NOT IN ( SELECT *
            FROM role_privilege));
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201612051725" author="Gaurav">
        <comment>Add 'Get Observations' privilege to all roles containing 'Add Encounters' and 'Edit Encounters'
            privilege
        </comment>
        <sql>
            INSERT INTO role_privilege (
            SELECT DISTINCT
            role,
            'Get Observations'
            FROM
            ( SELECT DISTINCT role
            FROM role_privilege
            WHERE privilege IN ('Add Encounters', 'Edit Encounters')) tmp
            WHERE (role, 'Get Observations') NOT IN ( SELECT *
            FROM role_privilege));
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201612051350" author="Preethi,Gaurav">
        <comment>Add 'Add Observations' privilege to all roles containing 'Add Encounters' and 'Edit Encounters'
            privilege
        </comment>
        <sql>
            INSERT INTO role_privilege (
            SELECT DISTINCT
            role,
            'Add Observations'
            FROM
            ( SELECT DISTINCT role
            FROM role_privilege
            WHERE privilege IN ('Add Encounters', 'Edit Encounters')) tmp
            WHERE (role, 'Add Observations') NOT IN ( SELECT *
            FROM role_privilege));
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201612051355" author="Preethi,Gaurav">
        <comment>Add 'Edit Observations' privilege to all roles containing 'Add Encounters' and 'Edit Encounters'
            privilege
        </comment>
        <sql>
            INSERT INTO role_privilege (
            SELECT DISTINCT
            role,
            'Edit Observations'
            FROM
            ( SELECT DISTINCT role
            FROM role_privilege
            WHERE privilege IN ('Add Encounters', 'Edit Encounters')) tmp
            WHERE (role, 'Edit Observations') NOT IN ( SELECT *
            FROM role_privilege));
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201612071518" author="Preethi, Gaurav">
        <comment>Delete empty diagnosis status obs</comment>
        <sql>
            set @diagnosis_status_concept_id = 0;
            select concept_id from concept_name where concept_name_type='FULLY_SPECIFIED' and name='Bahmni Diagnosis Status' into @diagnosis_status_concept_id;
            update obs o1 join obs o2 on o1.previous_version = o2.obs_id and o2.concept_id = @diagnosis_status_concept_id and o2.value_coded is null set o1.previous_version = null;
            delete from obs where concept_id = @diagnosis_status_concept_id and value_coded is null;
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201612081800" author="Jaswanth">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                select count(*) from role_privilege where role = 'Clinical-App' and privilege = 'app:clinical:deleteDiagnosis'
            </sqlCheck>
        </preConditions>
        <comment>Add delete diagnosis privilege to Clinical App role</comment>
        <sql>
            insert into role_privilege values('Clinical-App', 'app:clinical:deleteDiagnosis');
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201612091038" author="Preethi">
        <comment>Update log level of org.openmrs.api to WARN</comment>
        <sql>
            update global_property set property_value='org.openmrs.api:warn' where property = 'log.level' and property_value like '%org.openmrs.api%';
        </sql>
    </changeSet>

    <changeSet id="20100517-1545" author="wyclif and djazayeri" dbms="mysql">
        <comment>Switch boolean concepts/observations to be stored as coded</comment>
        <customChange class="org.openmrs.util.databasechange.BooleanConceptChangeSet"/>
    </changeSet>

    <changeSet id="bahmni-core-201701241540" author="Padma">
        <preConditions onFail="HALT">
            <not>
                <sqlCheck expectedResult="0">
                    SELECT COUNT(*) FROM global_property WHERE property = 'concept.true' and property_value is not null;
                </sqlCheck>
            </not>
        </preConditions>
        <comment>Set value coded for referred out concepts</comment>
        <sql>
            UPDATE obs
            SET value_coded = (SELECT property_value
            FROM global_property where property = 'concept.true')
            WHERE concept_id IN (SELECT concept_id
            FROM concept_name
            WHERE name = 'REFERRED_OUT' AND concept_name_type = 'FULLY_SPECIFIED') AND value_coded IS NULL;
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201702061413" author="Preethi">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                select count(*) from role where role = 'HubConnect';
            </sqlCheck>
        </preConditions>
        <comment>Create HubConnect Role with location and provider privileges</comment>
        <sql>
            insert into role(role, description, uuid) values( 'HubConnect', 'Will have privileges required to sync resources from parent Bahmni server to child Bahmni server', uuid());
            insert into role_privilege(role, privilege) values ('HubConnect', 'Get Locations');
            insert into role_privilege(role, privilege) values ('HubConnect', 'Get Location Attribute Types');
    </sql>
    </changeSet>

    <changeSet id="obsRelationship-ForeignKey-Update-201611151430" author="Santhosh, Chethan">
        <preConditions onFail="MARK_RAN">
            <tableExists tableName="obs_relationship"/>
            <foreignKeyConstraintExists foreignKeyName="obs_relationship_ibfk_4"/>
        </preConditions>
        <comment>Update the foreign key constrain on obs_relationship, Consider user_id(users) for foreign key reference instead of person_id(person)</comment>
        <sql>
            ALTER TABLE obs_relationship
            DROP FOREIGN KEY obs_relationship_ibfk_4;

            ALTER TABLE obs_relationship
            ADD CONSTRAINT obs_relationship_ibfk_4
            FOREIGN KEY (creator)
            REFERENCES users(user_id);
        </sql>
    </changeSet>

    <changeSet id="bahmni-clinical-201703071203" author="Shruthi P, Pushpa" context="rel3">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">select count(*) from patient_identifier_type where name = 'Bahmni Id'</sqlCheck>
        </preConditions>
        <comment>set global property value for bahmni primary identifier type</comment>
        <sql>
            update global_property set property_value = (select uuid from patient_identifier_type where name = 'Bahmni Id') where property = 'bahmni.primaryIdentifierType';
        </sql>
    </changeSet>

    <changeSet id="bahmni-PatientSearch-Update-201703071203" author="Shruthi P, Pushpa">
        <comment>update the search query to use bahmni.primaryIdentifierType global property instead of emr.primaryIdentifierType</comment>
        <sqlFile path="V1_97_PatientSearchSql.sql"/>
    </changeSet>

    <changeSet id="bahmni-WardsList-Update-201703071203" author="Shruthi P, Pushpa">
        <comment>Update the wards list sql to use bahmni.primaryIdentifierType global property instead of emr.primaryIdentifierType</comment>
        <sqlFile path="V1_98_WardsListSql.sql"/>
    </changeSet>

    <changeSet id="bahmni-202212131256" author="Shruthi P, Pushpa">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(property) FROM global_property WHERE property='emr.primaryIdentifierType';
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(property) FROM global_property WHERE property='bahmni.primaryIdentifierType';
            </sqlCheck>
        </preConditions>
        <comment>update global property key 'emr.primaryIdentifierType' to 'bahmni.primaryIdentifierType'</comment>
        <sql>
            UPDATE global_property SET property='bahmni.primaryIdentifierType' where property='emr.primaryIdentifierType';
        </sql>
    </changeSet>

    <changeSet id="bahmni-201703061756" author="Shruthi P, Pushpa">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(property) FROM global_property where property='emr.extraPatientIdentifierTypes';
            </sqlCheck>
        </preConditions>
        <comment>update global property key 'emr.extraPatientIdentifierTypes' to 'bahmni.extraPatientIdentifierTypes'</comment>
        <sql>
            update global_property set property='bahmni.extraPatientIdentifierTypes' where property='emr.extraPatientIdentifierTypes';
        </sql>
    </changeSet>

    <changeSet id="create-auditlogtable-201703211430" author="Shruthi,Salauddin">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="audit_log" />
            </not>
        </preConditions>

        <sql>
            CREATE TABLE audit_log (
            audit_log_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
            user_id INT(11) NOT NULL,
            patient_id INT(11),
            event_type VARCHAR(100) NOT NULL,
            message LONGBLOB NOT NULL,
            date_created DATETIME NOT NULL,
            uuid VARCHAR(38) NOT NULL UNIQUE,

            FOREIGN KEY fk_patient_id(patient_id) REFERENCES patient(patient_id),
            FOREIGN KEY fk_user_id(user_id) REFERENCES users(user_id)
            );

        </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
                name = 'Non-Coded Condition' AND concept_name_type = 'FULLY_SPECIFIED' AND voided = FALSE)
                and retired = FALSE;
            </sqlCheck>
        </preConditions>
        <comment>Add new concept for Non-Coded Condition</comment>
        <sql>
            set @concept_id = 0;
            set @answer_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, 'Non-Coded Condition',
            'Non-Coded Condition', 'Text', 'Question', false);

            update global_property set property_value = (select uuid from concept where concept_id = @concept_id)
            where property = 'conditionList.nonCodedUuid';
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201705041200" author="Bindu">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(*) from global_property where property_value='en, es, fr, it, pt';
            </sqlCheck>
        </preConditions>
        <comment>Renaming 'pt' to 'pt_BR' for locale.allowed.list property in global_property table</comment>
        <sql>
            update global_property set property_value='en, es, fr, it, pt_BR' where property_value='en, es, fr, it, pt';
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201704191128" author="Shashi, Gautam">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='Edit conditions'</sqlCheck>
        </preConditions>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('Edit conditions', 'Privilege to add or edit conditions', @uuid);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201704191135" author="Shashi, Gautam">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='Get conditions'</sqlCheck>
        </preConditions>
        <sql>
            set @uuid = '';
            select uuid() into @uuid;
            insert into privilege(privilege, description, uuid) values('Get conditions', 'Privilege to view conditions', @uuid);
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201704191140" author="Shashi, Gautam">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">SELECT count(privilege) FROM role_privilege WHERE privilege = 'Edit conditions' and role = 'Clinical-App-Save'</sqlCheck>
        </preConditions>
        <comment>Add privileges to roles Clinical-App-Save(Edit Conditions)</comment>
        <sql>
            INSERT IGNORE INTO role_privilege (role, privilege) SELECT * FROM (SELECT 'Clinical-App-Save', 'Edit conditions') AS tmp WHERE EXISTS ( SELECT role FROM role WHERE role = 'Clinical-App-Save' );
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201704191145" author="Shashi, Gautam">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">SELECT count(privilege) FROM role_privilege WHERE privilege = 'Get conditions' and role = 'Clinical-App-Read-Only'</sqlCheck>
        </preConditions>
        <comment>Add privileges to roles Clinical-App-Read-Only(Get conditions) </comment>
        <sql>
            INSERT IGNORE INTO role_privilege (role, privilege) SELECT * FROM (SELECT 'Clinical-App-Read-Only', 'Get conditions') AS tmp WHERE EXISTS ( SELECT role FROM role WHERE role = 'Clinical-App-Read-Only' );
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-201704211500" author="Shashi, Sicong">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">SELECT count(privilege) FROM role_privilege WHERE privilege = 'Get Forms' and role = 'Clinical-App-Read-Only'</sqlCheck>
        </preConditions>
        <comment>Add privileges to roles Clinical-App-Read-Only(Get Forms) </comment>
        <sql>
            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
                name = 'Follow-up Condition' AND concept_name_type = 'FULLY_SPECIFIED' AND voided = FALSE) and
                retired = FALSE;
            </sqlCheck>
        </preConditions>
        <comment>Add new concept for Follow-up Condition</comment>
        <sql>
            set @concept_id = 0;
            set @answer_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, 'Follow-up Condition',
            'Follow-up Condition', 'Text', 'Misc', false);
        </sql>
    </changeSet>

    <changeSet id="20170829-1138" author="Suman M">
        <comment>Update global property to handle null for family name</comment>
        <sql>
            UPDATE global_property
            SET property_value = REPLACE(property_value, "pn.family_name", "ifnull(pn.family_name,'')")
            WHERE global_property.property_value LIKE '%pn.family_name%';
        </sql>
    </changeSet>

    <changeSet id="Create-privilege-appointments-app-201709201731"  author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='app:appointments'</sqlCheck>
        </preConditions>
        <comment>Adding privilege for Appointments Module</comment>
        <sql>
            INSERT INTO privilege (privilege, description, uuid) VALUES ('app:appointments', 'Able to view Appointments module', uuid());
        </sql>
    </changeSet>

    <changeSet id="Create-privilege-appointments-manage-201709201740"  author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='app:appointments:manageAppointmentsTab'</sqlCheck>
        </preConditions>
        <comment>Adding privilege for managing appointments in appointments Module</comment>
        <sql>
            INSERT INTO privilege (privilege, description, uuid) VALUES ('app:appointments:manageAppointmentsTab', 'Able to manage appointments in appointments module', uuid());
        </sql>
    </changeSet>

    <changeSet id="Create-privilege-appointments-admin-201709201813"  author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">select count(*) from privilege where privilege='app:appointments:adminTab'</sqlCheck>
        </preConditions>
        <comment>Adding privilege for managing services in appointments Module</comment>
        <sql>
            INSERT INTO privilege (privilege, description, uuid) VALUES ('app:appointments:adminTab', 'Able to manage services in appointments module', uuid());
        </sql>
    </changeSet>

    <changeSet id="create-readonly-role-appointments-201709201830" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role WHERE role = 'Appointments:ReadOnly';
            </sqlCheck>
        </preConditions>
        <comment>Creating new role Appointments: ReadOnly for Appointments module</comment>
        <sql>
            INSERT INTO role(role, description, uuid) VALUES ("Appointments:ReadOnly", "Ability to view appointments in appointments module", uuid());
        </sql>
    </changeSet>
    <changeSet id="create-manage-role-appointments-201709201838" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role WHERE role = 'Appointments:ManageAppointments';
            </sqlCheck>
        </preConditions>
        <comment>Creating new role Appointments: Manage for Appointments module</comment>
        <sql>
            INSERT INTO role(role, description, uuid) VALUES ("Appointments:ManageAppointments", "Ability to manage appointments in appointments module", uuid());
        </sql>
    </changeSet>
    <changeSet id="create-fullaccess-role-appointments-201709201815" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role WHERE role = 'Appointments:FullAccess';
            </sqlCheck>
        </preConditions>
        <comment>Creating new role for Full Access to Appointments module</comment>
        <sql>
            INSERT INTO role(role, description, uuid) VALUES ("Appointments:FullAccess", "Ability to manage appointments and services in appointments module", uuid());
        </sql>
    </changeSet>

    <changeSet id="201710061600" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM privilege WHERE privilege = "app:appointments";
            </sqlCheck>
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM role WHERE role = "Appointments:ReadOnly";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role_privilege WHERE role = "Appointments:ReadOnly" AND privilege = "app:appointments";
            </sqlCheck>
        </preConditions>
        <comment>Adding app:appointments privilege to Appointments: ReadOnly role</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ("Appointments:ReadOnly", "app:appointments");
        </sql>
    </changeSet>
    <changeSet id="201710061610" author="Santhosh, Pramida">
        <preConditions onFail="CONTINUE">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM privilege WHERE privilege = "View Appointments";
            </sqlCheck>
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM role WHERE role = "Appointments:ReadOnly";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role_privilege WHERE role = "Appointments:ReadOnly" AND privilege="View Appointments";
            </sqlCheck>
        </preConditions>
        <comment>Adding View Appointments privilege to Appointments: ReadOnly role</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ("Appointments:ReadOnly", "View Appointments");
        </sql>
    </changeSet>
    <changeSet id="201710061620" author="Santhosh, Pramida">
        <preConditions onFail="CONTINUE">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM privilege WHERE privilege = "View Appointment Services";
            </sqlCheck>
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM role WHERE role = "Appointments:ReadOnly";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role_privilege WHERE role = "Appointments:ReadOnly" AND privilege ="View Appointment Services";
            </sqlCheck>
        </preConditions>
        <comment>Adding all the privileges to Appointments: ReadOnly</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ("Appointments:ReadOnly", "View Appointment Services");
        </sql>
    </changeSet>
    <changeSet id="201710061630" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM role WHERE role = "Appointments:ReadOnly";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM role_privilege WHERE role = 'Appointments:ReadOnly' AND privilege = 'Get Locations';
            </sqlCheck>
        </preConditions>
        <comment>adding Get Locations privilege to Appointments:ReadOnly role</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ('Appointments:ReadOnly', 'Get Locations');
        </sql>
    </changeSet>
    <changeSet id="201710061640" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM role WHERE role = "Appointments:ReadOnly";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM role_privilege WHERE role = 'Appointments:ReadOnly' AND privilege = 'Get Patients';
            </sqlCheck>
        </preConditions>
        <comment>adding Get Patients privilege to Appointments:ReadOnly role</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ('Appointments:ReadOnly', 'Get Patients');
        </sql>
    </changeSet>
    <changeSet id="201710061650" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM role WHERE role = "Appointments:ReadOnly";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM role_privilege WHERE role = 'Appointments:ReadOnly' AND privilege = 'Get Patient Identifiers';
            </sqlCheck>
        </preConditions>
        <comment>adding Get Patient Identifiers privilege to Appointments:ReadOnly role</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ('Appointments:ReadOnly', 'Get Patient Identifiers');
        </sql>
    </changeSet>
    <changeSet id="201710061700" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM role WHERE role = "Appointments:ReadOnly";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM role_privilege WHERE role = 'Appointments:ReadOnly' AND privilege = 'Get Providers';
            </sqlCheck>
        </preConditions>
        <comment>adding Get Providers privilege to Appointments:ReadOnly role</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ('Appointments:ReadOnly', 'Get Providers');
        </sql>
    </changeSet>


    <changeSet id="201710061710" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM privilege WHERE privilege = "app:appointments:manageAppointmentsTab";
            </sqlCheck>
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM role WHERE role = "Appointments:ManageAppointments";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role_privilege WHERE role = "Appointments:ManageAppointments" AND privilege = "app:appointments:manageAppointmentsTab";
            </sqlCheck>
        </preConditions>
        <comment>Adding app:appointments:manageAppointmentsTab privilege to Appointments:ManageAppointments role</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ("Appointments:ManageAppointments", "app:appointments:manageAppointmentsTab");
        </sql>
    </changeSet>
    <changeSet id="201710061720" author="Santhosh, Pramida">
        <preConditions onFail="CONTINUE">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM privilege WHERE privilege = "Manage Appointments";
            </sqlCheck>
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM role WHERE role = "Appointments:ManageAppointments";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role_privilege WHERE role = "Appointments:ManageAppointments" AND privilege = "Manage Appointments";
            </sqlCheck>
        </preConditions>
        <comment>Adding Manage Appointments privilege to Appointments:ManageAppointments role</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ("Appointments:ManageAppointments", "Manage Appointments");
        </sql>
    </changeSet>

    <changeSet id="201710061730" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM privilege WHERE privilege = "app:appointments:adminTab";
            </sqlCheck>
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM role WHERE role = "Appointments:FullAccess";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role_privilege WHERE role = "Appointments:FullAccess" AND privilege = "app:appointments:adminTab";
            </sqlCheck>
        </preConditions>
        <comment>Adding app:appointments:adminTab privilege to Appointments:FullAccess</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ("Appointments:FullAccess", "app:appointments:adminTab");
        </sql>
    </changeSet>
    <changeSet id="201710061740" author="Santhosh, Pramida">
        <preConditions onFail="CONTINUE">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM privilege WHERE privilege = "Manage Appointment Services";
            </sqlCheck>
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM role WHERE role = "Appointments:FullAccess";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role_privilege WHERE role = "Appointments:FullAccess" AND privilege = "Manage Appointment Services";
            </sqlCheck>
        </preConditions>
        <comment>Adding Manage Appointment Services privilege to Appointments:FullAccess</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ("Appointments:FullAccess", "Manage Appointment Services");
        </sql>
    </changeSet>

    <changeSet id="201710061750" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM role_role WHERE child_role = 'Appointments:ManageAppointments' AND parent_role = 'Appointments:ReadOnly';
            </sqlCheck>
        </preConditions>
        <comment>adding Appointments:ReadOnly as parent role for Appointments:ManageAppointments role to inherit all privileges from Appointments:ReadOnly</comment>
        <sql>
            INSERT INTO role_role(child_role, parent_role) VALUES ('Appointments:ManageAppointments', 'Appointments:ReadOnly');
        </sql>
    </changeSet>
    <changeSet id="201710061800" author="Santhosh, Pramida">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM role_role WHERE child_role = 'Appointments:FullAccess' AND parent_role = 'Appointments:ManageAppointments';
            </sqlCheck>
        </preConditions>
        <comment>adding Appointments:ManageAppointments as parent role for Appointments:FullAccess role to inherit all privileges from Appointments:ManageAppointments</comment>
        <sql>
            INSERT INTO role_role(child_role, parent_role) VALUES ('Appointments:FullAccess', 'Appointments:ManageAppointments');
        </sql>
    </changeSet>
    <changeSet id="Amman-201707101139" author="Shireesha, Pramida" context="rel3.2">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role where role = "OT: FullAccess";
            </sqlCheck>
        </preConditions>
        <comment> Creating a role for OT: FullAccess</comment>
        <sql>
            INSERT INTO role(role, description, uuid) VALUES ("OT: FullAccess", "Ability to access and modify OT schedules", uuid());
        </sql>
    </changeSet>
    <changeSet id="Amman-201707101152" author="Shireesha, Pramida" context="rel3.2">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role where role = "OT: ReadOnly";
            </sqlCheck>
        </preConditions>
        <comment> Creating a role for OT- ReadOnly</comment>
        <sql>
            INSERT INTO role(role, description, uuid) VALUES ("OT: ReadOnly", "Ability to access and modify OT schedules", uuid());
        </sql>
    </changeSet>
    <changeSet id="Amman-201707101154" author="Shireesha, Pramida" context="rel3.2">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM privilege where privilege = "app:ot";
            </sqlCheck>
        </preConditions>
        <comment> Creating a privilege for viewing the OT module</comment>
        <sql>
            INSERT INTO privilege(privilege, description, uuid) VALUES ("app:ot", "Ability to view OT module", uuid());
        </sql>
    </changeSet>
    <changeSet id="Amman-201707101156" author="Shireesha, Pramida" context="rel3.2">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM privilege where privilege = "app:ot:write";
            </sqlCheck>
        </preConditions>
        <comment> Creating a privilege for viewing the OT module</comment>
        <sql>
            INSERT INTO privilege(privilege, description, uuid) VALUES ("app:ot:write", "Ability to view new surgical block and other buttons to edit on OT module", uuid());
        </sql>
    </changeSet>
    <changeSet id="Amman-201707101106" author="Shireesha, Pramida" context="rel3.2">
        <preConditions onFail="CONTINUE">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM privilege WHERE privilege = "Manage OT Schedules";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role_privilege WHERE role = "OT: FullAccess" AND privilege = "Manage OT Schedules";
            </sqlCheck>
        </preConditions>
        <comment>Adding Manage OT Schedules privilege to OT: FullAccess role</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ("OT: FullAccess", "Manage OT Schedules");
            INSERT INTO role_privilege(role, privilege) VALUES ("OT: FullAccess", "View OT Schedules");
            INSERT INTO role_privilege(role, privilege) VALUES ("OT: FullAccess", "app:ot");
            INSERT INTO role_privilege(role, privilege) VALUES ("OT: FullAccess", "app:ot:write");
        </sql>
    </changeSet>
    <changeSet id="Amman-201707101159" author="Shireesha, Pramida" context="rel3.2">
        <preConditions onFail="CONTINUE">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM privilege WHERE privilege = "View OT Schedules";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role_privilege WHERE role = "OT: ReadOnly" AND privilege = "View OT Schedules";
            </sqlCheck>
        </preConditions>
        <comment>Adding view OT Schedules privilege to OT: ReadOnly role</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ("OT: ReadOnly", "View OT Schedules");
            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">
                SELECT count(*) FROM concept_view WHERE concept_full_name = 'Bahmni Initial Diagnosis';
            </sqlCheck>
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM concept WHERE is_set= TRUE AND concept_id = (SELECT concept_id FROM concept_view
                WHERE concept_full_name = 'Bahmni Initial Diagnosis');
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM concept_set WHERE concept_set = (SELECT concept_id FROM concept_view
                WHERE concept_full_name = 'Bahmni Initial Diagnosis');
            </sqlCheck>
        </preConditions>
        <comment>Updating 'Bahmni Initial Diagnosis' concept to non-set concept</comment>
        <sql>
            SET @concept_id=0;
            SELECT concept_id FROM concept_view WHERE concept_full_name = 'Bahmni Initial Diagnosis' INTO @concept_id;
            UPDATE concept SET is_set = FALSE WHERE concept_id = @concept_id;
        </sql>
    </changeSet>
    <changeSet id="201805112237" author="Suman">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM concept_view WHERE concept_full_name = 'Bahmni Diagnosis Status';
            </sqlCheck>
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM concept WHERE is_set= TRUE AND concept_id = (SELECT concept_id FROM concept_view
                WHERE concept_full_name = 'Bahmni Diagnosis Status');
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM concept_set WHERE concept_set = (SELECT concept_id FROM concept_view
                WHERE concept_full_name = 'Bahmni Diagnosis Status');
            </sqlCheck>
        </preConditions>
        <comment>Updating 'Bahmni Diagnosis Status' concept to non-set concept</comment>
        <sql>
            SET @concept_id=0;
            SELECT concept_id FROM concept_view WHERE concept_full_name = 'Bahmni Diagnosis Status' INTO @concept_id;
            UPDATE concept SET is_set = FALSE WHERE concept_id = @concept_id;
        </sql>
    </changeSet>
    <changeSet id="201805112239" author="Suman">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM concept_view WHERE concept_full_name = 'Bahmni Diagnosis Revised';
            </sqlCheck>
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM concept WHERE is_set= TRUE AND concept_id = (SELECT concept_id FROM concept_view
                WHERE concept_full_name = 'Bahmni Diagnosis Revised');
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM concept_set WHERE concept_set = (SELECT concept_id FROM concept_view
                WHERE concept_full_name = 'Bahmni Diagnosis Revised');
            </sqlCheck>
        </preConditions>
        <comment>Updating 'Bahmni Diagnosis Revised' concept to non-set concept</comment>
        <sql>
            SET @concept_id=0;
            SELECT concept_id FROM concept_view WHERE concept_full_name = 'Bahmni Diagnosis Revised' INTO @concept_id;
            UPDATE concept SET is_set = FALSE WHERE concept_id = @concept_id;
        </sql>
    </changeSet>
    <changeSet id="BAM-20180830150635" author="Angshu" runOnChange="true" context="release0.91">
        <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">
                select count(*) from scheduler_task_config where schedulable_class= "org.openmrs.module.emrapi.adt.CloseStaleVisitsTask" and name = "Close Stale Visits Task"; </sqlCheck>
        </preConditions>
        <comment> Add Bahmni preferred EMR API scheduler which closes stale visits </comment>
        <insert tableName="scheduler_task_config">
                <column name="name" value="Close Stale Visits Task" />
                <column name="description" value="Auto close visit task after number of hours specified by emrapi.visitExpireHours" />
                <column name="schedulable_class" value="org.openmrs.module.emrapi.adt.CloseStaleVisitsTask" />
                <column name="start_on_startup" valueBoolean="true" />
                <column name="start_time_pattern" value="MM/dd/yyyy HH:mm:ss" />
                <column name="start_time" valueDate="2014-04-30T23:59:59" />
                <column name="repeat_interval" value="86400" />
                <column name="date_created" valueDate="CURRENT_TIMESTAMP" />
                <column name="created_by" value="1" />
                <column name="uuid" valueComputed="uuid()" />
        </insert>
    </changeSet>
    <changeSet id="openmrs-atomfeed-offset-marker-201906032013" author="Angshu,Bindu" context="r0.92">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                select count(*) from scheduler_task_config where schedulable_class= "org.openmrs.module.atomfeed.scheduler.tasks.EventPublisherTask" and name = "OpenMRS event publisher task";
            </sqlCheck>
        </preConditions>
        <comment>adding OpenMRS event publisher task scheduler</comment>
        <insert tableName="scheduler_task_config">
            <column name="name" value="OpenMRS event publisher task"/>
            <column name="schedulable_class" value="org.openmrs.module.atomfeed.scheduler.tasks.EventPublisherTask"/>
            <column name="start_time" valueDate=" now() "/>
            <column name="start_time_pattern" value="MM/dd/yyyy HH:mm:ss"/>
            <column name="repeat_interval" value="5"/>
            <column name="start_on_startup" value="1"/>
            <column name="started" value="1"/>
            <column name="created_by" value="1"/>
            <column name="date_created" valueDate=" now() "/>
            <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>
    <changeSet id="bahmni-core-202102230936" author="Siva, Rakesh">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM global_property where property = 'bahmni.admin.csv.upload.dateFormat'
            </sqlCheck>
        </preConditions>
        <comment>Add default date format for all CSV imports</comment>
        <sql>
            insert into global_property (`property`, `property_value`, `description`, `uuid`)
            values ('bahmni.admin.csv.upload.dateFormat', 'yyyy-M-d', 'Default date format for all CSV imports', uuid());
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-202202241220" author="Rohit, Deepthi, Soorya, Kavitha">
        <preConditions onFail="MARK_RAN" >
            <not><columnExists tableName="concept_numeric" columnName="allow_decimal" /></not>
        </preConditions>
        <comment>Rename Column Precise To AllowDecimal in ConceptNumeric Table</comment>
        <sql>
            ALTER TABLE concept_numeric CHANGE precise allow_decimal tinyint(1);
        </sql>
    </changeSet>
    <changeSet id="20160329-176-update" author="Pankaj, Achinta">
        <comment>Make allow decimal checkbox checked for all numeric concept</comment>
        <sql>
            UPDATE concept_numeric SET allow_decimal = 1 WHERE allow_decimal = 0
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-201610101525-update" author="Bharat">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT COUNT(*) != 0 FROM concept WHERE datatype_id = 1 AND concept_id NOT IN (SELECT concept_id FROM concept_numeric);
            </sqlCheck>
        </preConditions>
        <comment>add concept numeric row to all numeric concepts</comment>
        <sql>
            INSERT INTO concept_numeric (concept_id,allow_decimal) (SELECT concept_id,0 FROM concept WHERE
            datatype_id  = (SELECT concept_datatype_id FROM concept_datatype WHERE name = 'Numeric')
            AND concept_id NOT IN (SELECT concept_id FROM concept_numeric));
        </sql>
    </changeSet>

    <changeSet id="Create-practitioner_type-20220722" author="BAHMNI">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM provider_attribute_type where name="practitioner_type";
            </sqlCheck>
        </preConditions>
        <comment>Adding provider attribute type of practitioner_type</comment>
        <sql>
            INSERT INTO provider_attribute_type (name, description, datatype, preferred_handler,handler_config, min_occurs, creator, date_created,
            retired, uuid)
            VALUES ("practitioner_type","list of practitioners",
            "org.openmrs.customdatatype.datatype.SpecifiedTextOptionsDatatype","org.openmrs.web.attribute.handler.SpecifiedTextOptionsDropdownHandler",",Doctor", 0, 1, NOW(), 0, UUID());
        </sql>
    </changeSet>
    <changeSet id="Update-metadatamapping_metadata_term_mapping-20220907" author="BAHMNI" >
        <preConditions onFail="CONTINUE" >
            <sqlCheck expectedResult="1">
                SELECT COUNT(*) from patient_identifier_type where name='Patient Identifier';
            </sqlCheck>
            <sqlCheck expectedResult="1">
                SELECT COUNT(*) from metadatamapping_metadata_term_mapping WHERE code="emr.primaryIdentifierType";
            </sqlCheck>
        </preConditions>
        <comment>Updating metadata_uuid in metadatamapping_metadata_term_mapping with primaryIdentifier uuid to remove exceptions in landing page of Lab Entry</comment>
        <sql>
			set @metadata_uuid = null;
			SELECT uuid INTO @metadata_uuid FROM patient_identifier_type WHERE name = "Patient Identifier";
			UPDATE metadatamapping_metadata_term_mapping SET metadata_uuid=@metadata_uuid WHERE code="emr.primaryIdentifierType";
        </sql>
    </changeSet>


    <changeSet id="bahmni-emrapi-202208101439" author="BAHMNI" >
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(c.concept_id) from concept c
                INNER join concept_name cn
                on cn.concept_id=c.concept_id and cn.name='Visit Diagnoses' and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' and c.version is null;
            </sqlCheck>
            <sqlCheck expectedResult="1">
                <!-- The below query returns the concept which has only one concept reference mapping !-->
                select count(rmap.concept_id) from concept_reference_map rmap
                INNER JOIN concept_name cn on cn.concept_id = rmap.concept_id and cn.name='Visit Diagnoses'
                and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' group by rmap.concept_id having count(*) = 1;
            </sqlCheck>
        </preConditions>
        <comment>Update version for the 'Visit Diagnoses' concept because Bahmni concept can be uniquely recognised and doens’t clash with CIEL, or other concepts</comment>
        <sql>
            SET @concept_id = 0;

            select rmap.concept_id into @concept_id from concept_reference_map rmap
            INNER JOIN concept_name cn on cn.concept_id = rmap.concept_id and cn.name='Visit Diagnoses'
            and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' group by rmap.concept_id having count(*) = 1;

            UPDATE concept set version = 'BAHMNI-CORE-1.0' where concept_id = @concept_id and version is null ;
        </sql>
    </changeSet>

    <changeSet id="bahmni-emrapi-202208101440" author="BAHMNI" >
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(c.concept_id) from concept c
                INNER join
                concept_name cn
                on cn.concept_id=c.concept_id and cn.name='Coded Diagnosis' and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' and c.version is null;
            </sqlCheck>
            <sqlCheck expectedResult="1">
                <!-- The below query returns the concept which has only one concept reference mapping !-->
                select count(rmap.concept_id) from concept_reference_map rmap
                INNER JOIN concept_name cn on cn.concept_id = rmap.concept_id and cn.name='Coded Diagnosis'
                and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' group by rmap.concept_id having count(*) = 1;
            </sqlCheck>
        </preConditions>
        <comment>Update version for the 'Coded Diagnosis' concept because Bahmni concept can be uniquely recognised and doens’t clash with CIEL, or other concepts</comment>
        <sql>
            SET @concept_id = 0;

            select rmap.concept_id into @concept_id from concept_reference_map rmap
            INNER JOIN concept_name cn on cn.concept_id = rmap.concept_id and cn.name='Coded Diagnosis'
            and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' group by rmap.concept_id having count(*) = 1;

            UPDATE concept set version='BAHMNI-CORE-1.0' where concept_id=@concept_id and version is null ;
        </sql>
    </changeSet>

    <changeSet id="bahmni-emrapi-202208101441" author="BAHMNI">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(c.concept_id) from concept c
                INNER join
                concept_name cn
                on cn.concept_id=c.concept_id and cn.name='Non-coded Diagnosis' and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' and c.version is null;
            </sqlCheck>
            <sqlCheck expectedResult="1">
                <!-- The below query returns the concept which has only one concept reference mapping !-->
                select count(rmap.concept_id) from concept_reference_map rmap
                INNER JOIN concept_name cn on cn.concept_id = rmap.concept_id and cn.name='Non-coded Diagnosis'
                and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' group by rmap.concept_id having count(*) = 1;
            </sqlCheck>
        </preConditions>
        <comment>Update version for the 'Non-Coded Diagnosis' concept because Bahmni concept can be uniquely recognised and doens’t clash with CIEL, or other concepts</comment>
        <sql>
            SET @concept_id = 0;

            select rmap.concept_id into @concept_id from concept_reference_map rmap
            INNER JOIN concept_name cn on cn.concept_id = rmap.concept_id and cn.name='Non-coded Diagnosis'
            and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' group by rmap.concept_id having count(*) = 1;

            UPDATE concept set version='BAHMNI-CORE-1.0' where concept_id=@concept_id and version is null ;
        </sql>
    </changeSet>

    <changeSet id="bahmni-emrapi-202208101442" author="BAHMNI">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(c.concept_id) from concept c
                INNER join
                concept_name cn
                on cn.concept_id=c.concept_id and cn.name='Diagnosis Certainty' and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' and c.version is null;
            </sqlCheck>
            <sqlCheck expectedResult="1">
                <!-- The below query returns the concept which has only one concept reference mapping !-->
                select count(rmap.concept_id) from concept_reference_map rmap
                INNER JOIN concept_name cn on cn.concept_id = rmap.concept_id and cn.name='Diagnosis Certainty'
                and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' group by rmap.concept_id having count(*) = 1;
            </sqlCheck>
        </preConditions>
        <comment>Update version for the 'Diagnosis Certainty' concept because Bahmni concept can be uniquely recognised and doens’t clash with CIEL, or other concepts</comment>
        <sql>
            SET @concept_id = 0;

            select rmap.concept_id into @concept_id from concept_reference_map rmap
            INNER JOIN concept_name cn on cn.concept_id = rmap.concept_id and cn.name='Diagnosis Certainty'
            and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' group by rmap.concept_id having count(*) = 1;

            UPDATE concept set version='BAHMNI-CORE-1.0' where concept_id=@concept_id and version is null ;
        </sql>
    </changeSet>

    <changeSet id="bahmni-emrapi-202208101443" author="BAHMNI">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(c.concept_id) from concept c
                INNER join
                concept_name cn
                on cn.concept_id=c.concept_id and cn.name='Diagnosis order' and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' and c.version is null;
            </sqlCheck>
            <sqlCheck expectedResult="1">
                <!-- The below query returns the concept which has only one concept reference mapping !-->
                select count(rmap.concept_id) from concept_reference_map rmap
                INNER JOIN concept_name cn on cn.concept_id = rmap.concept_id and cn.name='Diagnosis order'
                and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' group by rmap.concept_id having count(*) = 1;
            </sqlCheck>
        </preConditions>
        <comment>Update version for the 'Diagnosis order' concept because Bahmni concept can be uniquely recognised and doens’t clash with CIEL, or other concepts</comment>
        <sql>
            SET @concept_id = 0;

            select rmap.concept_id into @concept_id from concept_reference_map rmap
            INNER JOIN concept_name cn on cn.concept_id = rmap.concept_id and cn.name='Diagnosis order'
            and cn.concept_name_type='FULLY_SPECIFIED' and cn.voided=0 and cn.locale = 'en' group by rmap.concept_id having count(*) = 1;

            UPDATE concept set version='BAHMNI-CORE-1.0' where concept_id=@concept_id and version is null ;
        </sql>
    </changeSet>
    <changeSet id="emrapi-diganosis-202209121241" author="Bindu">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(*) from global_property where property='emrapi.useLegacyDiagnosisService' and property_value='FALSE';
            </sqlCheck>
        </preConditions>
        <comment>set 'emrapi.useLegacyDiagnosisService' to true to use legacy diagnosis service</comment>
        <sql>
            UPDATE global_property set property_value='TRUE' where property='emrapi.useLegacyDiagnosisService';
        </sql>
    </changeSet>
    <changeSet id="bahmni-202212131258" author="Bindu, Rohit, Deepthi">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(property) FROM global_property WHERE property='emr.primaryIdentifierType' AND property='bahmni.primaryIdentifierType';
            </sqlCheck>
        </preConditions>
        <comment>Remove global property with value 'emr.primaryIdentifierType' to avoid duplications</comment>
        <sql>
            DELETE FROM global_property WHERE property='emr.primaryIdentifierType';
        </sql>
    </changeSet>
    <changeSet id="bahmni-202212131913" author="Bindu, Rohit">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(property) FROM global_property WHERE property='bahmni.primaryIdentifierType';
            </sqlCheck>
        </preConditions>
        <comment>Update gobal property with Patient Identifier uuid</comment>
        <sql>
            SELECT uuid INTO @uuid FROM patient_identifier_type WHERE name='Patient Identifier';
            UPDATE global_property SET property_value=@uuid WHERE property='bahmni.primaryIdentifierType';
        </sql>
    </changeSet>

    <changeSet id="bahmni-202302231447" author="BAHMNI">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT count(*) FROM privilege WHERE privilege = "Create Teleconsultation";
            </sqlCheck>
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM role_privilege WHERE role = "Appointments:ManageAppointments" and privilege = "Create Teleconsultation";
            </sqlCheck>
        </preConditions>
        <comment>Adding Create Teleconsultation privilege to Appointments:ManageAppointments role</comment>
        <sql>
            INSERT INTO role_privilege(role, privilege) VALUES ("Appointments:ManageAppointments", "Create Teleconsultation");
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-202303029-BAH-2652" author="clinic-config">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(*) from order_type where name='Lab Order';
            </sqlCheck>
            <sqlCheck expectedResult="1">
                select count(*) from concept_class where name='Test';
            </sqlCheck>
            <sqlCheck expectedResult="0">
                select count(*) from order_type_class_map where order_type_id=(select order_type_id from order_type where name = 'Lab Order') and concept_class_id=(select concept_class_id from concept_class where name = 'Test');
            </sqlCheck>
        </preConditions>
        <comment>Associating Test concept classes to Lab Order order type</comment>
        <sql>
            set @order_type_id = '';
            set @test_class = '';

            select order_type_id into @order_type_id from order_type where name = 'Lab Order';
            select concept_class_id into @test_class from concept_class where name = 'Test';

            insert into order_type_class_map(order_type_id, concept_class_id) values(@order_type_id,@test_class);
        </sql>
    </changeSet>
    <changeSet id="clinic-config-BAH2652-2932023" author="clinic-config">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT COUNT(*) FROM concept_class where name = 'Radiology/Imaging Procedure';
            </sqlCheck>
        </preConditions>
        <comment>Add concept class for Radiology/Imaging Procedure</comment>
        <sql>
            insert into concept_class (name, description, creator, date_created, retired, uuid)
            values ('Radiology/Imaging Procedure', 'Radiology Orders', 1, NOW(), 0, 'c6664c16-16b4-4bf4-91da-93f2ac88a0eb');
        </sql>
    </changeSet>
    <changeSet id="bahmni-core-20230329-bah-265229032023" author="clinic-config">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                select count(*) from order_type where name='Radiology Order';
            </sqlCheck>
            <sqlCheck expectedResult="1">
                select count(*) from concept_class where name='Radiology/Imaging Procedure';
            </sqlCheck>
            <sqlCheck expectedResult="0">
                select count(*) from order_type_class_map where order_type_id=(select order_type_id from order_type where name = 'Radiology Order') and concept_class_id=(select concept_class_id from concept_class where name = 'Radiology/Imaging Procedure');
            </sqlCheck>
        </preConditions>
        <comment>Associating Radiology/Imaging Procedure concept class to Radiology Order order type</comment>
        <sql>
            set @radiology_order_type_id = '';
            set @radiology_imaging = '';

            select order_type_id into @radiology_order_type_id from order_type where name = 'Radiology Order';
            select concept_class_id into @radiology_imaging from concept_class where name = 'Radiology/Imaging Procedure';

            insert into order_type_class_map(order_type_id, concept_class_id) values(@radiology_order_type_id,@radiology_imaging);
        </sql>
    </changeSet>
    <changeSet author="Bindu" id="notes-202307091607">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="notes"/>
            </not>
        </preConditions>
        <createTable tableName="notes">
            <column autoIncrement="true" name="note_id" type="INT">
                <constraints nullable="false" primaryKey="true"/>
            </column>
            <column name="note_type_id" type="INT"/>
            <column name="note_text" type="TEXT">
                <constraints nullable="false"/>
            </column>
            <column name="date_created" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column name="note_date" type="datetime">
                <constraints nullable="false"/>
            </column>
            <column defaultValueNumeric="0" name="creator" type="INT">
                <constraints nullable="false"/>
            </column>
            <column name="voided_by" type="INT"/>
            <column name="location_id" type="INT">
            </column>
            <column name="changed_by" type="INT"/>
            <column name="date_changed" type="datetime"/>
            <column name="date_voided" type="datetime"/>
            <column name="void_reason" type="TEXT"/>
            <column defaultValueBoolean="false" name="is_voided" type="BOOLEAN">
                <constraints nullable="false" />
            </column>
            <column name="uuid" type="CHAR(38)">
                <constraints nullable="false" unique="true"/>
            </column>
        </createTable>

        <addNotNullConstraint tableName="notes" columnName="uuid" columnDataType="char(38)" />

        <addForeignKeyConstraint baseColumnNames="creator"
                                 baseTableName="notes" constraintName="user_who_created_notes"
                                 referencedColumnNames="user_id" referencedTableName="users" />

        <addForeignKeyConstraint baseColumnNames="changed_by"
                                 baseTableName="notes" constraintName="user_who_changed_notes"
                                 referencedColumnNames="user_id" referencedTableName="users" />

        <addForeignKeyConstraint baseColumnNames="location_id"
                                 baseTableName="notes" constraintName="location_notes"
                                 referencedColumnNames="location_id" referencedTableName="location" />

        <createIndex tableName="notes" unique="true" indexName="notes_uuid_index" >
            <column name="uuid" />
        </createIndex>

    </changeSet>
    <changeSet author="Bindu" id="note-type-202307101601">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="note_type"/>
            </not>
        </preConditions>
        <createTable tableName="note_type">
            <column defaultValueNumeric="0" name="note_type_id" type="INT">
                <constraints nullable="false" primaryKey="true"/>
            </column>
            <column name="name" type="VARCHAR(50)">
            <constraints nullable="false"/>
            </column>
            <column name="description" type="TEXT">
                <constraints nullable="true"/>
            </column>
            <column name="uuid" type="CHAR(38)">
                <constraints nullable="false" unique="true"/>
            </column>
        </createTable>

        <addNotNullConstraint tableName="note_type" columnName="uuid" columnDataType="char(38)" />

        <createIndex tableName="note_type" unique="true" indexName="note_type_uuid_index" >
            <column name="uuid" />
        </createIndex>
    </changeSet>
    <changeSet id="note-name-202307241600" author="Bindu">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                select count(*) from note_type where name = 'OT module';
            </sqlCheck>
        </preConditions>
        <comment> Adding note type </comment>
        <sql>
            insert into note_type (name, description, uuid) values ('OT module', 'OT module', uuid());
        </sql>
    </changeSet>
    <include file="addAtomfeedMigrations.xml"/>
    <changeSet id="provider-attribute-login-locations-202307191200" author="BAHMNI">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0">
                SELECT count(*) FROM provider_attribute_type where name="Login Locations";
            </sqlCheck>
        </preConditions>
        <comment>Adding provider attribute type - Login Locations</comment>
        <sql>
            INSERT INTO provider_attribute_type (name, description, datatype, min_occurs, creator, date_created, retired, uuid)
            VALUES ("Login Locations","Specific locations for providers to login", "org.openmrs.customdatatype.datatype.LocationDatatype", 0, 1, NOW(), 0, UUID());
        </sql>
    </changeSet>

    <changeSet id="bahmni-core-20231206-bah-3336" author="BAHMNI">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="1">
                SELECT COUNT(*) FROM program_attribute_type where name = 'Stage' AND datatype =
                'org.bahmni.module.bahmnicore.customdatatype.datatype.CodedConceptDatatype';
            </sqlCheck>
        </preConditions>
        <comment>Update datatype of patient stage program attribute type</comment>
        <sql>
            UPDATE program_attribute_type SET datatype = 'org.openmrs.customdatatype.datatype.ConceptDatatype' WHERE
            name = 'Stage' AND datatype = 'org.bahmni.module.bahmnicore.customdatatype.datatype.CodedConceptDatatype';
        </sql>
    </changeSet>
    <changeSet id="bahmni-WardsList-Update-202406271807" author="Bahmni">
        <comment>Update the wards list sql to optimize for MySQL 8 - Bahmni Standard 1.0</comment>
        <sqlFile path="V1_99_WardsListSql.sql"/>
    </changeSet>

</databaseChangeLog>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy