Class: RTP::Prescription

Inherits:
Record
  • Object
show all
Defined in:
lib/rtp-connect/prescription.rb

Overview

Note:

Relations:

  • Parent: Plan

  • Children: SiteSetup, SimulationField, Field

The Prescription site class.

Constant Summary

Constants inherited from Record

Record::NR_SURPLUS_ATTRIBUTES

Instance Attribute Summary collapse

Attributes inherited from Record

#attributes, #crc, #keyword

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Record

#encode, #get_parent, #load, #to_record, #to_s, #values

Constructor Details

#initialize(parent) ⇒ Prescription

Creates a new Prescription site.

Parameters:

  • parent (Record)

    a record which is used to determine the proper parent of this instance



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rtp-connect/prescription.rb', line 47

def initialize(parent)
  super('RX_DEF', 4, 13)
  # Child objects:
  @site_setup = nil
  @fields = Array.new
  @simulation_fields = Array.new
  # Parent relation (may get more than one type of record here):
  @parent = get_parent(parent.to_record, Plan)
  @parent.add_prescription(self)
  @attributes = [
    # Required:
    :keyword,
    :course_id,
    :rx_site_name,
    # Optional:
    :technique,
    :modality,
    :dose_spec,
    :rx_depth,
    :dose_ttl,
    :dose_tx,
    :pattern,
    :rx_note,
    :number_of_fields
  ]
end

Instance Attribute Details

#course_idObject

Returns the value of attribute course_id.



19
20
21
# File 'lib/rtp-connect/prescription.rb', line 19

def course_id
  @course_id
end

#dose_specObject

Returns the value of attribute dose_spec.



23
24
25
# File 'lib/rtp-connect/prescription.rb', line 23

def dose_spec
  @dose_spec
end

#dose_ttlObject

Returns the value of attribute dose_ttl.



25
26
27
# File 'lib/rtp-connect/prescription.rb', line 25

def dose_ttl
  @dose_ttl
end

#dose_txObject

Returns the value of attribute dose_tx.



26
27
28
# File 'lib/rtp-connect/prescription.rb', line 26

def dose_tx
  @dose_tx
end

#fieldsObject (readonly)

An array of Field records (if any) that belongs to this Prescription.



18
19
20
# File 'lib/rtp-connect/prescription.rb', line 18

def fields
  @fields
end

#modalityObject

Returns the value of attribute modality.



22
23
24
# File 'lib/rtp-connect/prescription.rb', line 22

def modality
  @modality
end

#number_of_fieldsObject

Returns the value of attribute number_of_fields.



29
30
31
# File 'lib/rtp-connect/prescription.rb', line 29

def number_of_fields
  @number_of_fields
end

#parentObject

The Record which this instance belongs to.



12
13
14
# File 'lib/rtp-connect/prescription.rb', line 12

def parent
  @parent
end

#patternObject

Returns the value of attribute pattern.



27
28
29
# File 'lib/rtp-connect/prescription.rb', line 27

def pattern
  @pattern
end

#rx_depthObject

Returns the value of attribute rx_depth.



24
25
26
# File 'lib/rtp-connect/prescription.rb', line 24

def rx_depth
  @rx_depth
end

#rx_noteObject

Returns the value of attribute rx_note.



28
29
30
# File 'lib/rtp-connect/prescription.rb', line 28

def rx_note
  @rx_note
end

#rx_site_nameObject

Returns the value of attribute rx_site_name.



20
21
22
# File 'lib/rtp-connect/prescription.rb', line 20

def rx_site_name
  @rx_site_name
end

#simulation_fieldsObject (readonly)

An array of SimulationField records (if any) that belongs to this Prescription.



16
17
18
# File 'lib/rtp-connect/prescription.rb', line 16

def simulation_fields
  @simulation_fields
end

#site_setupObject (readonly)

The SiteSetup record (if any) that belongs to this Prescription.



14
15
16
# File 'lib/rtp-connect/prescription.rb', line 14

def site_setup
  @site_setup
end

#techniqueObject

Returns the value of attribute technique.



21
22
23
# File 'lib/rtp-connect/prescription.rb', line 21

def technique
  @technique
end

Class Method Details

.load(string, parent) ⇒ Prescription

Creates a new Prescription site by parsing a RTPConnect string line.

Parameters:

  • string (#to_s)

    the prescription site definition record string line

  • parent (Record)

    a record which is used to determine the proper parent of this instance

Returns:

Raises:

  • (ArgumentError)

    if given a string containing an invalid number of elements



38
39
40
41
# File 'lib/rtp-connect/prescription.rb', line 38

def self.load(string, parent)
  p = self.new(parent)
  p.load(string)
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Checks for equality.

Other and self are considered equivalent if they are of compatible types and their attributes are equivalent.

Parameters:

  • other

    an object to be compared with self.

Returns:

  • (Boolean)

    true if self and other are considered equivalent



82
83
84
85
86
# File 'lib/rtp-connect/prescription.rb', line 82

def ==(other)
  if other.respond_to?(:to_prescription)
    other.send(:state) == state
  end
end

#add_field(child) ⇒ Object

Adds a treatment field record to this instance.

Parameters:

  • child (Field)

    a Field instance which is to be associated with self



94
95
96
97
# File 'lib/rtp-connect/prescription.rb', line 94

def add_field(child)
  @fields << child.to_field
  child.parent = self
end

#add_simulation_field(child) ⇒ Object

Adds a simulation field record to this instance.

Parameters:

  • child (Field)

    a SimulationField instance which is to be associated with self



103
104
105
106
# File 'lib/rtp-connect/prescription.rb', line 103

def add_simulation_field(child)
  @simulation_fields << child.to_simulation_field
  child.parent = self
end

#add_site_setup(child) ⇒ Object

Adds a site setup record to this instance.

Parameters:

  • child (SiteSetup)

    a SiteSetup instance which is to be associated with self



112
113
114
115
# File 'lib/rtp-connect/prescription.rb', line 112

def add_site_setup(child)
  @site_setup = child.to_site_setup
  child.parent = self
end

#childrenArray<SiteSetup, SimulationField, Field>

Collects the child records of this instance in a properly sorted array.

Returns:



121
122
123
# File 'lib/rtp-connect/prescription.rb', line 121

def children
  return [@site_setup, @simulation_fields, @fields].flatten.compact
end

#delete(record) ⇒ Object

Removes the reference of the given instance from this instance.

Parameters:



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/rtp-connect/prescription.rb', line 129

def delete(record)
  case record
  when Field
    delete_child(:fields, record)
  when SimulationField
    delete_child(:simulation_fields, record)
  when SiteSetup
    delete_site_setup
  else
    logger.warn("Unknown class (record) given to Prescription#delete: #{record.class}")
  end
end

#delete_fieldsObject

Removes all field references from this instance.



144
145
146
# File 'lib/rtp-connect/prescription.rb', line 144

def delete_fields
  delete_children(:fields)
end

#delete_simulation_fieldsObject

Removes all simulation_field references from this instance.



150
151
152
# File 'lib/rtp-connect/prescription.rb', line 150

def delete_simulation_fields
  delete_children(:simulation_fields)
end

#delete_site_setupObject

Removes the site setup reference from this instance.



156
157
158
# File 'lib/rtp-connect/prescription.rb', line 156

def delete_site_setup
  delete_child(:site_setup)
end

#hashFixnum

Note:

Two objects with the same attributes will have the same hash code.

Computes a hash code for this object.

Returns:

  • (Fixnum)

    the object’s hash code



166
167
168
# File 'lib/rtp-connect/prescription.rb', line 166

def hash
  state.hash
end

#to_prescriptionPrescription

Returns self.

Returns:



174
175
176
# File 'lib/rtp-connect/prescription.rb', line 174

def to_prescription
  self
end