Mercurial > hg > orthanc-databases
comparison PostgreSQL/Plugins/CreateInstance.sql @ 434:23c7af6f671a pg-transactions
DeleteResource does not need the RemainingAncestor table anymore
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 13 Dec 2023 16:52:06 +0100 |
parents | 4d0bacbd0fba |
children |
comparison
equal
deleted
inserted
replaced
433:5964ce6385a5 | 434:23c7af6f671a |
---|---|
22 isNewSeries := 1; | 22 isNewSeries := 1; |
23 isNewInstance := 1; | 23 isNewInstance := 1; |
24 | 24 |
25 BEGIN | 25 BEGIN |
26 INSERT INTO "resources" VALUES (DEFAULT, 0, patient, NULL); | 26 INSERT INTO "resources" VALUES (DEFAULT, 0, patient, NULL); |
27 exception | 27 EXCEPTION |
28 when unique_violation then | 28 WHEN unique_violation THEN |
29 isNewPatient := 0; | 29 isNewPatient := 0; |
30 end; | 30 END; |
31 select internalid into patientKey from "resources" where publicId=patient and resourcetype = 0; | 31 SELECT internalid INTO patientKey FROM "resources" WHERE publicId=patient AND resourcetype = 0; |
32 | 32 |
33 BEGIN | 33 BEGIN |
34 INSERT INTO "resources" VALUES (DEFAULT, 1, study, patientKey); | 34 INSERT INTO "resources" VALUES (DEFAULT, 1, study, patientKey); |
35 exception | 35 EXCEPTION |
36 when unique_violation then | 36 WHEN unique_violation THEN |
37 isNewStudy := 0; | 37 isNewStudy := 0; |
38 end; | 38 END; |
39 select internalid into studyKey from "resources" where publicId=study and resourcetype = 1; | 39 SELECT internalid INTO studyKey FROM "resources" WHERE publicId=study AND resourcetype = 1; |
40 | 40 |
41 BEGIN | 41 BEGIN |
42 INSERT INTO "resources" VALUES (DEFAULT, 2, series, studyKey); | 42 INSERT INTO "resources" VALUES (DEFAULT, 2, series, studyKey); |
43 exception | 43 EXCEPTION |
44 when unique_violation then | 44 WHEN unique_violation THEN |
45 isNewSeries := 0; | 45 isNewSeries := 0; |
46 end; | 46 END; |
47 select internalid into seriesKey from "resources" where publicId=series and resourcetype = 2; | 47 SELECT internalid INTO seriesKey FROM "resources" WHERE publicId=series AND resourcetype = 2; |
48 | 48 |
49 BEGIN | 49 BEGIN |
50 INSERT INTO "resources" VALUES (DEFAULT, 3, instance, seriesKey); | 50 INSERT INTO "resources" VALUES (DEFAULT, 3, instance, seriesKey); |
51 exception | 51 EXCEPTION |
52 when unique_violation then | 52 WHEN unique_violation THEN |
53 isNewInstance := 0; | 53 isNewInstance := 0; |
54 end; | 54 END; |
55 select internalid into instanceKey from "resources" where publicId=instance and resourcetype = 3; | 55 SELECT internalid INTO instanceKey FROM "resources" WHERE publicId=instance AND resourcetype = 3; |
56 | 56 |
57 IF isNewInstance > 0 THEN | 57 IF isNewInstance > 0 THEN |
58 -- Move the patient to the end of the recycling order | 58 -- Move the patient to the end of the recycling order |
59 SELECT seq FROM PatientRecyclingOrder WHERE patientId = patientKey INTO patientSeq; | 59 SELECT seq FROM PatientRecyclingOrder WHERE patientId = patientKey INTO patientSeq; |
60 | 60 |