rtp-connect 1.6 → 1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,17 @@ class String
26
26
  self.split(',')
27
27
  end
28
28
 
29
+ # Reformats a string, attempting to fix broken CSV format. Note that this
30
+ # method attempts to fix the CSV in a rather primitive, crude way: Any attributes
31
+ # containing a " character, will have these characters simply removed.
32
+ #
33
+ # @return [String] the processed string
34
+ #
35
+ def repair_csv
36
+ arr = self[1..-2].split('","')
37
+ "\"#{arr.collect{|e| e.gsub('"', '')}.join('","')}\""
38
+ end
39
+
29
40
  # Removes leading & trailing double quotes from a string.
30
41
  #
31
42
  # @return [String] the processed string
@@ -38,14 +49,24 @@ class String
38
49
  # quotation (leading and trailing double-quote characters) from the extracted
39
50
  # string elements.
40
51
  #
52
+ # @param [Boolean] repair if true, the method will attempt to repair a string that fails CSV processing, and then try to process it a second time
41
53
  # @return [Array<String>] an array of the comma separated values
42
54
  #
43
- def values
55
+ def values(repair=false)
44
56
  begin
45
57
  CSV.parse(self).first
46
58
  rescue StandardError => e
47
- RTP.logger.error("Unable to parse the given string record. Probably invalid CSV format: #{self}")
48
- raise e
59
+ if repair
60
+ RTP.logger.warn("CSV processing failed. Will attempt to reformat and reprocess the string record.")
61
+ begin
62
+ CSV.parse(self.repair_csv).first
63
+ rescue StandardError => e
64
+ RTP.logger.error("Unable to parse the given string record. Probably the CSV format is invalid and beyond repair: #{self}")
65
+ end
66
+ else
67
+ RTP.logger.error("Unable to parse the given string record. Probably invalid CSV format: #{self}")
68
+ raise e
69
+ end
49
70
  end
50
71
  end
51
72
 
@@ -76,6 +97,16 @@ class Array
76
97
  return wrapped.join(',')
77
98
  end
78
99
 
100
+ # Validates the number of elements in an array and converts all elements
101
+ # to strings.
102
+ #
103
+ # @param [Integer] nr the required number of elements in the array
104
+ #
105
+ def validate_and_process(nr)
106
+ raise ArgumentError, "Invalid array length. Expected exactly #{nr} elements, got #{self.length}." unless self.length == nr
107
+ self.collect {|e| e && e.to_s.strip}
108
+ end
109
+
79
110
  end
80
111
 
81
112
  # An extension to the NilClass, facilitating a transformation from nil to
@@ -1,702 +1,607 @@
1
- module RTP
2
-
3
- # The simulation field class.
4
- #
5
- # @note Relations:
6
- # * Parent: Prescription
7
- # * Children: none
8
- #
9
- class SimulationField < Record
10
-
11
- # The Record which this instance belongs to.
12
- attr_reader :parent
13
- attr_reader :rx_site_name
14
- attr_reader :field_name
15
- attr_reader :field_id
16
- attr_reader :field_note
17
- attr_reader :treatment_machine
18
- attr_reader :gantry_angle
19
- attr_reader :collimator_angle
20
- attr_reader :field_x_mode
21
- attr_reader :field_x
22
- attr_reader :collimator_x1
23
- attr_reader :collimator_x2
24
- attr_reader :field_y_mode
25
- attr_reader :field_y
26
- attr_reader :collimator_y1
27
- attr_reader :collimator_y2
28
- attr_reader :couch_vertical
29
- attr_reader :couch_lateral
30
- attr_reader :couch_longitudinal
31
- attr_reader :couch_angle
32
- attr_reader :couch_pedestal
33
- attr_reader :sad
34
- attr_reader :ap_separation
35
- attr_reader :pa_separation
36
- attr_reader :lateral_separation
37
- attr_reader :tangential_separation
38
- attr_reader :other_label_1
39
- attr_reader :ssd_1
40
- attr_reader :sfd_1
41
- attr_reader :other_label_2
42
- attr_reader :other_measurement_1
43
- attr_reader :other_measurement_2
44
- attr_reader :other_label_3
45
- attr_reader :other_measurement_3
46
- attr_reader :other_measurement_4
47
- attr_reader :other_label_4
48
- attr_reader :other_measurement_5
49
- attr_reader :other_measurement_6
50
- attr_reader :blade_x_mode
51
- attr_reader :blade_x
52
- attr_reader :blade_x1
53
- attr_reader :blade_x2
54
- attr_reader :blade_y_mode
55
- attr_reader :blade_y
56
- attr_reader :blade_y1
57
- attr_reader :blade_y2
58
- attr_reader :ii_lateral
59
- attr_reader :ii_longitudinal
60
- attr_reader :ii_vertical
61
- attr_reader :kvp
62
- attr_reader :ma
63
- attr_reader :seconds
64
-
65
- # Creates a new SimulationField by parsing a RTPConnect string line.
66
- #
67
- # @param [#to_s] string the simulation field definition record string line
68
- # @param [Record] parent a record which is used to determine the proper parent of this instance
69
- # @return [Field] the created SimulationField instance
70
- # @raise [ArgumentError] if given a string containing an invalid number of elements
71
- #
72
- def self.load(string, parent)
73
- # Get the quote-less values:
74
- values = string.to_s.values
75
- low_limit = 17
76
- high_limit = 53
77
- raise ArgumentError, "Invalid argument 'string': Expected at least #{low_limit} elements, got #{values.length}." if values.length < low_limit
78
- RTP.logger.warn "The number of elements (#{values.length}) for this Simulation Field record exceeds the known number of data items for this record (#{high_limit}). This may indicate an invalid record or that the RTP format has recently been expanded with new items." if values.length > high_limit
79
- sf = self.new(parent)
80
- # Assign the values to attributes:
81
- sf.keyword = values[0]
82
- sf.rx_site_name = values[1]
83
- sf.field_name = values[2]
84
- sf.field_id = values[3]
85
- sf.field_note = values[4]
86
- sf.treatment_machine = values[5]
87
- sf.gantry_angle = values[6]
88
- sf.collimator_angle = values[7]
89
- sf.field_x_mode = values[8]
90
- sf.field_x = values[9]
91
- sf.collimator_x1 = values[10]
92
- sf.collimator_x2 = values[11]
93
- sf.field_y_mode = values[12]
94
- sf.field_y = values[13]
95
- sf.collimator_y1 = values[14]
96
- sf.collimator_y2 = values[15]
97
- sf.couch_vertical = values[16]
98
- sf.couch_lateral = values[17]
99
- sf.couch_longitudinal = values[18]
100
- sf.couch_angle = values[19]
101
- sf.couch_pedestal = values[20]
102
- sf.sad = values[21]
103
- sf.ap_separation = values[22]
104
- sf.pa_separation = values[23]
105
- sf.lateral_separation = values[24]
106
- sf.tangential_separation = values[25]
107
- sf.other_label_1 = values[26]
108
- sf.ssd_1 = values[27]
109
- sf.sfd_1 = values[28]
110
- sf.other_label_2 = values[29]
111
- sf.other_measurement_1 = values[30]
112
- sf.other_measurement_2 = values[31]
113
- sf.other_label_3 = values[32]
114
- sf.other_measurement_3 = values[33]
115
- sf.other_measurement_4 = values[34]
116
- sf.other_label_4 = values[35]
117
- sf.other_measurement_5 = values[36]
118
- sf.other_measurement_6 = values[37]
119
- sf.blade_x_mode = values[38]
120
- sf.blade_x = values[39]
121
- sf.blade_x1 = values[40]
122
- sf.blade_x2 = values[41]
123
- sf.blade_y_mode = values[42]
124
- sf.blade_y = values[43]
125
- sf.blade_y1 = values[44]
126
- sf.blade_y2 = values[45]
127
- sf.ii_lateral = values[46]
128
- sf.ii_longitudinal = values[47]
129
- sf.ii_vertical = values[48]
130
- sf.kvp = values[49]
131
- sf.ma = values[50]
132
- sf.seconds = values[51]
133
- sf.crc = values[-1]
134
- return sf
135
- end
136
-
137
- # Creates a new SimulationField.
138
- #
139
- # @param [Record] parent a record which is used to determine the proper parent of this instance
140
- #
141
- def initialize(parent)
142
- # Parent relation (may get more than one type of record here):
143
- @parent = get_parent(parent.to_record, Prescription)
144
- @parent.add_simulation_field(self)
145
- @keyword = 'SIM_DEF'
146
- end
147
-
148
- # Checks for equality.
149
- #
150
- # Other and self are considered equivalent if they are
151
- # of compatible types and their attributes are equivalent.
152
- #
153
- # @param other an object to be compared with self.
154
- # @return [Boolean] true if self and other are considered equivalent
155
- #
156
- def ==(other)
157
- if other.respond_to?(:to_simulation_field)
158
- other.send(:state) == state
159
- end
160
- end
161
-
162
- alias_method :eql?, :==
163
-
164
- # Collects the child records of this instance in a properly sorted array.
165
- #
166
- # @return [Array] an emtpy array
167
- #
168
- def children
169
- return Array.new
170
- end
171
-
172
- # Computes a hash code for this object.
173
- #
174
- # @note Two objects with the same attributes will have the same hash code.
175
- #
176
- # @return [Fixnum] the object's hash code
177
- #
178
- def hash
179
- state.hash
180
- end
181
-
182
- # Collects the values (attributes) of this instance.
183
- #
184
- # @note The CRC is not considered part of the actual values and is excluded.
185
- # @return [Array<String>] an array of attributes (in the same order as they appear in the RTP string)
186
- #
187
- def values
188
- return [
189
- @keyword,
190
- @rx_site_name,
191
- @field_name,
192
- @field_id,
193
- @field_note,
194
- @treatment_machine,
195
- @gantry_angle,
196
- @collimator_angle,
197
- @field_x_mode,
198
- @field_x,
199
- @collimator_x1,
200
- @collimator_x2,
201
- @field_y_mode,
202
- @field_y,
203
- @collimator_y1,
204
- @collimator_y2,
205
- @couch_vertical,
206
- @couch_lateral,
207
- @couch_longitudinal,
208
- @couch_angle,
209
- @couch_pedestal,
210
- @sad,
211
- @ap_separation,
212
- @pa_separation,
213
- @lateral_separation,
214
- @tangential_separation,
215
- @other_label_1,
216
- @ssd_1,
217
- @sfd_1,
218
- @other_label_2,
219
- @other_measurement_1,
220
- @other_measurement_2,
221
- @other_label_3,
222
- @other_measurement_3,
223
- @other_measurement_4,
224
- @other_label_4,
225
- @other_measurement_5,
226
- @other_measurement_6,
227
- @blade_x_mode,
228
- @blade_x,
229
- @blade_x1,
230
- @blade_x2,
231
- @blade_y_mode,
232
- @blade_y,
233
- @blade_y1,
234
- @blade_y2,
235
- @ii_lateral,
236
- @ii_longitudinal,
237
- @ii_vertical,
238
- @kvp,
239
- @ma,
240
- @seconds
241
- ]
242
- end
243
-
244
- # Returns self.
245
- #
246
- # @return [SimulationField] self
247
- #
248
- def to_simulation_field
249
- self
250
- end
251
-
252
- # Encodes the SimulationField object + any hiearchy of child objects,
253
- # to a properly formatted RTPConnect ascii string.
254
- #
255
- # @return [String] an RTP string with a single or multiple lines/records
256
- #
257
- def to_s
258
- str = encode
259
- if children
260
- children.each do |child|
261
- str += child.to_s
262
- end
263
- end
264
- return str
265
- end
266
-
267
- alias :to_str :to_s
268
-
269
- # Sets the keyword attribute.
270
- #
271
- # @note Since only a specific string is accepted, this is more of an argument check than a traditional setter method
272
- # @param [#to_s] value the new attribute value
273
- # @raise [ArgumentError] if given an unexpected keyword
274
- #
275
- def keyword=(value)
276
- value = value.to_s.upcase
277
- raise ArgumentError, "Invalid keyword. Expected 'SIM_DEF', got #{value}." unless value == "SIM_DEF"
278
- @keyword = value
279
- end
280
-
281
- # Sets the rx_site_name attribute.
282
- #
283
- # @param [nil, #to_s] value the new attribute value
284
- #
285
- def rx_site_name=(value)
286
- @rx_site_name = value && value.to_s
287
- end
288
-
289
- # Sets the field_name attribute.
290
- #
291
- # @param [nil, #to_s] value the new attribute value
292
- #
293
- def field_name=(value)
294
- @field_name = value && value.to_s
295
- end
296
-
297
- # Sets the field_id attribute.
298
- #
299
- # @param [nil, #to_s] value the new attribute value
300
- #
301
- def field_id=(value)
302
- @field_id = value && value.to_s
303
- end
304
-
305
- # Sets the field_note attribute.
306
- #
307
- # @param [nil, #to_s] value the new attribute value
308
- #
309
- def field_note=(value)
310
- @field_note = value && value.to_s
311
- end
312
-
313
- # Sets the treatment_machine attribute.
314
- #
315
- # @param [nil, #to_s] value the new attribute value
316
- #
317
- def treatment_machine=(value)
318
- @treatment_machine = value && value.to_s
319
- end
320
-
321
- # Sets the gantry_angle attribute.
322
- #
323
- # @param [nil, #to_s] value the new attribute value
324
- #
325
- def gantry_angle=(value)
326
- @gantry_angle = value && value.to_s.strip
327
- end
328
-
329
- # Sets the collimator_angle attribute.
330
- #
331
- # @param [nil, #to_s] value the new attribute value
332
- #
333
- def collimator_angle=(value)
334
- @collimator_angle = value && value.to_s.strip
335
- end
336
-
337
- # Sets the field_x_mode attribute.
338
- #
339
- # @param [nil, #to_s] value the new attribute value
340
- #
341
- def field_x_mode=(value)
342
- @field_x_mode = value && value.to_s
343
- end
344
-
345
- # Sets the field_x attribute.
346
- #
347
- # @param [nil, #to_s] value the new attribute value
348
- #
349
- def field_x=(value)
350
- @field_x = value && value.to_s.strip
351
- end
352
-
353
- # Sets the collimator_x1 attribute.
354
- #
355
- # @param [nil, #to_s] value the new attribute value
356
- #
357
- def collimator_x1=(value)
358
- @collimator_x1 = value && value.to_s.strip
359
- end
360
-
361
- # Sets the collimator_x2 attribute.
362
- #
363
- # @param [nil, #to_s] value the new attribute value
364
- #
365
- def collimator_x2=(value)
366
- @collimator_x2 = value && value.to_s.strip
367
- end
368
-
369
- # Sets the field_y_mode attribute.
370
- #
371
- # @param [nil, #to_s] value the new attribute value
372
- #
373
- def field_y_mode=(value)
374
- @field_y_mode = value && value.to_s
375
- end
376
-
377
- # Sets the field_y attribute.
378
- #
379
- # @param [nil, #to_s] value the new attribute value
380
- #
381
- def field_y=(value)
382
- @field_y = value && value.to_s.strip
383
- end
384
-
385
- # Sets the collimator_y1 attribute.
386
- #
387
- # @param [nil, #to_s] value the new attribute value
388
- #
389
- def collimator_y1=(value)
390
- @collimator_y1 = value && value.to_s.strip
391
- end
392
-
393
- # Sets the collimator_y2 attribute.
394
- #
395
- # @param [nil, #to_s] value the new attribute value
396
- #
397
- def collimator_y2=(value)
398
- @collimator_y2 = value && value.to_s.strip
399
- end
400
-
401
- # Sets the couch_vertical attribute.
402
- #
403
- # @param [nil, #to_s] value the new attribute value
404
- #
405
- def couch_vertical=(value)
406
- @couch_vertical = value && value.to_s.strip
407
- end
408
-
409
- # Sets the couch_lateral attribute.
410
- #
411
- # @param [nil, #to_s] value the new attribute value
412
- #
413
- def couch_lateral=(value)
414
- @couch_lateral = value && value.to_s.strip
415
- end
416
-
417
- # Sets the couch_longitudinal attribute.
418
- #
419
- # @param [nil, #to_s] value the new attribute value
420
- #
421
- def couch_longitudinal=(value)
422
- @couch_longitudinal = value && value.to_s.strip
423
- end
424
-
425
- # Sets the couch_angle attribute.
426
- #
427
- # @param [nil, #to_s] value the new attribute value
428
- #
429
- def couch_angle=(value)
430
- @couch_angle = value && value.to_s.strip.strip
431
- end
432
-
433
- # Sets the couch_pedestal attribute.
434
- #
435
- # @param [nil, #to_s] value the new attribute value
436
- #
437
- def couch_pedestal=(value)
438
- @couch_pedestal = value && value.to_s.strip
439
- end
440
-
441
- # Sets the sad attribute.
442
- #
443
- # @param [nil, #to_s] value the new attribute value
444
- #
445
- def sad=(value)
446
- @sad = value && value.to_s.strip
447
- end
448
-
449
- # Sets the ap_separation attribute.
450
- #
451
- # @param [nil, #to_s] value the new attribute value
452
- #
453
- def ap_separation=(value)
454
- @ap_separation = value && value.to_s
455
- end
456
-
457
- # Sets the pa_separation attribute.
458
- #
459
- # @param [nil, #to_s] value the new attribute value
460
- #
461
- def pa_separation=(value)
462
- @pa_separation = value && value.to_s.strip
463
- end
464
-
465
- # Sets the lateral_separation attribute.
466
- #
467
- # @param [nil, #to_s] value the new attribute value
468
- #
469
- def lateral_separation=(value)
470
- @lateral_separation = value && value.to_s.strip
471
- end
472
-
473
- # Sets the tangential_separation attribute.
474
- #
475
- # @param [nil, #to_s] value the new attribute value
476
- #
477
- def tangential_separation=(value)
478
- @tangential_separation = value && value.to_s.strip
479
- end
480
-
481
- # Sets the other_label_1 attribute.
482
- #
483
- # @param [nil, #to_s] value the new attribute value
484
- #
485
- def other_label_1=(value)
486
- @other_label_1 = value && value.to_s
487
- end
488
-
489
- # Sets the ssd_1 attribute.
490
- #
491
- # @param [nil, #to_s] value the new attribute value
492
- #
493
- def ssd_1=(value)
494
- @ssd_1 = value && value.to_s
495
- end
496
-
497
- # Sets the sfd_1 attribute.
498
- #
499
- # @param [nil, #to_s] value the new attribute value
500
- #
501
- def sfd_1=(value)
502
- @sfd_1 = value && value.to_s
503
- end
504
-
505
- # Sets the other_label_2 attribute.
506
- #
507
- # @param [nil, #to_s] value the new attribute value
508
- #
509
- def other_label_2=(value)
510
- @other_label_2 = value && value.to_s
511
- end
512
-
513
- # Sets the other_measurement_1 attribute.
514
- #
515
- # @param [nil, #to_s] value the new attribute value
516
- #
517
- def other_measurement_1=(value)
518
- @other_measurement_1 = value && value.to_s
519
- end
520
-
521
- # Sets the other_measurement_2 attribute.
522
- #
523
- # @param [nil, #to_s] value the new attribute value
524
- #
525
- def other_measurement_2=(value)
526
- @other_measurement_2 = value && value.to_s
527
- end
528
-
529
- # Sets the other_label_3 attribute.
530
- #
531
- # @param [nil, #to_s] value the new attribute value
532
- #
533
- def other_label_3=(value)
534
- @other_label_3 = value && value.to_s
535
- end
536
-
537
- # Sets the other_measurement_3 attribute.
538
- #
539
- # @param [nil, #to_s] value the new attribute value
540
- #
541
- def other_measurement_3=(value)
542
- @other_measurement_3 = value && value.to_s
543
- end
544
-
545
- # Sets the other_measurement_4 attribute.
546
- #
547
- # @param [nil, #to_s] value the new attribute value
548
- #
549
- def other_measurement_4=(value)
550
- @other_measurement_4 = value && value.to_s
551
- end
552
-
553
- # Sets the other_label_4 attribute.
554
- #
555
- # @param [nil, #to_s] value the new attribute value
556
- #
557
- def other_label_4=(value)
558
- @other_label_4 = value && value.to_s
559
- end
560
-
561
- # Sets the other_measurement_5 attribute.
562
- #
563
- # @param [nil, #to_s] value the new attribute value
564
- #
565
- def other_measurement_5=(value)
566
- @other_measurement_5 = value && value.to_s
567
- end
568
-
569
- # Sets the other_measurement_6 attribute.
570
- #
571
- # @param [nil, #to_s] value the new attribute value
572
- #
573
- def other_measurement_6=(value)
574
- @other_measurement_6 = value && value.to_s
575
- end
576
-
577
- # Sets the blade_x_mode attribute.
578
- #
579
- # @param [nil, #to_s] value the new attribute value
580
- #
581
- def blade_x_mode=(value)
582
- @blade_x_mode = value && value.to_s
583
- end
584
-
585
- # Sets the blade_x attribute.
586
- #
587
- # @param [nil, #to_s] value the new attribute value
588
- #
589
- def blade_x=(value)
590
- @blade_x = value && value.to_s
591
- end
592
-
593
- # Sets the blade_x1 attribute.
594
- #
595
- # @param [nil, #to_s] value the new attribute value
596
- #
597
- def blade_x1=(value)
598
- @blade_x1 = value && value.to_s
599
- end
600
-
601
- # Sets the blade_x2 attribute.
602
- #
603
- # @param [nil, #to_s] value the new attribute value
604
- #
605
- def blade_x2=(value)
606
- @blade_x2 = value && value.to_s
607
- end
608
-
609
- # Sets the blade_y_mode attribute.
610
- #
611
- # @param [nil, #to_s] value the new attribute value
612
- #
613
- def blade_y_mode=(value)
614
- @blade_y_mode = value && value.to_s
615
- end
616
-
617
- # Sets the blade_y attribute.
618
- #
619
- # @param [nil, #to_s] value the new attribute value
620
- #
621
- def blade_y=(value)
622
- @blade_y = value && value.to_s
623
- end
624
-
625
- # Sets the blade_y1 attribute.
626
- #
627
- # @param [nil, #to_s] value the new attribute value
628
- #
629
- def blade_y1=(value)
630
- @blade_y1 = value && value.to_s
631
- end
632
-
633
- # Sets the blade_y2 attribute.
634
- #
635
- # @param [nil, #to_s] value the new attribute value
636
- #
637
- def blade_y2=(value)
638
- @blade_y2 = value && value.to_s
639
- end
640
-
641
- # Sets the ii_lateral attribute.
642
- #
643
- # @param [nil, #to_s] value the new attribute value
644
- #
645
- def ii_lateral=(value)
646
- @ii_lateral = value && value.to_s
647
- end
648
-
649
- # Sets the ii_longitudinal attribute.
650
- #
651
- # @param [nil, #to_s] value the new attribute value
652
- #
653
- def ii_longitudinal=(value)
654
- @ii_longitudinal = value && value.to_s
655
- end
656
-
657
- # Sets the ii_vertical attribute.
658
- #
659
- # @param [nil, #to_s] value the new attribute value
660
- #
661
- def ii_vertical=(value)
662
- @ii_vertical = value && value.to_s
663
- end
664
-
665
- # Sets the kvp attribute.
666
- #
667
- # @param [nil, #to_s] value the new attribute value
668
- #
669
- def kvp=(value)
670
- @kvp = value && value.to_s
671
- end
672
-
673
- # Sets the ma attribute.
674
- #
675
- # @param [nil, #to_s] value the new attribute value
676
- #
677
- def ma=(value)
678
- @ma = value && value.to_s
679
- end
680
-
681
- # Sets the seconds attribute.
682
- #
683
- # @param [nil, #to_s] value the new attribute value
684
- #
685
- def seconds=(value)
686
- @seconds = value && value.to_s
687
- end
688
-
689
-
690
- private
691
-
692
-
693
- # Collects the attributes of this instance.
694
- #
695
- # @note The CRC is not considered part of the attributes of interest and is excluded
696
- # @return [Array<String>] an array of attributes
697
- #
698
- alias_method :state, :values
699
-
700
- end
701
-
1
+ module RTP
2
+
3
+ # The simulation field class.
4
+ #
5
+ # @note Relations:
6
+ # * Parent: Prescription
7
+ # * Children: none
8
+ #
9
+ class SimulationField < Record
10
+
11
+ # The Record which this instance belongs to.
12
+ attr_accessor :parent
13
+ attr_reader :rx_site_name
14
+ attr_reader :field_name
15
+ attr_reader :field_id
16
+ attr_reader :field_note
17
+ attr_reader :treatment_machine
18
+ attr_reader :gantry_angle
19
+ attr_reader :collimator_angle
20
+ attr_reader :field_x_mode
21
+ attr_reader :field_x
22
+ attr_reader :collimator_x1
23
+ attr_reader :collimator_x2
24
+ attr_reader :field_y_mode
25
+ attr_reader :field_y
26
+ attr_reader :collimator_y1
27
+ attr_reader :collimator_y2
28
+ attr_reader :couch_vertical
29
+ attr_reader :couch_lateral
30
+ attr_reader :couch_longitudinal
31
+ attr_reader :couch_angle
32
+ attr_reader :couch_pedestal
33
+ attr_reader :sad
34
+ attr_reader :ap_separation
35
+ attr_reader :pa_separation
36
+ attr_reader :lateral_separation
37
+ attr_reader :tangential_separation
38
+ attr_reader :other_label_1
39
+ attr_reader :ssd_1
40
+ attr_reader :sfd_1
41
+ attr_reader :other_label_2
42
+ attr_reader :other_measurement_1
43
+ attr_reader :other_measurement_2
44
+ attr_reader :other_label_3
45
+ attr_reader :other_measurement_3
46
+ attr_reader :other_measurement_4
47
+ attr_reader :other_label_4
48
+ attr_reader :other_measurement_5
49
+ attr_reader :other_measurement_6
50
+ attr_reader :blade_x_mode
51
+ attr_reader :blade_x
52
+ attr_reader :blade_x1
53
+ attr_reader :blade_x2
54
+ attr_reader :blade_y_mode
55
+ attr_reader :blade_y
56
+ attr_reader :blade_y1
57
+ attr_reader :blade_y2
58
+ attr_reader :ii_lateral
59
+ attr_reader :ii_longitudinal
60
+ attr_reader :ii_vertical
61
+ attr_reader :kvp
62
+ attr_reader :ma
63
+ attr_reader :seconds
64
+
65
+ # Creates a new SimulationField by parsing a RTPConnect string line.
66
+ #
67
+ # @param [#to_s] string the simulation field definition record string line
68
+ # @param [Record] parent a record which is used to determine the proper parent of this instance
69
+ # @return [Field] the created SimulationField instance
70
+ # @raise [ArgumentError] if given a string containing an invalid number of elements
71
+ #
72
+ def self.load(string, parent)
73
+ sf = self.new(parent)
74
+ sf.load(string)
75
+ end
76
+
77
+ # Creates a new SimulationField.
78
+ #
79
+ # @param [Record] parent a record which is used to determine the proper parent of this instance
80
+ #
81
+ def initialize(parent)
82
+ super('SIM_DEF', 17, 53)
83
+ # Parent relation (may get more than one type of record here):
84
+ @parent = get_parent(parent.to_record, Prescription)
85
+ @parent.add_simulation_field(self)
86
+ @attributes = [
87
+ # Required:
88
+ :keyword,
89
+ :rx_site_name,
90
+ :field_name,
91
+ :field_id,
92
+ :field_note,
93
+ :treatment_machine,
94
+ :gantry_angle,
95
+ :collimator_angle,
96
+ :field_x_mode,
97
+ :field_x,
98
+ :collimator_x1,
99
+ :collimator_x2,
100
+ :field_y_mode,
101
+ :field_y,
102
+ :collimator_y1,
103
+ :collimator_y2,
104
+ # Optional:
105
+ :couch_vertical,
106
+ :couch_lateral,
107
+ :couch_longitudinal,
108
+ :couch_angle,
109
+ :couch_pedestal,
110
+ :sad,
111
+ :ap_separation,
112
+ :pa_separation,
113
+ :lateral_separation,
114
+ :tangential_separation,
115
+ :other_label_1,
116
+ :ssd_1,
117
+ :sfd_1,
118
+ :other_label_2,
119
+ :other_measurement_1,
120
+ :other_measurement_2,
121
+ :other_label_3,
122
+ :other_measurement_3,
123
+ :other_measurement_4,
124
+ :other_label_4,
125
+ :other_measurement_5,
126
+ :other_measurement_6,
127
+ :blade_x_mode,
128
+ :blade_x,
129
+ :blade_x1,
130
+ :blade_x2,
131
+ :blade_y_mode,
132
+ :blade_y,
133
+ :blade_y1,
134
+ :blade_y2,
135
+ :ii_lateral,
136
+ :ii_longitudinal,
137
+ :ii_vertical,
138
+ :kvp,
139
+ :ma,
140
+ :seconds
141
+ ]
142
+ end
143
+
144
+ # Checks for equality.
145
+ #
146
+ # Other and self are considered equivalent if they are
147
+ # of compatible types and their attributes are equivalent.
148
+ #
149
+ # @param other an object to be compared with self.
150
+ # @return [Boolean] true if self and other are considered equivalent
151
+ #
152
+ def ==(other)
153
+ if other.respond_to?(:to_simulation_field)
154
+ other.send(:state) == state
155
+ end
156
+ end
157
+
158
+ alias_method :eql?, :==
159
+
160
+ # Collects the child records of this instance in a properly sorted array.
161
+ #
162
+ # @return [Array] an emtpy array
163
+ #
164
+ def children
165
+ return Array.new
166
+ end
167
+
168
+ # Computes a hash code for this object.
169
+ #
170
+ # @note Two objects with the same attributes will have the same hash code.
171
+ #
172
+ # @return [Fixnum] the object's hash code
173
+ #
174
+ def hash
175
+ state.hash
176
+ end
177
+
178
+ # Returns self.
179
+ #
180
+ # @return [SimulationField] self
181
+ #
182
+ def to_simulation_field
183
+ self
184
+ end
185
+
186
+ # Sets the rx_site_name attribute.
187
+ #
188
+ # @param [nil, #to_s] value the new attribute value
189
+ #
190
+ def rx_site_name=(value)
191
+ @rx_site_name = value && value.to_s
192
+ end
193
+
194
+ # Sets the field_name attribute.
195
+ #
196
+ # @param [nil, #to_s] value the new attribute value
197
+ #
198
+ def field_name=(value)
199
+ @field_name = value && value.to_s
200
+ end
201
+
202
+ # Sets the field_id attribute.
203
+ #
204
+ # @param [nil, #to_s] value the new attribute value
205
+ #
206
+ def field_id=(value)
207
+ @field_id = value && value.to_s
208
+ end
209
+
210
+ # Sets the field_note attribute.
211
+ #
212
+ # @param [nil, #to_s] value the new attribute value
213
+ #
214
+ def field_note=(value)
215
+ @field_note = value && value.to_s
216
+ end
217
+
218
+ # Sets the treatment_machine attribute.
219
+ #
220
+ # @param [nil, #to_s] value the new attribute value
221
+ #
222
+ def treatment_machine=(value)
223
+ @treatment_machine = value && value.to_s
224
+ end
225
+
226
+ # Sets the gantry_angle attribute.
227
+ #
228
+ # @param [nil, #to_s] value the new attribute value
229
+ #
230
+ def gantry_angle=(value)
231
+ @gantry_angle = value && value.to_s.strip
232
+ end
233
+
234
+ # Sets the collimator_angle attribute.
235
+ #
236
+ # @param [nil, #to_s] value the new attribute value
237
+ #
238
+ def collimator_angle=(value)
239
+ @collimator_angle = value && value.to_s.strip
240
+ end
241
+
242
+ # Sets the field_x_mode attribute.
243
+ #
244
+ # @param [nil, #to_s] value the new attribute value
245
+ #
246
+ def field_x_mode=(value)
247
+ @field_x_mode = value && value.to_s
248
+ end
249
+
250
+ # Sets the field_x attribute.
251
+ #
252
+ # @param [nil, #to_s] value the new attribute value
253
+ #
254
+ def field_x=(value)
255
+ @field_x = value && value.to_s.strip
256
+ end
257
+
258
+ # Sets the collimator_x1 attribute.
259
+ #
260
+ # @param [nil, #to_s] value the new attribute value
261
+ #
262
+ def collimator_x1=(value)
263
+ @collimator_x1 = value && value.to_s.strip
264
+ end
265
+
266
+ # Sets the collimator_x2 attribute.
267
+ #
268
+ # @param [nil, #to_s] value the new attribute value
269
+ #
270
+ def collimator_x2=(value)
271
+ @collimator_x2 = value && value.to_s.strip
272
+ end
273
+
274
+ # Sets the field_y_mode attribute.
275
+ #
276
+ # @param [nil, #to_s] value the new attribute value
277
+ #
278
+ def field_y_mode=(value)
279
+ @field_y_mode = value && value.to_s
280
+ end
281
+
282
+ # Sets the field_y attribute.
283
+ #
284
+ # @param [nil, #to_s] value the new attribute value
285
+ #
286
+ def field_y=(value)
287
+ @field_y = value && value.to_s.strip
288
+ end
289
+
290
+ # Sets the collimator_y1 attribute.
291
+ #
292
+ # @param [nil, #to_s] value the new attribute value
293
+ #
294
+ def collimator_y1=(value)
295
+ @collimator_y1 = value && value.to_s.strip
296
+ end
297
+
298
+ # Sets the collimator_y2 attribute.
299
+ #
300
+ # @param [nil, #to_s] value the new attribute value
301
+ #
302
+ def collimator_y2=(value)
303
+ @collimator_y2 = value && value.to_s.strip
304
+ end
305
+
306
+ # Sets the couch_vertical attribute.
307
+ #
308
+ # @param [nil, #to_s] value the new attribute value
309
+ #
310
+ def couch_vertical=(value)
311
+ @couch_vertical = value && value.to_s.strip
312
+ end
313
+
314
+ # Sets the couch_lateral attribute.
315
+ #
316
+ # @param [nil, #to_s] value the new attribute value
317
+ #
318
+ def couch_lateral=(value)
319
+ @couch_lateral = value && value.to_s.strip
320
+ end
321
+
322
+ # Sets the couch_longitudinal attribute.
323
+ #
324
+ # @param [nil, #to_s] value the new attribute value
325
+ #
326
+ def couch_longitudinal=(value)
327
+ @couch_longitudinal = value && value.to_s.strip
328
+ end
329
+
330
+ # Sets the couch_angle attribute.
331
+ #
332
+ # @param [nil, #to_s] value the new attribute value
333
+ #
334
+ def couch_angle=(value)
335
+ @couch_angle = value && value.to_s.strip.strip
336
+ end
337
+
338
+ # Sets the couch_pedestal attribute.
339
+ #
340
+ # @param [nil, #to_s] value the new attribute value
341
+ #
342
+ def couch_pedestal=(value)
343
+ @couch_pedestal = value && value.to_s.strip
344
+ end
345
+
346
+ # Sets the sad attribute.
347
+ #
348
+ # @param [nil, #to_s] value the new attribute value
349
+ #
350
+ def sad=(value)
351
+ @sad = value && value.to_s.strip
352
+ end
353
+
354
+ # Sets the ap_separation attribute.
355
+ #
356
+ # @param [nil, #to_s] value the new attribute value
357
+ #
358
+ def ap_separation=(value)
359
+ @ap_separation = value && value.to_s
360
+ end
361
+
362
+ # Sets the pa_separation attribute.
363
+ #
364
+ # @param [nil, #to_s] value the new attribute value
365
+ #
366
+ def pa_separation=(value)
367
+ @pa_separation = value && value.to_s.strip
368
+ end
369
+
370
+ # Sets the lateral_separation attribute.
371
+ #
372
+ # @param [nil, #to_s] value the new attribute value
373
+ #
374
+ def lateral_separation=(value)
375
+ @lateral_separation = value && value.to_s.strip
376
+ end
377
+
378
+ # Sets the tangential_separation attribute.
379
+ #
380
+ # @param [nil, #to_s] value the new attribute value
381
+ #
382
+ def tangential_separation=(value)
383
+ @tangential_separation = value && value.to_s.strip
384
+ end
385
+
386
+ # Sets the other_label_1 attribute.
387
+ #
388
+ # @param [nil, #to_s] value the new attribute value
389
+ #
390
+ def other_label_1=(value)
391
+ @other_label_1 = value && value.to_s
392
+ end
393
+
394
+ # Sets the ssd_1 attribute.
395
+ #
396
+ # @param [nil, #to_s] value the new attribute value
397
+ #
398
+ def ssd_1=(value)
399
+ @ssd_1 = value && value.to_s
400
+ end
401
+
402
+ # Sets the sfd_1 attribute.
403
+ #
404
+ # @param [nil, #to_s] value the new attribute value
405
+ #
406
+ def sfd_1=(value)
407
+ @sfd_1 = value && value.to_s
408
+ end
409
+
410
+ # Sets the other_label_2 attribute.
411
+ #
412
+ # @param [nil, #to_s] value the new attribute value
413
+ #
414
+ def other_label_2=(value)
415
+ @other_label_2 = value && value.to_s
416
+ end
417
+
418
+ # Sets the other_measurement_1 attribute.
419
+ #
420
+ # @param [nil, #to_s] value the new attribute value
421
+ #
422
+ def other_measurement_1=(value)
423
+ @other_measurement_1 = value && value.to_s
424
+ end
425
+
426
+ # Sets the other_measurement_2 attribute.
427
+ #
428
+ # @param [nil, #to_s] value the new attribute value
429
+ #
430
+ def other_measurement_2=(value)
431
+ @other_measurement_2 = value && value.to_s
432
+ end
433
+
434
+ # Sets the other_label_3 attribute.
435
+ #
436
+ # @param [nil, #to_s] value the new attribute value
437
+ #
438
+ def other_label_3=(value)
439
+ @other_label_3 = value && value.to_s
440
+ end
441
+
442
+ # Sets the other_measurement_3 attribute.
443
+ #
444
+ # @param [nil, #to_s] value the new attribute value
445
+ #
446
+ def other_measurement_3=(value)
447
+ @other_measurement_3 = value && value.to_s
448
+ end
449
+
450
+ # Sets the other_measurement_4 attribute.
451
+ #
452
+ # @param [nil, #to_s] value the new attribute value
453
+ #
454
+ def other_measurement_4=(value)
455
+ @other_measurement_4 = value && value.to_s
456
+ end
457
+
458
+ # Sets the other_label_4 attribute.
459
+ #
460
+ # @param [nil, #to_s] value the new attribute value
461
+ #
462
+ def other_label_4=(value)
463
+ @other_label_4 = value && value.to_s
464
+ end
465
+
466
+ # Sets the other_measurement_5 attribute.
467
+ #
468
+ # @param [nil, #to_s] value the new attribute value
469
+ #
470
+ def other_measurement_5=(value)
471
+ @other_measurement_5 = value && value.to_s
472
+ end
473
+
474
+ # Sets the other_measurement_6 attribute.
475
+ #
476
+ # @param [nil, #to_s] value the new attribute value
477
+ #
478
+ def other_measurement_6=(value)
479
+ @other_measurement_6 = value && value.to_s
480
+ end
481
+
482
+ # Sets the blade_x_mode attribute.
483
+ #
484
+ # @param [nil, #to_s] value the new attribute value
485
+ #
486
+ def blade_x_mode=(value)
487
+ @blade_x_mode = value && value.to_s
488
+ end
489
+
490
+ # Sets the blade_x attribute.
491
+ #
492
+ # @param [nil, #to_s] value the new attribute value
493
+ #
494
+ def blade_x=(value)
495
+ @blade_x = value && value.to_s
496
+ end
497
+
498
+ # Sets the blade_x1 attribute.
499
+ #
500
+ # @param [nil, #to_s] value the new attribute value
501
+ #
502
+ def blade_x1=(value)
503
+ @blade_x1 = value && value.to_s
504
+ end
505
+
506
+ # Sets the blade_x2 attribute.
507
+ #
508
+ # @param [nil, #to_s] value the new attribute value
509
+ #
510
+ def blade_x2=(value)
511
+ @blade_x2 = value && value.to_s
512
+ end
513
+
514
+ # Sets the blade_y_mode attribute.
515
+ #
516
+ # @param [nil, #to_s] value the new attribute value
517
+ #
518
+ def blade_y_mode=(value)
519
+ @blade_y_mode = value && value.to_s
520
+ end
521
+
522
+ # Sets the blade_y attribute.
523
+ #
524
+ # @param [nil, #to_s] value the new attribute value
525
+ #
526
+ def blade_y=(value)
527
+ @blade_y = value && value.to_s
528
+ end
529
+
530
+ # Sets the blade_y1 attribute.
531
+ #
532
+ # @param [nil, #to_s] value the new attribute value
533
+ #
534
+ def blade_y1=(value)
535
+ @blade_y1 = value && value.to_s
536
+ end
537
+
538
+ # Sets the blade_y2 attribute.
539
+ #
540
+ # @param [nil, #to_s] value the new attribute value
541
+ #
542
+ def blade_y2=(value)
543
+ @blade_y2 = value && value.to_s
544
+ end
545
+
546
+ # Sets the ii_lateral attribute.
547
+ #
548
+ # @param [nil, #to_s] value the new attribute value
549
+ #
550
+ def ii_lateral=(value)
551
+ @ii_lateral = value && value.to_s
552
+ end
553
+
554
+ # Sets the ii_longitudinal attribute.
555
+ #
556
+ # @param [nil, #to_s] value the new attribute value
557
+ #
558
+ def ii_longitudinal=(value)
559
+ @ii_longitudinal = value && value.to_s
560
+ end
561
+
562
+ # Sets the ii_vertical attribute.
563
+ #
564
+ # @param [nil, #to_s] value the new attribute value
565
+ #
566
+ def ii_vertical=(value)
567
+ @ii_vertical = value && value.to_s
568
+ end
569
+
570
+ # Sets the kvp attribute.
571
+ #
572
+ # @param [nil, #to_s] value the new attribute value
573
+ #
574
+ def kvp=(value)
575
+ @kvp = value && value.to_s
576
+ end
577
+
578
+ # Sets the ma attribute.
579
+ #
580
+ # @param [nil, #to_s] value the new attribute value
581
+ #
582
+ def ma=(value)
583
+ @ma = value && value.to_s
584
+ end
585
+
586
+ # Sets the seconds attribute.
587
+ #
588
+ # @param [nil, #to_s] value the new attribute value
589
+ #
590
+ def seconds=(value)
591
+ @seconds = value && value.to_s
592
+ end
593
+
594
+
595
+ private
596
+
597
+
598
+ # Collects the attributes of this instance.
599
+ #
600
+ # @note The CRC is not considered part of the attributes of interest and is excluded
601
+ # @return [Array<String>] an array of attributes
602
+ #
603
+ alias_method :state, :values
604
+
605
+ end
606
+
702
607
  end