MppsHandler.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (c) 2012-2020 fo-dicom contributors.
  2. // Licensed under the Microsoft Public License (MS-PL).
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Dicom.Log;
  6. namespace Worklist_SCP.Model
  7. {
  8. /// <summary>
  9. /// An implementation of IMppsSource, that does only logging but does not store the MPPS messages
  10. /// </summary>
  11. class MppsHandler : IMppsSource
  12. {
  13. public static Dictionary<string, WorklistItem> PendingProcedures { get; } = new Dictionary<string, WorklistItem>();
  14. private readonly Logger _logger;
  15. public MppsHandler(Logger logger)
  16. {
  17. _logger = logger;
  18. }
  19. public bool SetInProgress(string sopInstanceUID, string procedureStepId)
  20. {
  21. var workItem = WorklistServer.CurrentWorklistItems
  22. .FirstOrDefault(w => w.ProcedureStepID == procedureStepId);
  23. if (workItem == null)
  24. {
  25. // the procedureStepId provided cannot be found any more, so the data is invalid or the
  26. // modality tries to start a procedure that has been deleted/changed on the ris side...
  27. return false;
  28. }
  29. // now here change the sate of the procedure in the database or do similar stuff...
  30. _logger.Info($"Procedure with id {workItem.ProcedureStepID} of Patient {workItem.Surname} {workItem.Forename} is started");
  31. // remember the sopInstanceUID and store the worklistitem to which the sopInstanceUID belongs.
  32. // You should do this more permanent like in database or in file
  33. PendingProcedures.Add(sopInstanceUID, workItem);
  34. return true;
  35. }
  36. public bool SetDiscontinued(string sopInstanceUID, string reason)
  37. {
  38. if (!PendingProcedures.ContainsKey(sopInstanceUID))
  39. {
  40. // there is no pending procedure with this sopInstanceUID!
  41. return false;
  42. }
  43. var workItem = PendingProcedures[sopInstanceUID];
  44. // now here change the sate of the procedure in the database or do similar stuff...
  45. _logger.Info($"Procedure with id {workItem.ProcedureStepID} of Patient {workItem.Surname} {workItem.Forename} is discontinued for reason {reason}");
  46. // since the procedure was stopped, we remove it from the list of pending procedures
  47. PendingProcedures.Remove(sopInstanceUID);
  48. return true;
  49. }
  50. public bool SetCompleted(string sopInstanceUID, string doseDescription, List<string> affectedInstanceUIDs)
  51. {
  52. if (!PendingProcedures.ContainsKey(sopInstanceUID))
  53. {
  54. // there is no pending procedure with this sopInstanceUID!
  55. return false;
  56. }
  57. var workItem = PendingProcedures[sopInstanceUID];
  58. // now here change the sate of the procedure in the database or do similar stuff...
  59. _logger.Info($"Procedure with id {workItem.ProcedureStepID} of Patient {workItem.Surname} {workItem.Forename} is completed");
  60. // the MPPS completed message contains some additional informations about the performed procedure.
  61. // this informations are very vendor depending, so read the DICOM Conformance Statement or read
  62. // the DICOM logfiles to see which informations the vendor sends
  63. // since the procedure was completed, we remove it from the list of pending procedures
  64. PendingProcedures.Remove(sopInstanceUID);
  65. return true;
  66. }
  67. }
  68. }