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