Changeset 107


Ignore:
Timestamp:
Oct 12, 2008, 3:39:11 PM (10 years ago)
Author:
KOBAYASHI, Shinji
Message:

refs #39, #48

Location:
ruby/trunk/lib/models
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ruby/trunk/lib/models/rm/data_types/text.rb

    r106 r107  
    4646        class Code_Phrase
    4747          attr_reader :terminology_id, :code_string
    48           def initialize(terminology_id, code_string)
     48          def initialize(code_string, terminology_id)
     49            self.code_string = code_string
    4950            self.terminology_id = terminology_id
    50             self.code_string = code_string
    5151          end
    5252
  • ruby/trunk/lib/models/rm/support/identification.rb

    r106 r107  
    9494          attr_reader :name, :version_id
    9595
    96           def initialize(value, name , version_id="")
    97             self.value = value
     96          def initialize(name, version_id="")
    9897            self.name = name
    9998            self.version_id = version_id
    10099          end
    101100
    102           def value = (value)
     101          def value
     102            if @version_id.empty?
     103              @name
     104            else
     105              @name + '(' + @version_id + ')'
     106            end
     107          end
     108
     109
     110          def value=(value)
    103111            raise ArgumentError, "value not valid" if value.nil? or value.empty?
    104             if /(.*)(\(.*\)$)/ = value
     112            if /(.*)\((.*)\)$/ =~ value
    105113              @name = $1
    106114              @version_id = $2
     
    114122            raise ArgumentError, "name not valid" if name.nil? or name.empty?
    115123            @name = name
    116             if @version_id.empty?
    117               @value = name
    118             else
    119               @value = name + '(' + value ')'
    120             end
    121124          end
    122125
  • ruby/trunk/lib/models/tests/test_reference_model.rb

    r106 r107  
    3939    assert_nothing_raised(Exception){@object_ref = OpenEHR::RM::Support::Identification::Object_Ref.new('local', 'ANY', @object_id)}
    4040    assert_nothing_raised(Exception){@archetype_id = OpenEHR::RM::Support::Identification::Archetype_ID.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
    41     assert_nothing_raised(Exception){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new("0.0.7", 'terminology','0.0.3')}
     41    assert_nothing_raised(Exception){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new("ICD10",'2003')}
    4242    assert_nothing_raised(Exception){@generic_id = OpenEHR::RM::Support::Identification::Generic_ID.new("0.0.3", "openehr")}
    4343    assert_nothing_raised(Exception){@uid_based_id = OpenEHR::RM::Support::Identification::UID_Based_ID.new('rrip::0.0.3')}
     
    165165
    166166  def test_terminology_id
    167     assert_equal "0.0.7", @terminology_id.value
    168     assert_nothing_raised(Exception){@terminology_id.value = "0.0.8"}
    169     assert_equal "0.0.8", @terminology_id.value
     167    assert_equal "ICD10(2003)", @terminology_id.value
     168    assert_nothing_raised(Exception){@terminology_id.value = "ICD9(1999)"}
     169    assert_equal "ICD9", @terminology_id.name
     170    assert_equal "1999", @terminology_id.version_id
    170171    assert_raise(ArgumentError){@terminology_id.value = nil}
    171172    assert_raise(ArgumentError){@terminology_id.value = ""}
    172173
    173174    assert_raise(ArgumentError){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new}
    174     assert_raise(ArgumentError){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new(nil, 'terminology','0.0.3')}
    175     assert_raise(ArgumentError){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new("", 'terminology','0.0.3')}
    176     assert_raise(ArgumentError){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new("", 'terminology','0.0.3')}
    177     assert_raise(ArgumentError){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new("0.0.7", nil,'0.0.3')}
    178     assert_raise(ArgumentError){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new("0.0.7", '','0.0.3')}
    179     assert_raise(ArgumentError){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new("0.0.7", "terminology", nil)}
    180     assert_nothing_raised(Exception){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new("0.0.7", "terminology",'')}
    181 
    182     assert_equal "terminology", @terminology_id.name
    183     assert_nothing_raised(Exception){@terminology_id.name = "snomed"}
    184     assert_equal "snomed", @terminology_id.name
     175    assert_raise(ArgumentError){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new(nil,'2008')}
     176    assert_raise(ArgumentError){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new('','02008')}
     177    assert_raise(ArgumentError){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new("SNOMED", nil)}
     178    assert_nothing_raised(Exception){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new("SNOMED",'')}
     179
     180    assert_equal "SNOMED", @terminology_id.name
     181    assert_nothing_raised(Exception){@terminology_id.name = "LOINC"}
     182    assert_equal "LOINC", @terminology_id.name
    185183    assert_raise(ArgumentError){@terminology_id.name = nil}
    186184    assert_raise(ArgumentError){@terminology_id.name = ""}
    187185
    188186    assert_equal "", @terminology_id.version_id
    189     assert_nothing_raised(Exception){@terminology_id.version_id = "0.0.8"}
    190     assert_equal "0.0.8", @terminology_id.version_id
     187    assert_nothing_raised(Exception){@terminology_id.version_id = "2008"}
     188    assert_equal "2008", @terminology_id.version_id
     189    assert_equal 'LOINC(2008)', @terminology_id.value
    191190    assert_raise(ArgumentError){@terminology_id.version_id = nil}
    192191    assert_nothing_raised(Exception){@terminology_id.version_id = ''}
     
    353352  def setup
    354353    assert_nothing_raised(Exception){@dv_boolean = OpenEHR::RM::Data_Types::Basic::DV_Boolean.new("TRUE")}
    355     @terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new('C83.3', 'ICD10','')
    356     @code_phrase = OpenEHR::RM::Data_Types::Text::Code_Phrase(@terminology_id,
    357     @dv_coded_text = OpenEHR::RM::Data_Types::Text::DV_Coded_Text
    358     @dv_state = OpenEHR::RM::Data_Types::Basic::DV_State.new(OpenEHR::RM::Data_Types::Text:DV_Coded_Text.new("Chronic myeloid leukemia", @terminology_id), true)
     354    @terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new('ICD10')
     355    @code_phrase = OpenEHR::RM::Data_Types::Text::Code_Phrase.new('C92.0', @terminology_id)
     356    @dv_coded_text = OpenEHR::RM::Data_Types::Text::DV_Coded_Text.new("Acute Myeloyd Leukemia", @code_phrase)
     357    @dv_state = OpenEHR::RM::Data_Types::Basic::DV_State.new(@dv_coded_text, true)
    359358    @dv_identifier = OpenEHR::RM::Data_Types::Basic::DV_Identifier.new("Ruby Hospital","0123456-0", "Information office", "personal id")
    360359  end
     
    376375
    377376  def test_dv_state
    378     assert_equal("code1", @dv_state.value)
     377    assert_equal(@dv_coded_text, @dv_state.value)
    379378    assert_nothing_raised(Exception){@dv_state.value = "code2"}
    380379    assert_equal("code2", @dv_state.value)
     
    437436  def setup
    438437    assert_nothing_raised(Exception){@dv_text = OpenEHR::RM::Data_Types::Text::DV_Text.new("valid value")}
    439     @terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID('ICD10', '')
    440     assert_nothing_raised(Exception){@dv_coded_text = OpenEHR::RM::Data_Types::Text::DV_Coded_Text.new("C82.3", @terminology_id)}
     438    @terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new('ICD10', '')
     439   
     440    assert_nothing_raised(Exception){@code_phrase = OpenEHR::RM::Data_Types::Text::Code_Phrase.new('C92.0', @terminology_id)}
     441    assert_nothing_raised(Exception){@dv_coded_text = OpenEHR::RM::Data_Types::Text::DV_Coded_Text.new("Acute Myeloid Leukemia", @code_phrase)}
    441442    @dv_paragraph = OpenEHR::RM::Data_Types::Text::DV_Paragraph.new(Set.new(["test1", "test2"]))
    442443    @term_mapping = OpenEHR::RM::Data_Types::Text::Term_Mapping.new('=',@dv_coded_text,"TEST")
     
    445446  def test_init
    446447    assert_instance_of OpenEHR::RM::Data_Types::Text::DV_Text, @dv_text
     448    assert_instance_of OpenEHR::RM::Data_Types::Text::Code_Phrase, @code_phrase
    447449    assert_instance_of OpenEHR::RM::Data_Types::Text::DV_Coded_Text, @dv_coded_text
    448450    assert_instance_of OpenEHR::RM::Data_Types::Text::Term_Mapping, @term_mapping
     
    462464  end
    463465
     466  def test_code_phrase
     467    assert_equal 'C92.0', @code_phrase.code_string
     468    assert_equal 'ICD10', @code_phrase.terminology_id.value
     469    assert_nothing_raised(Exception){@code_phrase.code_string = 'C93.0'}
     470    assert_equal 'C93.0', @code_phrase.code_string
     471  end
     472
    464473  def test_dv_coded_text
    465     assert_equal("C83.2", @dv_coded_text.value)
    466     assert_equal("ICD10", @dv_coded_text.defining_code)
     474    assert_equal("Acute Myeloid Leukemia", @dv_coded_text.value)
     475    assert_equal("ICD10", @dv_coded_text.defining_code.terminology_id.name)
    467476    assert_raise(ArgumentError){@dv_coded_text.defining_code=nil}
    468477  end
Note: See TracChangeset for help on using the changeset viewer.