<commit_before>module Crucible
  module Tests
    class TrackOneTest < BaseSuite

      def id
        'Connectathon8Track1'
      end

      def description
        'Connectathon 8 Track 1 Tests'
      end

      def setup
        @resources = Crucible::Generator::Resources.new

        @patient = @resources.example_patient
        @patient.identifier = nil # clear the identifier, in case the server checks for duplicates

        @patient_us = @resources.example_patient_us
        @patient_us.xmlId = nil # clear the identifier, in case the server checks for duplicates
      end

      def teardown
        @client.destroy(FHIR::Patient, @patient_id) if !@patient_id.nil?
        @client.destroy(FHIR::Patient, @patient_us_id) if !@patient_us_id.nil?
      end

      #
      # Test if we can create a new Patient.
      #
      test 'C8T1_1A','Register a new patient' do
        metadata {
          links "#{REST_SPEC_LINK}#create"
          links 'http://wiki.hl7.org/index.php?title=FHIR_Connectathon_8#1._Register_a_new_patient'
          requires resource: 'Patient', methods: ['create']
          validates resource: 'Patient', methods: ['create']
        }

        reply = @client.create @patient
        @patient_id = reply.id

        assert_response_ok(reply)

        if !reply.resource.nil?
          temp = reply.resource.xmlId
          reply.resource.xmlId = nil
          warning { assert @patient.equals?(reply.resource), 'The server did not correctly preserve the Patient data.' }
          reply.resource.xmlId = temp
        end

        warning { assert_valid_resource_content_type_present(reply) }
        warning { assert_last_modified_present(reply) }
        warning { assert_valid_content_location_present(reply) }
      end

      #
      # Test if we can create a new Patient with US Extensions.
      #
      test 'C8T1_1B','Register a new patient - BONUS: Extensions' do
        metadata {
          links "#{REST_SPEC_LINK}#create"
          links 'http://wiki.hl7.org/index.php?title=FHIR_Connectathon_8#1._Register_a_new_patient'
          requires resource: 'Patient', methods: ['create']
          validates resource: 'Patient', methods: ['create']
        }

        reply = @client.create @patient_us
        @patient_us_id = reply.id

        assert_response_ok(reply)

        if !reply.resource.nil?
          temp = reply.resource.xmlId
          reply.resource.xmlId = nil
          warning { assert @patient.equals?(reply.resource), 'The server did not correctly preserve the Patient data.' }
          reply.resource.xmlId = temp
        end

        warning { assert_valid_resource_content_type_present(reply) }
        warning { assert_last_modified_present(reply) }
        warning { assert_valid_content_location_present(reply) }
      end

      #
      # Test if we can update a patient.
      #
      test 'C8T1_2A','Update a patient' do
        metadata {
          links "#{REST_SPEC_LINK}#update"
          links 'http://wiki.hl7.org/index.php?title=FHIR_Connectathon_8#2._Update_a_patient'
          requires resource: 'Patient', methods: ['create', 'update']
          validates resource: 'Patient', methods: ['update']
        }

        @patient.telecom[0].value='1-800-TOLL-FREE'
        @patient.name[0].given = ["Crocodile","Pants"]

        reply = @client.update @patient, @patient_id

        assert_response_ok(reply)

        if !reply.resource.nil?
          temp = reply.resource.xmlId
          reply.resource.xmlId = nil
          warning { assert @patient.equals?(reply.resource), 'The server did not correctly preserve the Patient data.' }
          reply.resource.xmlId = temp
        end

        warning { assert_valid_resource_content_type_present(reply) }
        warning { assert_last_modified_present(reply) }
        warning { assert_valid_content_location_present(reply) }
      end

      #
      # Test if we can update a patient with unmodified extensions.
      #
      test 'C8T1_2B','Update a patient - BONUS: Unmodified Extensions' do
        metadata {
          links "#{REST_SPEC_LINK}#update"
          links 'http://wiki.hl7.org/index.php?title=FHIR_Connectathon_8#2._Update_a_patient'
          requires resource: 'Patient', methods: ['create','update']
          validates resource: 'Patient', methods: ['update']
        }

        @patient_us.telecom[0].value='1-800-TOLL-FREE'
        @patient_us.name[0].given = ["Alligator","Pants"]

        reply = @client.update @patient_us, @patient_us_id

        assert_response_ok(reply)

        if !reply.resource.nil?
          temp = reply.resource.xmlId
          reply.resource.xmlId = nil
          warning { assert @patient.equals?(reply.resource), 'The server did not correctly preserve the Patient data.' }
          reply.resource.xmlId = temp
        end

        warning { assert_valid_resource_content_type_present(reply) }
        warning { assert_last_modified_present(reply) }
        warning { assert_valid_content_location_present(reply) }
      end

      #
      # Test if we can update a patient with modified extensions.
      #
      test 'C8T1_2C','Update a patient - BONUS: Modified Extensions' do
        metadata {
          links "#{REST_SPEC_LINK}#update"
          links 'http://wiki.hl7.org/index.php?title=FHIR_Connectathon_8#2._Update_a_patient'
          requires resource: 'Patient', methods: ['create','update']
          validates resource: 'Patient', methods: ['update']
        }

        @patient_us.extensions[0].value[:value].coding[0].code = '1569-3'
        @patient_us.extensions[1].value[:value].coding[0].code = '2186-5'

        reply = @client.update @patient_us, @patient_us_id

        assert_response_ok(reply)
<commit_msg>Fix extension reference in C8T1_2C<commit_after>module Crucible
  module Tests
    class TrackOneTest < BaseSuite

      def id
        'Connectathon8Track1'
      end

      def description
        'Connectathon 8 Track 1 Tests'
      end

      def setup
        @resources = Crucible::Generator::Resources.new

        @patient = @resources.example_patient
        @patient.identifier = nil # clear the identifier, in case the server checks for duplicates

        @patient_us = @resources.example_patient_us
        @patient_us.xmlId = nil # clear the identifier, in case the server checks for duplicates
      end

      def teardown
        @client.destroy(FHIR::Patient, @patient_id) if !@patient_id.nil?
        @client.destroy(FHIR::Patient, @patient_us_id) if !@patient_us_id.nil?
      end

      #
      # Test if we can create a new Patient.
      #
      test 'C8T1_1A','Register a new patient' do
        metadata {
          links "#{REST_SPEC_LINK}#create"
          links 'http://wiki.hl7.org/index.php?title=FHIR_Connectathon_8#1._Register_a_new_patient'
          requires resource: 'Patient', methods: ['create']
          validates resource: 'Patient', methods: ['create']
        }

        reply = @client.create @patient
        @patient_id = reply.id

        assert_response_ok(reply)

        if !reply.resource.nil?
          temp = reply.resource.xmlId
          reply.resource.xmlId = nil
          warning { assert @patient.equals?(reply.resource), 'The server did not correctly preserve the Patient data.' }
          reply.resource.xmlId = temp
        end

        warning { assert_valid_resource_content_type_present(reply) }
        warning { assert_last_modified_present(reply) }
        warning { assert_valid_content_location_present(reply) }
      end

      #
      # Test if we can create a new Patient with US Extensions.
      #
      test 'C8T1_1B','Register a new patient - BONUS: Extensions' do
        metadata {
          links "#{REST_SPEC_LINK}#create"
          links 'http://wiki.hl7.org/index.php?title=FHIR_Connectathon_8#1._Register_a_new_patient'
          requires resource: 'Patient', methods: ['create']
          validates resource: 'Patient', methods: ['create']
        }

        reply = @client.create @patient_us
        @patient_us_id = reply.id

        assert_response_ok(reply)

        if !reply.resource.nil?
          temp = reply.resource.xmlId
          reply.resource.xmlId = nil
          warning { assert @patient.equals?(reply.resource), 'The server did not correctly preserve the Patient data.' }
          reply.resource.xmlId = temp
        end

        warning { assert_valid_resource_content_type_present(reply) }
        warning { assert_last_modified_present(reply) }
        warning { assert_valid_content_location_present(reply) }
      end

      #
      # Test if we can update a patient.
      #
      test 'C8T1_2A','Update a patient' do
        metadata {
          links "#{REST_SPEC_LINK}#update"
          links 'http://wiki.hl7.org/index.php?title=FHIR_Connectathon_8#2._Update_a_patient'
          requires resource: 'Patient', methods: ['create', 'update']
          validates resource: 'Patient', methods: ['update']
        }

        @patient.telecom[0].value='1-800-TOLL-FREE'
        @patient.name[0].given = ["Crocodile","Pants"]

        reply = @client.update @patient, @patient_id

        assert_response_ok(reply)

        if !reply.resource.nil?
          temp = reply.resource.xmlId
          reply.resource.xmlId = nil
          warning { assert @patient.equals?(reply.resource), 'The server did not correctly preserve the Patient data.' }
          reply.resource.xmlId = temp
        end

        warning { assert_valid_resource_content_type_present(reply) }
        warning { assert_last_modified_present(reply) }
        warning { assert_valid_content_location_present(reply) }
      end

      #
      # Test if we can update a patient with unmodified extensions.
      #
      test 'C8T1_2B','Update a patient - BONUS: Unmodified Extensions' do
        metadata {
          links "#{REST_SPEC_LINK}#update"
          links 'http://wiki.hl7.org/index.php?title=FHIR_Connectathon_8#2._Update_a_patient'
          requires resource: 'Patient', methods: ['create','update']
          validates resource: 'Patient', methods: ['update']
        }

        @patient_us.telecom[0].value='1-800-TOLL-FREE'
        @patient_us.name[0].given = ["Alligator","Pants"]

        reply = @client.update @patient_us, @patient_us_id

        assert_response_ok(reply)

        if !reply.resource.nil?
          temp = reply.resource.xmlId
          reply.resource.xmlId = nil
          warning { assert @patient.equals?(reply.resource), 'The server did not correctly preserve the Patient data.' }
          reply.resource.xmlId = temp
        end

        warning { assert_valid_resource_content_type_present(reply) }
        warning { assert_last_modified_present(reply) }
        warning { assert_valid_content_location_present(reply) }
      end

      #
      # Test if we can update a patient with modified extensions.
      #
      test 'C8T1_2C','Update a patient - BONUS: Modified Extensions' do
        metadata {
          links "#{REST_SPEC_LINK}#update"
          links 'http://wiki.hl7.org/index.php?title=FHIR_Connectathon_8#2._Update_a_patient'
          requires resource: 'Patient', methods: ['create','update']
          validates resource: 'Patient', methods: ['update']
        }

        @patient_us.extension[0].value[:value].coding[0].code = '1569-3'
        @patient_us.extension[1].value[:value].coding[0].code = '2186-5'

        reply = @client.update @patient_us, @patient_us_id

        assert_response_ok(reply)

{'fraction_non_alphanumeric': 0.1014909756735548, 'fraction_numerical': 0.010724561862411719, 'mean_word_length': 2.5065729134821155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6188742', 'n_tokens_mistral': 3439, 'n_tokens_neox': 3266, 'n_words': 742}