DicomQuery.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /****************************************************************
  2. * Name: DicomQuery.hpp
  3. *
  4. ****************************************************************/
  5. #ifndef _INCLUDE_DICOM_QUERY_
  6. #define _INCLUDE_DICOM_QUERY_
  7. /////////////////////////////////////////////////////////////////////
  8. //
  9. class QueryTreeNode;
  10. class QueryTreeRoot;
  11. class QueryTreePatient;
  12. class QueryTreeStudy;
  13. class QueryTreeSeries;
  14. class QueryTreeImage;
  15. typedef BOOL (*QueryFindCallback) (const void * Para, UINT16 Status, const QueryTreeNode * ql);
  16. typedef BOOL (*QueryMoveCallback) (const void * Para, UINT16 Status, DICOMImage * DicomImage);
  17. typedef BOOL (*QueryMoveCallbackEx) (const void * Para, QueryTreeRoot * Root, UINT16 Status, DICOMImage * DicomImage);
  18. typedef BOOL (*QueryTreeDetachCallback) (const void * Para, const QueryTreeNode * ql);
  19. typedef BOOL (*MoveCompletedCallback) (
  20. const void * Para,
  21. QueryTreeRoot * Root,
  22. UINT16 Status,
  23. UINT16 NbOfRemaining,
  24. UINT16 NbOfCompleted,
  25. UINT16 NbOfFailed,
  26. UINT16 NbOfWarning);
  27. class QuerySCU;
  28. /////////////////////////////////////////////////////////////////////
  29. // class QueryTreeNode
  30. class DICOM_API QueryTreeNode
  31. {
  32. public:
  33. ArrayOfPtr < QueryTreeNode *> * Children;
  34. const DICOMDataSet *ResultDDS;
  35. tQueryLevel Tag;
  36. UINT32 lParam;
  37. DString SOPInstanceUID;
  38. protected:
  39. QueryTreeNode * TreeUp; // Tree level links upwards
  40. public:
  41. QueryTreeNode ()
  42. {
  43. Children = NULL;
  44. ResultDDS = NULL;
  45. Tag = tQInvalidLevel;
  46. lParam = 0;
  47. TreeUp = NULL;
  48. }
  49. virtual ~QueryTreeNode () { } ;
  50. virtual void Detach (void) ;
  51. virtual BOOL Expand (void) = 0;
  52. virtual BOOL Load (ArrayOfPtr < DICOMImage * > *);
  53. virtual BOOL Load (void);
  54. QueryTreeNode * GetParent (void) const { return TreeUp; }
  55. BOOL CheckConsistency (void) const;
  56. const QueryTreeRoot * UpToRoot (void) const
  57. {
  58. const QueryTreeNode * ql = this;
  59. while (ql -> TreeUp)
  60. ql = ql -> TreeUp;
  61. return ((QueryTreeRoot *)ql);
  62. }
  63. QueryTreeNode * FindDescendant (const char * theSOPInstanceUID)
  64. {
  65. if (SOPInstanceUID == theSOPInstanceUID)
  66. return this;
  67. if (Tag == tQImageLevel)
  68. return NULL;
  69. ArrayIterator < QueryTreeNode * > Iter (Children);
  70. while (Iter)
  71. {
  72. QueryTreeNode * Child = Iter ();
  73. if (Child->SOPInstanceUID == theSOPInstanceUID)
  74. return Child;
  75. if (Child->Tag == tQImageLevel)
  76. continue;
  77. QueryTreeNode * ql = Child->FindDescendant (theSOPInstanceUID);
  78. if (ql) return ql;
  79. }
  80. return NULL;
  81. }
  82. virtual void Dump (void) const;
  83. BOOL DoQuery (ArrayOfPtr <DICOMDataSet * > * ResultADDO);
  84. void OnQueryConfirm (const DICOMDataSet * DDS, UINT16 Status);
  85. void OnRetrieveConfirm (const DICOMDataSet * DDS, UINT16 Status);
  86. void OnRetrieveCompleted (UINT16 Status, UINT16 R, UINT16 C, UINT16 F, UINT16 W);
  87. BOOL ExpandToLeaf (void);
  88. protected:
  89. void ClearSendCallbackFlag (void);
  90. virtual BOOL LoadImage (ArrayOfPtr < DICOMImage * > *);
  91. virtual BOOL LoadImage (void);
  92. static BOOL DummyQueryCallback (const void * SThis, UINT16 Status, const QueryTreeNode * ql);
  93. static BOOL DummyRetrieveCallback (const void * SThis, UINT16 Status, DICOMImage * DicomImage);
  94. static BOOL DummyRetrieveCallbackEx (const void * SThis, QueryTreeRoot * Root, UINT16 Status, DICOMImage * DicomImage);
  95. static BOOL DummyDetachCallback (const void * SThis, const QueryTreeNode * ql);
  96. static BOOL DummyRetrieveCompletedCallback (const void * SThis, QueryTreeRoot * Root, UINT16 Status, UINT16 R, UINT16 C, UINT16 F, UINT16 W);
  97. virtual BOOL QueryCallback (UINT16 Status, QueryTreeNode * ql);
  98. virtual BOOL RetrieveCallback (UINT16 Status, DICOMImage * DicomImage);
  99. protected:
  100. virtual void Set (const DICOMDataSet * DDS) = 0;
  101. virtual void Clapse (void) { Detach () ; };
  102. virtual BOOL IsImageExistInLocal (void);
  103. void Add (QueryTreeNode * ql) { ql->TreeUp = this; Children->Add(ql); }
  104. BOOL UpdateQueryCriteria (tQueryLevel Level) const;
  105. BOOL DoRetrieve (void);
  106. void Disconnect (void);
  107. protected:
  108. friend class QueryTreeRoot;
  109. };
  110. /////////////////////////////////////////////////////////////////////
  111. // class QueryTreeRoot
  112. class DICOM_API QueryTreeRoot : public QueryTreeNode
  113. {
  114. public:
  115. bool TryLoadFromCache;
  116. bool DetachBeforeExpand;
  117. public:
  118. bool IsConnected (void) const
  119. {
  120. return (! m_bDisconnected);
  121. }
  122. protected:
  123. bool m_bDisconnected;
  124. private:
  125. mutable QueryFindCallback m_QueryCallback;
  126. mutable QueryMoveCallback m_RetrieveCallback;
  127. mutable QueryMoveCallbackEx m_RetrieveCallbackEx;
  128. mutable QueryTreeDetachCallback m_DetachCallback;
  129. mutable MoveCompletedCallback m_MoveCompletedCallback;
  130. mutable const void * m_pQCBPara;
  131. mutable const void * m_pRCBPara;
  132. mutable const void * m_pDCBPara;
  133. mutable const void * m_pCCBPara;
  134. QuerySCU * m_pDicomQuery;
  135. QueryCriteria * m_pQueryCriteria;
  136. const Modality * m_pAttachedModality;
  137. char m_MoveDestination [64]; // (0000,0600)
  138. tQueryRoot m_QueryRoot;
  139. tQueryLevel m_QueryLevel;
  140. DStringArray m_arSOPInstanceUIDSent;
  141. protected:
  142. bool ShouldICallback (DString SOPInstanceUID) ;
  143. bool ShouldICallback (const char * SOPInstanceUID) ;
  144. public:
  145. QueryTreeRoot ();
  146. QueryTreeRoot (const QueryTreeRoot & fromRoot);
  147. ~QueryTreeRoot () { Clapse (); };
  148. void SetQueryCallback (QueryFindCallback Callback, const void * Arg) const;
  149. void SetRetrieveCallback (QueryMoveCallback Callback, const void * Arg) const;
  150. void SetRetrieveCallbackEx (QueryMoveCallbackEx CallbackEx, const void * Arg) const;
  151. void SetDetachCallback (QueryTreeDetachCallback Callback, const void * Arg) const;
  152. void SetRetrieveCompletedCallback (MoveCompletedCallback Callback, const void * Arg) const;
  153. virtual void Detach (void);
  154. virtual BOOL Expand (void);
  155. virtual BOOL Load (ArrayOfPtr < DICOMImage * > *);
  156. virtual BOOL Load (void);
  157. virtual BOOL LoadDirect (tQueryLevel Level, const char * SOPInstanceUID);
  158. BOOL LoadDirectEx (tQueryLevel Level,
  159. const char * PatientID,
  160. const char * StudyInstanceUID,
  161. const char * SeriesInstanceUID,
  162. const char * SOPInstanceUID);
  163. void SetQueryLevel (tQueryLevel queryLevel) { m_QueryLevel = queryLevel; }
  164. tQueryLevel GetQueryLevel (void) const { return m_QueryLevel; }
  165. void SetQueryCriteria (class QueryCriteria *);
  166. QueryCriteria * GetQueryCriteria (void) const { return m_pQueryCriteria ; }
  167. BOOL ConnectTo (const Modality * pAttachedModality);
  168. const Modality * GetModality (void) const { return m_pAttachedModality; }
  169. BOOL Disconnect (void);
  170. BOOL SetMoveDestinationModality (const Modality * pMoveDestinationModality);
  171. protected:
  172. virtual void Set (const DICOMDataSet *);
  173. virtual void Clapse (void);
  174. virtual void Dump (void) const;
  175. friend QueryTreeNode;
  176. friend QueryTreePatient;
  177. friend QueryTreeStudy;
  178. friend QueryTreeSeries;
  179. friend QueryTreeImage;
  180. };
  181. /////////////////////////////////////////////////////////////////////
  182. // class QueryTreePatient
  183. class DICOM_API QueryTreePatient : public QueryTreeNode
  184. {
  185. public:
  186. QueryTreePatient ()
  187. {
  188. Tag = tQPatientLevel;
  189. };
  190. ~QueryTreePatient () { Clapse (); };
  191. virtual BOOL Expand (void);
  192. virtual void Set (const DICOMDataSet *);
  193. protected:
  194. BOOL Expand (BOOL FromParent);
  195. QueryTreePatient (const DICOMDataSet * DDS)
  196. {
  197. Tag = tQPatientLevel;
  198. Set (DDS);
  199. };
  200. friend QueryTreeRoot;
  201. };
  202. /////////////////////////////////////////////////////////////////////
  203. // class QueryTreeStudy
  204. class DICOM_API QueryTreeStudy : public QueryTreeNode
  205. {
  206. public:
  207. QueryTreeStudy ()
  208. {
  209. Tag = tQStudyLevel;
  210. }
  211. ~QueryTreeStudy () { Clapse (); };
  212. virtual BOOL Expand (void);
  213. virtual void Set (const DICOMDataSet *);
  214. protected:
  215. BOOL Expand (BOOL FromParent);
  216. QueryTreeStudy (const DICOMDataSet * DDS)
  217. {
  218. Tag = tQStudyLevel;
  219. Set (DDS);
  220. }
  221. friend QueryTreePatient;
  222. };
  223. /////////////////////////////////////////////////////////////////////
  224. // class QueryTreeStudy
  225. class DICOM_API QueryTreeSeries : public QueryTreeNode
  226. {
  227. public:
  228. QueryTreeSeries ()
  229. {
  230. Tag = tQSeriesLevel;
  231. }
  232. ~QueryTreeSeries () { Clapse (); };
  233. virtual BOOL Expand (void);
  234. virtual void Set (const DICOMDataSet *);
  235. protected:
  236. BOOL Expand (BOOL FromParent);
  237. QueryTreeSeries (const DICOMDataSet * DDS)
  238. {
  239. Tag = tQSeriesLevel;
  240. Set (DDS);
  241. }
  242. friend QueryTreeStudy;
  243. };
  244. /////////////////////////////////////////////////////////////////////
  245. // class QueryTreeImage
  246. class DICOM_API QueryTreeImage : public QueryTreeNode
  247. {
  248. public:
  249. QueryTreeImage ()
  250. {
  251. Tag = tQImageLevel;
  252. ImageIcon = NULL;
  253. DicomImage = NULL;
  254. }
  255. ~QueryTreeImage ()
  256. { Clapse (); };
  257. virtual BOOL Expand (void);
  258. virtual void Set (const DICOMDataSet *);
  259. virtual BOOL Load (ArrayOfPtr < DICOMImage * > *);
  260. virtual BOOL Load (void);
  261. DICOMImageIcon * GetImageIcon (void) { return ImageIcon; };
  262. DICOMImageIcon * SetImageIcon (DICOMImageIcon * newIcon)
  263. {
  264. DICOMImageIcon * oldIcon = ImageIcon;
  265. ImageIcon = newIcon;
  266. return oldIcon;
  267. }
  268. virtual void Detach (void)
  269. {
  270. QueryTreeNode::Detach ();
  271. if (ImageIcon) delete ImageIcon;
  272. if (DicomImage) delete DicomImage;
  273. ImageIcon = NULL;
  274. DicomImage = NULL;
  275. }
  276. protected:
  277. DICOMImageIcon * ImageIcon;
  278. DICOMImage * DicomImage;
  279. protected:
  280. QueryTreeImage (const DICOMDataSet * DDS)
  281. {
  282. Tag = tQImageLevel;
  283. ImageIcon = NULL;
  284. DicomImage = NULL;
  285. Set (DDS);
  286. }
  287. virtual BOOL LoadImage (ArrayOfPtr < DICOMImage * > * pImageArray) { return Load (pImageArray); }
  288. virtual BOOL LoadImage (void);
  289. BOOL LoadImageFromLocal (void);
  290. BOOL LoadImageFromRemote (void);
  291. BOOL DoLoadImageFromLocal (void);
  292. BOOL DoLoadImageFromRemote (void);
  293. virtual BOOL IsImageExistInLocal (void);
  294. private:
  295. BOOL LoadImageNoCallback (void);
  296. friend QueryTreeSeries;
  297. };
  298. /////////////////////////////////////////////////////////////////////
  299. inline BOOL QueryTreeNode::DummyQueryCallback (const void * Para, UINT16 Status, const QueryTreeNode * ql)
  300. {
  301. return false;
  302. }
  303. inline BOOL QueryTreeNode::DummyRetrieveCallback (const void * Para, UINT16 Status, DICOMImage * DicomImage)
  304. {
  305. return false;
  306. }
  307. inline BOOL QueryTreeNode::DummyRetrieveCallbackEx (const void * Para, QueryTreeRoot * Root, UINT16 Status, DICOMImage * DicomImage)
  308. {
  309. return false;
  310. }
  311. inline BOOL QueryTreeNode::DummyDetachCallback (const void * Para, const QueryTreeNode * ql)
  312. {
  313. return false;
  314. }
  315. inline BOOL QueryTreeNode::DummyRetrieveCompletedCallback (const void * SThis, QueryTreeRoot * Root, UINT16 Status, UINT16 R, UINT16 C, UINT16 F, UINT16 W)
  316. {
  317. return false;
  318. }
  319. /////////////////////////////////////////////////////////////////////
  320. DICOM_API inline bool operator == (const QueryTreeNode & qlA, const QueryTreeNode & qlB)
  321. {
  322. return (qlA.SOPInstanceUID == qlB.SOPInstanceUID);
  323. }
  324. DICOM_API inline bool operator != (const QueryTreeNode & qlA, const QueryTreeNode & qlB)
  325. {
  326. return (qlA.SOPInstanceUID != qlB.SOPInstanceUID);
  327. }
  328. #endif