diff OrthancServer/PrepareDatabase.sql @ 262:2354560daf2f

primitives for recycling patients
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Dec 2012 12:56:27 +0100
parents bd009f0b1931
children d384af918264
line wrap: on
line diff
--- a/OrthancServer/PrepareDatabase.sql	Wed Dec 05 13:56:53 2012 +0100
+++ b/OrthancServer/PrepareDatabase.sql	Fri Dec 07 12:56:27 2012 +0100
@@ -55,9 +55,15 @@
        date TEXT
        ); 
 
+CREATE TABLE PatientRecyclingOrder(
+       seq INTEGER PRIMARY KEY AUTOINCREMENT,
+       patientId INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE
+       );
+
 CREATE INDEX ChildrenIndex ON Resources(parentId);
 CREATE INDEX PublicIndex ON Resources(publicId);
 CREATE INDEX ResourceTypeIndex ON Resources(resourceType);
+CREATE INDEX PatientRecyclingIndex ON PatientRecyclingOrder(patientId);
 
 CREATE INDEX MainDicomTagsIndex1 ON MainDicomTags(id);
 CREATE INDEX MainDicomTagsIndex2 ON MainDicomTags(tagGroup, tagElement);
@@ -86,6 +92,14 @@
   DELETE FROM Resources WHERE internalId = old.parentId;
 END;
 
+CREATE TRIGGER PatientAdded
+AFTER INSERT ON Resources
+FOR EACH ROW WHEN new.resourceType = 1  -- "1" corresponds to "ResourceType_Patient" in C++
+BEGIN
+  INSERT INTO PatientRecyclingOrder VALUES (NULL, new.internalId);
+END;
+
+
 -- Set the version of the database schema
 -- The "1" corresponds to the "GlobalProperty_DatabaseSchemaVersion" enumeration
-INSERT INTO GlobalProperties VALUES (1, "2");
+INSERT INTO GlobalProperties VALUES (1, "3");