annotate PerfsDb/DbPopulator.py @ 156:f1a75985caa8

first Db test framework - work in progress
author am@osimis.io
date Thu, 16 Aug 2018 17:13:32 +0200
parents
children df1f9946571c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
1 import typing
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
2 from orthancRestApi import OrthancClient
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
3
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
4 from DbSize import DbSize
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
5
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
6 class DbPopulator:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
7
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
8 def __init__(self, orthanc: OrthancClient, dbSize: DbSize):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
9 self._orthanc = orthanc
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
10 self._dbSize = dbSize
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
11 self._sourceInstanceId = None
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
12
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
13 def populate(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
14 self._sourceInstanceId = self._orthanc.uploadDicomFile("../Database/DummyCT.dcm")
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
15
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
16 if self._dbSize == DbSize.Small:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
17 patientCount = 3
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
18 smallStudiesPerPatient = 2
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
19 largeStudiesPerPatient = 1
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
20 else:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
21 patientCount = 100
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
22 smallStudiesPerPatient = 4
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
23 largeStudiesPerPatient = 8
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
24
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
25 # data that are the same in small and large DBs (and that can be used in tests for comparing the same things !!)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
26
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
27 # used in TestFindStudyByPatientId5Results
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
28 self.createStudy(studyIndex=99994, patientIndex=99998, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
29 self.createStudy(studyIndex=99995, patientIndex=99998, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
30 self.createStudy(studyIndex=99996, patientIndex=99998, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
31 self.createStudy(studyIndex=99997, patientIndex=99998, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
32 self.createStudy(studyIndex=99998, patientIndex=99998, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
33
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
34 # used in TestFindStudyByStudyDescription1Result
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
35 # used in TestFindStudyByPatientId1Result
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
36 self.createStudy(studyIndex=99999, patientIndex=99999, seriesCount=1, instancesPerSeries=1)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
37
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
38 # data to make the DB "large" or "small"
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
39 for patientIndex in range(0, patientCount):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
40 studyIndex=0
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
41 print("Generating data for patient " + str(patientIndex))
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
42 for i in range(0, smallStudiesPerPatient):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
43 print("Generating small study " + str(i))
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
44 self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=2, instancesPerSeries=2)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
45 studyIndex+=1
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
46 for i in range(0, largeStudiesPerPatient):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
47 print("Generating large study " + str(i))
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
48 self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=4, instancesPerSeries=500)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
49 studyIndex+=1
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
50
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
51
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
52
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
53 print("Generation completed")
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
54
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
55 def createStudy(self, studyIndex: int, patientIndex: int, seriesCount: int, instancesPerSeries: int):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
56 for seriesIndex in range(0, seriesCount):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
57 for instanceIndex in range(0, instancesPerSeries):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
58 dicomFile = self.createDicomFile(patientIndex=patientIndex, studyIndex=studyIndex, seriesIndex=seriesIndex, instanceIndex=instanceIndex)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
59 self._orthanc.uploadDicom(dicomFile)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
60
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
61 def createDicomFile(self, patientIndex: int, studyIndex: int, seriesIndex: int, instanceIndex: int) -> object:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
62 return self._orthanc.instances.modify(
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
63 instanceId=self._sourceInstanceId,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
64 replaceTags={
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
65 "PatientName": "Patient-" + str(patientIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
66 "PatientID": str(patientIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
67 "StudyDescription": str(patientIndex) + "-" + str(studyIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
68 "SeriesDescription": str(patientIndex) + "-" + str(studyIndex) + "-" + str(seriesIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
69 "SOPInstanceUID": str(patientIndex) + "." + str(studyIndex) + "." + str(seriesIndex) + "." + str(instanceIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
70 "StudyInstanceUID": str(patientIndex) + "." + str(studyIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
71 "SeriesInstanceUID": str(patientIndex) + "." + str(studyIndex) + "." + str(seriesIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
72 "SeriesNumber": str(seriesIndex),
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
73 "InstanceNumber": str(instanceIndex)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
74 },
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
75 deleteOriginal=False
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
76 )