APRActions.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import axiosInstance from '../interceptor';
  2. export interface AprConfig {
  3. AECDensity: number;
  4. AECField: string;
  5. AECFilm: number;
  6. Dose: number;
  7. ExposureMode: number;
  8. Focus: number;
  9. TOD: number;
  10. TubeLoad: number;
  11. kV: number;
  12. mA: number;
  13. mAs: number;
  14. ms: number;
  15. }
  16. interface AprSub {
  17. work_station_id: number;
  18. patient_size: string;
  19. config_object: {
  20. Common: AprConfig;
  21. };
  22. }
  23. interface APR {
  24. '@type': string;
  25. apr_id: string;
  26. apr_name: string;
  27. apr_description: string;
  28. patient_type: string;
  29. body_part_id: string;
  30. view_position: string;
  31. category: string;
  32. modality: string;
  33. sub: AprSub[];
  34. sort: number;
  35. is_enabled: boolean;
  36. product: string;
  37. is_pre_install: boolean;
  38. }
  39. // interface AprResponse {
  40. // code: string;
  41. // description: string;
  42. // solution: string;
  43. // data: APR;
  44. // }
  45. const getAprDetails = async (
  46. id: string,
  47. patientType: string,
  48. bodyPart: string,
  49. isEnabled: boolean,
  50. procedureId: string
  51. ): Promise<APR> => {
  52. const response = await axiosInstance.get(
  53. `/dr/api/v1/auth/protocol/view/${id}/apr`,
  54. {
  55. params: {
  56. patient_type: patientType,
  57. body_part: bodyPart,
  58. is_enabled: isEnabled,
  59. procedure_id: procedureId,
  60. },
  61. }
  62. );
  63. return response.data.data;
  64. };
  65. const getAprExposureParams = async (
  66. id: string,
  67. workStationId: number,
  68. patientSize: string
  69. ): Promise<AprConfig> => {
  70. const response = await axiosInstance.get(`auth/protocol/apr/${id}/tech`, {
  71. params: {
  72. work_station_id: workStationId,
  73. patient_size: patientSize,
  74. },
  75. });
  76. return response.data.data.ep;
  77. };
  78. const getAprByThickness = async (thickness: number): Promise<AprConfig> => {
  79. const response = await axiosInstance.get(
  80. `auth/protocol/thickness/${thickness}/apr`
  81. );
  82. return response.data.data;
  83. };
  84. export { getAprDetails, getAprExposureParams, getAprByThickness };
  85. interface DeviceActionMessage {
  86. deviceUri: string;
  87. reqName: string;
  88. reqParam: string;
  89. reqTransaction: string;
  90. reqClientID: string;
  91. }
  92. const pathOfGenerator = 'DIOS/DEVICE/Generator';
  93. const sendDeviceAction = async (reqName: string) => {
  94. const message: DeviceActionMessage = {
  95. deviceUri: pathOfGenerator,
  96. reqName,
  97. reqParam: `{"P0":"default"}`,
  98. reqTransaction: '',
  99. reqClientID: '',
  100. };
  101. try {
  102. await axiosInstance.post('/auth/device/action', message);
  103. } catch (error) {
  104. console.error(`[${reqName}] Failed to send device action:`, error);
  105. throw error;
  106. }
  107. };
  108. const incKv = async () => {
  109. await sendDeviceAction('IncParam_KV');
  110. };
  111. const decKv = async () => {
  112. await sendDeviceAction('DecParam_KV');
  113. };
  114. const incMas = async () => {
  115. await sendDeviceAction('IncParam_MAS');
  116. };
  117. const decMas = async () => {
  118. await sendDeviceAction('DecParam_MAS');
  119. };
  120. const incMa = async () => {
  121. await sendDeviceAction('IncParam_MA');
  122. };
  123. const decMa = async () => {
  124. await sendDeviceAction('DecParam_MA');
  125. };
  126. const incMs = async () => {
  127. await sendDeviceAction('IncParam_MS');
  128. };
  129. const decMs = async () => {
  130. await sendDeviceAction('DecParam_MS');
  131. };
  132. const incDensity = async () => {
  133. await sendDeviceAction('IncParam_Density');
  134. };
  135. const decDensity = async () => {
  136. await sendDeviceAction('DecParam_Density');
  137. };
  138. const incThickness = async () => {
  139. await sendDeviceAction('IncParam_Thickness');
  140. };
  141. const decThickness = async () => {
  142. await sendDeviceAction('DecParam_Thickness');
  143. };
  144. const SetAPR = async (reqParam: string) => {
  145. const message: DeviceActionMessage = {
  146. deviceUri: pathOfGenerator,
  147. reqName: 'SetAPR',
  148. reqParam,
  149. reqTransaction: '',
  150. reqClientID: '',
  151. };
  152. try {
  153. await axiosInstance.post('/auth/device/action', message);
  154. } catch (error) {
  155. console.error(`[SetAPR] Failed to send device action:`, error);
  156. throw error;
  157. }
  158. };
  159. export {
  160. incKv,
  161. decKv,
  162. incMas,
  163. decMas,
  164. incMa,
  165. decMa,
  166. incMs,
  167. decMs,
  168. incDensity,
  169. decDensity,
  170. incThickness,
  171. decThickness,
  172. SetAPR,
  173. };