Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ ALTER TABLE ehr_compliancedb.requirementsperemployee DROP CONSTRAINT fk_requirem
ALTER TABLE ehr_compliancedb.sopbycategory DROP CONSTRAINT fk_sopbycategory_category;
ALTER TABLE ehr_compliancedb.sopdates DROP CONSTRAINT fk_sopdates_employeeid;

SELECT core.fn_dropifexists('requirements', 'ehr_compliancedb', 'CONSTRAINT', 'PK_requirements');
ALTER TABLE ehr_compliancedb.requirements DROP CONSTRAINT IF EXISTS PK_requirements;
ALTER TABLE ehr_compliancedb.requirements ADD CONSTRAINT pk_requirements PRIMARY KEY (rowid);

ALTER TABLE ehr_compliancedb.requirements ADD datedisabled TIMESTAMP;
Expand Down
22 changes: 10 additions & 12 deletions ehr/resources/schemas/dbscripts/postgresql/ehr-0.000-25.000.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1309,22 +1309,20 @@ ALTER TABLE ehr.encounter_participants ADD taskid entityid;
truncate table ehr.encounter_participants;

--this might have been created by EHRManager
SELECT core.fn_dropifexists('encounter_participants', 'ehr', 'INDEX', 'encounter_participants_objectid');
DROP INDEX IF EXISTS ehr.encounter_participants_objectid;

ALTER TABLE ehr.encounter_participants ALTER COLUMN objectid SET NOT NULL;

SELECT core.fn_dropifexists('encounter_participants', 'ehr', 'CONSTRAINT', 'pk_encounter_participants');
ALTER TABLE ehr.encounter_participants DROP CONSTRAINT IF EXISTS pk_encounter_participants;

ALTER TABLE ehr.encounter_participants ADD CONSTRAINT pk_encounter_participants PRIMARY KEY (objectid);

SELECT core.fn_dropifexists('encounter_participants', 'ehr', 'INDEX', 'encounter_participants_container_rowid_id');
SELECT core.fn_dropifexists('encounter_participants', 'ehr', 'INDEX', 'encounter_participants_container_rowid_parentid');
DROP INDEX IF EXISTS ehr.encounter_participants_container_rowid_id;
DROP INDEX IF EXISTS ehr.encounter_participants_container_rowid_parentid;

ALTER TABLE ehr.encounter_participants DROP COLUMN rowid;

--this might have been created by EHRManager
SELECT core.fn_dropifexists('encounter_participants', 'ehr', 'INDEX', 'encounter_participants_objectid');
SELECT core.fn_dropifexists('encounter_participants', 'ehr', 'CONSTRAINT', 'pk_encounter_participants');
ALTER TABLE ehr.encounter_participants DROP CONSTRAINT IF EXISTS pk_encounter_participants;

ALTER TABLE ehr.encounter_participants ALTER COLUMN objectid TYPE VARCHAR(60);

Expand All @@ -1333,10 +1331,10 @@ ALTER TABLE ehr.encounter_participants ADD CONSTRAINT pk_encounter_participants
ALTER TABLE ehr.project ADD shortname varchar(200);

--this might have been created by EHRManager
SELECT core.fn_dropifexists('encounter_summaries', 'ehr', 'index', 'encounter_summaries_objectid');
SELECT core.fn_dropifexists('encounter_summaries', 'ehr', 'index', 'encounter_summaries_parentid_rowid_container_id');
SELECT core.fn_dropifexists('encounter_summaries', 'ehr', 'index', 'encounter_summaries_container_rowid');
SELECT core.fn_dropifexists('encounter_summaries', 'ehr', 'constraint', 'PK_encounter_summaries');
DROP INDEX IF EXISTS ehr.encounter_summaries_objectid;
DROP INDEX IF EXISTS ehr.encounter_summaries_parentid_rowid_container_id;
DROP INDEX IF EXISTS ehr.encounter_summaries_container_rowid;
ALTER TABLE ehr.encounter_summaries DROP CONSTRAINT IF EXISTS PK_encounter_summaries;

ALTER TABLE ehr.encounter_summaries ADD taskid entityid;
ALTER TABLE ehr.encounter_summaries ALTER COLUMN objectid SET NOT NULL;
Expand Down Expand Up @@ -1498,7 +1496,7 @@ SELECT ehr.handleUpgrade();

DROP FUNCTION ehr.handleUpgrade();

SELECT core.fn_dropifexists('treatment_times', 'ehr', 'Index', 'IDX_treatment_times_treatmentid');
DROP INDEX IF EXISTS ehr.IDX_treatment_times_treatmentid;

CREATE INDEX IDX_treatment_times_treatmentid ON ehr.treatment_times (treatmentid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9331,7 +9331,7 @@ UPDATE ehr_lookups.procedure_default_treatments set dosage_units = null;
ALTER TABLE ehr_lookups.snomed_subsets ADD container entityid;
ALTER TABLE ehr_lookups.snomed_subsets ADD rowid serial;

SELECT core.fn_dropifexists('snomed_subsets', 'ehr_lookups', 'CONSTRAINT', 'PK_snomed_subsets');
ALTER TABLE ehr_lookups.snomed_subsets DROP CONSTRAINT IF EXISTS PK_snomed_subsets;
ALTER TABLE ehr_lookups.snomed_subsets ADD CONSTRAINT pk_snomed_subsets PRIMARY KEY (rowid);

--upgrade path for WNPRC
Expand All @@ -9356,7 +9356,7 @@ ALTER TABLE ehr_lookups.snomed ADD container ENTITYID;
--upgrade path for WNPRC
UPDATE ehr_lookups.snomed SET container = (SELECT c.entityid from core.containers c LEFT JOIN core.Containers c2 on (c.Parent = c2.EntityId) WHERE c.name = 'EHR' and c2.name = 'WNPRC');

SELECT core.fn_dropifexists('snomed', 'ehr_lookups', 'CONSTRAINT', 'PK_snomed');
ALTER TABLE ehr_lookups.snomed DROP CONSTRAINT IF EXISTS PK_snomed;
ALTER TABLE ehr_lookups.snomed ADD rowid SERIAL;

ALTER TABLE ehr_lookups.snomed ADD CONSTRAINT pk_snomed PRIMARY KEY (rowid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ ALTER TABLE ehr_billing.aliases DROP COLUMN aliasEnabled;
ALTER TABLE ehr_billing.aliases ADD isAcceptingCharges boolean DEFAULT true;

-- dropping to avoid duplicate index, EHR_BILLING_ALIASES_INDEX includes index to container
SELECT core.fn_dropifexists ('aliases', 'ehr_billing', 'INDEX', 'ehr_billing_aliases_container_index');
DROP INDEX IF EXISTS ehr_billing.ehr_billing_aliases_container_index;

-- index on lsid col in extensible tables
SELECT core.fn_dropifexists ('aliases', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_ALIASES_LSID');
CREATE INDEX IX_EHR_BILLING_ALIASES_LSID ON ehr_billing.aliases (lsid);

-- Convert from a plain index to a unique constraint
SELECT core.fn_dropifexists ('aliases', 'ehr_billing', 'INDEX', 'EHR_BILLING_ALIASES_INDEX');
DROP INDEX IF EXISTS ehr_billing.EHR_BILLING_ALIASES_INDEX;

ALTER TABLE ehr_billing.aliases ADD CONSTRAINT UNIQUE_ALIAS UNIQUE (Container, alias);

Expand Down Expand Up @@ -82,11 +81,8 @@ ALTER TABLE ehr_billing.chargeRates ADD COLUMN LSID LSIDtype;

ALTER TABLE ehr_billing.chargeRates ALTER COLUMN unitCost TYPE DECIMAL(13,2);
-- constraint and index in chargeRates table
SELECT core.fn_dropifexists ('chargeRates', 'ehr_billing', 'CONSTRAINT', 'FK_EHR_BILLING_CHARGE_RATES_CHARGEID');
SELECT core.fn_dropifexists ('chargeRates', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_CHARGE_RATES_CHARGEID');
CREATE INDEX IX_EHR_BILLING_CHARGE_RATES_CHARGEID ON ehr_billing.chargeRates (chargeId);

SELECT core.fn_dropifexists ('chargeRates', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_CHARGE_RATES_LSID');
CREATE INDEX IX_EHR_BILLING_CHARGE_RATES_LSID ON ehr_billing.chargeRates (lsid);

--this table contains records of misc charges that have happened that cannot otherwise be
Expand Down Expand Up @@ -136,9 +132,9 @@ CREATE INDEX EHR_BILLING_MISC_CHARGES_CONTAINER_INDEX ON ehr_billing.miscCharges

ALTER TABLE ehr_billing.miscCharges ADD COLUMN Lsid LSIDType;

SELECT core.fn_dropifexists('miscCharges', 'ehr_billing', 'CONSTRAINT', 'FK_EHR_BILLING_MISC_CHARGES_CONTAINER');
ALTER TABLE ehr_billing.miscCharges DROP CONSTRAINT IF EXISTS FK_EHR_BILLING_MISC_CHARGES_CONTAINER;

SELECT core.fn_dropifexists('miscCharges', 'ehr_billing', 'INDEX', 'EHR_BILLING_MISC_CHARGES_CONTAINER_INDEX');
DROP INDEX IF EXISTS ehr_billing.EHR_BILLING_MISC_CHARGES_CONTAINER_INDEX;


ALTER TABLE ehr_billing.miscCharges ADD CONSTRAINT FK_EHR_BILLING_MISC_CHARGES_CONTAINER FOREIGN KEY (Container) REFERENCES core.Containers (EntityId);
Expand All @@ -149,14 +145,10 @@ ALTER TABLE ehr_billing.miscCharges ALTER COLUMN unitCost TYPE DECIMAL(13,2);
ALTER TABLE ehr_billing.miscCharges ADD investigator varchar(100);

-- constraint and index in miscCharges
SELECT core.fn_dropifexists ('misccharges', 'ehr_billing', 'CONSTRAINT', 'FK_EHR_BILLING_MISC_CHARGES_CHARGEID');
SELECT core.fn_dropifexists ('misccharges', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_MISC_CHARGES_CHARGEID');
CREATE INDEX IX_EHR_BILLING_MISC_CHARGES_CHARGEID ON ehr_billing.misccharges (chargeid);

SELECT core.fn_dropifexists ('misccharges', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_MISC_CHARGES_PROJECT');
CREATE INDEX IX_EHR_BILLING_MISC_CHARGES_PROJECT ON ehr_billing.misccharges (project);

SELECT core.fn_dropifexists ('miscCharges', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_MISC_CHARGES_LSID');
CREATE INDEX IX_EHR_BILLING_MISC_CHARGES_LSID ON ehr_billing.miscCharges (lsid);

ALTER TABLE ehr_billing.miscCharges ALTER COLUMN creditedaccount TYPE varchar(200);
Expand Down Expand Up @@ -191,12 +183,11 @@ CREATE INDEX EHR_BILLING_INVOICE_RUNS_CONTAINER_INDEX ON ehr_billing.invoiceRuns
ALTER TABLE ehr_billing.invoiceRuns DROP invoiceNumber;

ALTER TABLE ehr_billing.invoiceruns ADD COLUMN Lsid LSIDType;
SELECT core.fn_dropifexists('invoiceRuns', 'ehr_billing', 'CONSTRAINT', 'FK_EHR_BILLING_INVOICE_RUNS_CONTAINER');
SELECT core.fn_dropifexists('invoiceRuns', 'ehr_billing', 'INDEX', 'EHR_BILLING_INVOICE_RUNS_CONTAINER_INDEX');
ALTER TABLE ehr_billing.invoiceRuns DROP CONSTRAINT IF EXISTS FK_EHR_BILLING_INVOICE_RUNS_CONTAINER;
DROP INDEX IF EXISTS ehr_billing.EHR_BILLING_INVOICE_RUNS_CONTAINER_INDEX;
ALTER TABLE ehr_billing.invoiceRuns ADD CONSTRAINT FK_EHR_BILLING_INVOICE_RUNS_CONTAINER FOREIGN KEY (Container) REFERENCES core.Containers (EntityId);
CREATE INDEX EHR_BILLING_INVOICE_RUNS_CONTAINER_INDEX ON ehr_billing.invoiceRuns (Container);

SELECT core.fn_dropifexists ('invoiceRuns', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_INVOICE_RUNS_LSID');
CREATE INDEX IX_EHR_BILLING_INVOICE_RUNS_LSID ON ehr_billing.invoiceRuns (lsid);

--this table contains a snapshot of items actually invoiced, which will draw from many places in the animal record
Expand Down Expand Up @@ -260,34 +251,28 @@ ALTER TABLE ehr_billing.invoicedItems ALTER COLUMN invoiceNumber SET NOT NULL;
CREATE INDEX EHR_BILLING_INVOICEDITEMS_INVNUM_INDEX ON ehr_billing.invoicedItems (invoiceNumber);

ALTER TABLE ehr_billing.invoiceditems ADD COLUMN Lsid LSIDType;
SELECT core.fn_dropifexists('invoicedItems', 'ehr_billing', 'CONSTRAINT', 'FK_EHR_BILLING_INVOICED_ITEMS_CONTAINER');
SELECT core.fn_dropifexists('invoicedItems', 'ehr_billing', 'INDEX', 'EHR_BILLING_INVOICED_ITEMS_CONTAINER_INDEX');
ALTER TABLE ehr_billing.invoicedItems DROP CONSTRAINT IF EXISTS FK_EHR_BILLING_INVOICED_ITEMS_CONTAINER;
DROP INDEX IF EXISTS ehr_billing.EHR_BILLING_INVOICED_ITEMS_CONTAINER_INDEX;
ALTER TABLE ehr_billing.invoicedItems ADD CONSTRAINT FK_EHR_BILLING_INVOICED_ITEMS_CONTAINER FOREIGN KEY (Container) REFERENCES core.Containers (EntityId);
CREATE INDEX EHR_BILLING_INVOICED_ITEMS_CONTAINER_INDEX ON ehr_billing.invoicedItems (Container);

SELECT core.fn_dropifexists('invoiceRuns', 'ehr_billing', 'COLUMN', 'invoiceNumber');
SELECT core.fn_dropifexists('invoicedItems', 'ehr_billing', 'COLUMN', 'invoiceNumber');
ALTER TABLE ehr_billing.invoicedItems DROP COLUMN IF EXISTS invoiceNumber CASCADE;

TRUNCATE TABLE ehr_billing.invoicedItems;
ALTER TABLE ehr_billing.invoicedItems ADD COLUMN invoiceNumber varchar(20) NOT NULL;

SELECT core.fn_dropifexists('invoicedItems', 'ehr_billing', 'CONSTRAINT', 'EHR_BILLING_INVOICEDITEMS_INVNUM_INDEX');

CREATE INDEX EHR_BILLING_INVOICEDITEMS_INVNUM_INDEX ON ehr_billing.invoicedItems (invoiceNumber);

ALTER TABLE ehr_billing.invoicedItems ALTER COLUMN unitCost TYPE DECIMAL(13,2);
ALTER TABLE ehr_billing.invoicedItems ALTER COLUMN totalCost TYPE DECIMAL(13,2);

-- constraint and index in invoicedItems
SELECT core.fn_dropifexists ('invoiceditems', 'ehr_billing', 'CONSTRAINT', 'FK_EHR_BILLING_INVOICED_ITEMS_CHARGEID');
SELECT core.fn_dropifexists ('invoiceditems', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_INVOICED_ITEMS_CHARGEID');
CREATE INDEX IX_EHR_BILLING_INVOICED_ITEMS_CHARGEID ON ehr_billing.invoiceditems (chargeid);

SELECT core.fn_dropifexists ('invoicedItems', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_INVOICED_ITEMS_LSID');
CREATE INDEX IX_EHR_BILLING_INVOICED_ITEMS_LSID ON ehr_billing.invoicedItems (lsid);

-- drop Index and Constraints
SELECT core.fn_dropifexists ('invoicedItems', 'ehr_billing', 'INDEX', 'EHR_BILLING_INVOICEDITEMS_INVNUM_INDEX');
DROP INDEX IF EXISTS ehr_billing.EHR_BILLING_INVOICEDITEMS_INVNUM_INDEX;

-- Modify invoiceNumber
ALTER TABLE ehr_billing.invoicedItems ALTER COLUMN invoiceNumber TYPE varchar(100);
Expand Down Expand Up @@ -337,7 +322,6 @@ ALTER TABLE ehr_billing.invoiceditems ADD CONSTRAINT FK_EHR_BILLING_INVOICED_ITE

ALTER TABLE ehr_billing.misccharges ADD CONSTRAINT FK_EHR_BILLING_MISC_CHARGES_CHARGEID FOREIGN KEY (chargeid) REFERENCES ehr_billing.chargeableItems (rowid);

SELECT core.fn_dropifexists ('chargeableItems', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_CHARGEABLE_ITEMS_LSID');
CREATE INDEX IX_EHR_BILLING_CHARGEABLE_ITEMS_LSID ON ehr_billing.chargeableItems (lsid);

CREATE TABLE ehr_billing.chargeRateExemptions
Expand All @@ -361,7 +345,6 @@ CREATE TABLE ehr_billing.chargeRateExemptions
);

CREATE INDEX EHR_BILLING_CHARGERATEEXEMPTIONS_CONTAINER_INDEX ON ehr_billing.chargeRateExemptions (Container);
SELECT core.fn_dropifexists ('chargeRateExemptions', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_CHARGE_RATE_EXEMPTIONS_LSID');
CREATE INDEX IX_EHR_BILLING_CHARGE_RATE_EXEMPTIONS_LSID ON ehr_billing.chargeRateExemptions (lsid);

CREATE TABLE ehr_billing.chargeUnits
Expand All @@ -385,7 +368,6 @@ CREATE TABLE ehr_billing.chargeUnits
);

CREATE INDEX EHR_BILLING_CHARGEUNITS_CONTAINER_INDEX ON ehr_billing.chargeUnits (Container);
SELECT core.fn_dropifexists ('chargeUnits', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_CHARGE_UNITS_LSID');
CREATE INDEX IX_EHR_BILLING_CHARGE_UNITS_LSID ON ehr_billing.chargeUnits (lsid);

CREATE TABLE ehr_billing.invoice
Expand Down Expand Up @@ -419,31 +401,25 @@ ALTER TABLE ehr_billing.invoice ALTER COLUMN invoiceAmount TYPE DECIMAL(13,2);
ALTER TABLE ehr_billing.invoice ALTER COLUMN paymentAmountReceived TYPE DECIMAL(13,2);
ALTER TABLE ehr_billing.invoice ADD balanceDue DECIMAL(13,2);
-- constraint and index in invoice table
SELECT core.fn_dropifexists ('invoice', 'ehr_billing', 'CONSTRAINT', 'FK_EHR_BILLING_INVOICE_INVOICERUNID');
ALTER TABLE ehr_billing.invoice ADD CONSTRAINT FK_EHR_BILLING_INVOICE_INVOICERUNID FOREIGN KEY (invoicerunid) REFERENCES ehr_billing.invoiceRuns (objectid);

SELECT core.fn_dropifexists ('invoice', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_INVOICE_INVOICERUNID');
CREATE INDEX IX_EHR_BILLING_INVOICE_INVOICERUNID ON ehr_billing.invoice (invoicerunid);

SELECT core.fn_dropifexists ('invoice', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_INVOICE_ACCOUNTNUMBER');
CREATE INDEX IX_EHR_BILLING_INVOICE_ACCOUNTNUMBER ON ehr_billing.invoice (accountnumber);

SELECT core.fn_dropifexists ('invoice', 'ehr_billing', 'CONSTRAINT', 'UQ_EHR_BILLING_INVOICE_INVOICENUMBER');
ALTER TABLE ehr_billing.invoice ADD CONSTRAINT UQ_EHR_BILLING_INVOICE_INVOICENUMBER UNIQUE (invoicenumber);

SELECT core.fn_dropifexists ('invoice', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_INVOICE_INVOICENUMBER');
CREATE INDEX IX_EHR_BILLING_INVOICE_INVOICENUMBER ON ehr_billing.invoice (invoicenumber);

SELECT core.fn_dropifexists ('invoice', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_INVOICE_LSID');
CREATE INDEX IX_EHR_BILLING_INVOICE_LSID ON ehr_billing.invoice (lsid);

SELECT core.fn_dropifexists ('invoice', 'ehr_billing', 'CONSTRAINT', 'PK_EHR_BILLING_INVOICE_INVNUM');
ALTER TABLE ehr_billing.invoice DROP CONSTRAINT IF EXISTS PK_EHR_BILLING_INVOICE_INVNUM;

SELECT core.fn_dropifexists ('invoice', 'ehr_billing', 'CONSTRAINT', 'UNIQUE_INVOICE_NUM');
ALTER TABLE ehr_billing.invoice DROP CONSTRAINT IF EXISTS UNIQUE_INVOICE_NUM;

SELECT core.fn_dropifexists ('invoice', 'ehr_billing', 'CONSTRAINT', 'UQ_EHR_BILLING_INVOICE_INVOICENUMBER');
ALTER TABLE ehr_billing.invoice DROP CONSTRAINT IF EXISTS UQ_EHR_BILLING_INVOICE_INVOICENUMBER;

SELECT core.fn_dropifexists ('invoice', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_INVOICE_INVOICENUMBER');
DROP INDEX IF EXISTS ehr_billing.IX_EHR_BILLING_INVOICE_INVOICENUMBER;

ALTER TABLE ehr_billing.invoice ALTER COLUMN invoiceNumber TYPE varchar(100);

Expand Down Expand Up @@ -502,13 +478,10 @@ CREATE TABLE ehr_billing.dataAccess
CREATE INDEX EHR_BILLING_DATA_ACCESS_CONTAINER_INDEX ON ehr_billing.dataAccess (Container);

-- constraint and index in dataaccess table
SELECT core.fn_dropifexists ('dataaccess', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_DATA_ACCESS_PROJECT');
CREATE INDEX IX_EHR_BILLING_DATA_ACCESS_PROJECT ON ehr_billing.dataaccess (project);

SELECT core.fn_dropifexists ('dataaccess', 'ehr_billing', 'CONSTRAINT', 'FK_EHR_BILLING_DATA_ACCESS_USERID');
ALTER TABLE ehr_billing.dataaccess ADD CONSTRAINT FK_EHR_BILLING_DATA_ACCESS_USERID FOREIGN KEY (userid) REFERENCES core.Usersdata (UserId);

SELECT core.fn_dropifexists ('dataaccess', 'ehr_billing', 'INDEX', 'IX_EHR_BILLING_DATA_ACCESS_USERID');
CREATE INDEX IX_EHR_BILLING_DATA_ACCESS_USERID ON ehr_billing.dataaccess (userid);

CREATE TABLE ehr_billing.fiscalAuthorities
Expand Down