<commit_before>require 'test_helper'

class Cat3Test < MiniTest::Unit::TestCase
  def setup
    collection_fixtures('query_cache')

    @start_date = Time.now.years_ago(1)
    @end_date = Time.now
    @header = generate_header
    measure = {'hqmf_id' => "8A4D92B2-397A-48D2-0139-C648B33D5582", 'hqmf_set_id' => "AAAAAAAA-397A-48D2-0139-C648B33D5582"}
    @qrda_xml = HealthDataStandards::Export::Cat3.new.export([measure],@header, 1356998340, @start_date, @end_date)
    @doc = Nokogiri::XML(@qrda_xml)
    @doc.root.add_namespace_definition('cda', 'urn:hl7-org:v3')
  end

  def test_top_level_count
    ipp_count = @doc.at_xpath("//cda:observation[cda:templateId/@root='2.16.840.1.113883.10.20.27.3.5' and cda:value/@code='IPP']/cda:entryRelationship/cda:observation[cda:templateId/@root='2.16.840.1.113883.10.20.27.3.3']/cda:value")['value']
    assert_equal 3, ipp_count.to_i
  end

  def test_strat_count
    ipp_count = @doc.at_xpath("//cda:observation[cda:templateId/@root='2.16.840.1.113883.10.20.27.3.5' and cda:value/@code='IPP']/cda:entryRelationship/cda:observation[cda:templateId/@root='2.16.840.1.113883.10.20.27.3.4']/cda:entryRelationship/cda:observation/cda:value")['value']
    assert_equal 2, ipp_count.to_i
  end


  def generate_header
   header_hash=  {identifier: {root: "header_root", extension: "header_ext"},
     authors: [{ids: [ {root: "author_root" , extension: "author_extension"}],
                   device: {name:"dvice_name" , model: "device_mod"},
                   addresses:[],
                   telecoms: [],
                   time: Time.now,
                   organization: {ids: [ {root: "authors_organization_root" , extension: "authors_organization_ext"}],
                                  name: ""}}],
     custodian: {ids: [ {root: "custodian_root" , extension: "custodian_ext"}],
                 person: {given: "", family: ""},
                 organization: {ids: [ {root: "custodian_rganization_root" , extension: "custodian_organization_ext"}],
                                name: ""}},
     legal_authenticator:{ids: [ {root: "legal_authenticator_root" , extension: "legal_authenticator_ext"}],
                          addresses: [],
                          telecoms:[],
                          time: Time.now,
                          person: {given:"hey", family: "there"},
                          organization:{ids: [ {root: "legal_authenticator_org_root" , extension: "legal_authenticator_org_ext"}],
                                        name: ""}
                          }
      }
    
    Qrda::Header.new(header_hash)
  end
end<commit_msg>add a schema validation test for cat-3 exports<commit_after>require 'test_helper'

class Cat3Test < MiniTest::Unit::TestCase
  def setup
    collection_fixtures('query_cache')

    @start_date = Time.now.years_ago(1)
    @end_date = Time.now
    @header = generate_header
    measure = {'hqmf_id' => "8A4D92B2-397A-48D2-0139-C648B33D5582", 'hqmf_set_id' => "AAAAAAAA-397A-48D2-0139-C648B33D5582"}
    @qrda_xml = HealthDataStandards::Export::Cat3.new.export([measure],@header, 1356998340, @start_date, @end_date)
    @doc = Nokogiri::XML(@qrda_xml)
    @doc.root.add_namespace_definition('cda', 'urn:hl7-org:v3')
  end

  def test_top_level_count
    ipp_count = @doc.at_xpath("//cda:observation[cda:templateId/@root='2.16.840.1.113883.10.20.27.3.5' and cda:value/@code='IPP']/cda:entryRelationship/cda:observation[cda:templateId/@root='2.16.840.1.113883.10.20.27.3.3']/cda:value")['value']
    assert_equal 3, ipp_count.to_i
  end

  def test_strat_count
    ipp_count = @doc.at_xpath("//cda:observation[cda:templateId/@root='2.16.840.1.113883.10.20.27.3.5' and cda:value/@code='IPP']/cda:entryRelationship/cda:observation[cda:templateId/@root='2.16.840.1.113883.10.20.27.3.4']/cda:entryRelationship/cda:observation/cda:value")['value']
    assert_equal 2, ipp_count.to_i
  end

  def test_schema_validation
    xsd = Nokogiri::XML::Schema(open("./resources/schema/infrastructure/cda/CDA_SDTC.xsd"))
    assert_equal [], xsd.validate(@doc), "Invalid Cat III document"
  end

  def generate_header
    header_hash=  {identifier: {root: "2.16.840.1.113883.4.6", extension: "header_ext"},
                   authors: [{ids: [ {root: "2.16.840.1.113883.4.7" , extension: "author_extension"}],
                              device: {name:"dvice_name" , model: "device_mod"},
                              addresses:[],
                              telecoms: [],
                              time: Time.now,
                              organization: {ids: [ {root: "2.16.840.1.113883.4.9" , extension: "authors_organization_ext"}],
                                             name: ""}}],
                   custodian: {ids: [ {root: "custodian_root" , extension: "custodian_ext"}],
                               person: {given: "", family: ""},
                               organization: {ids: [ {root: "2.16.840.1.113883.4.12" , extension: "custodian_organization_ext"}],
                                              name: ""}},
                   legal_authenticator:{ids: [ {root: "2.16.840.1.113883.4.14" , extension: "legal_authenticator_ext"}],
                                        addresses: [],
                                        telecoms:[],
                                        time: Time.now,
                                        person: {given:"hey", family: "there"},
                                        organization:{ids: [ {root: "2.16.840.1.113883.4.62" , extension: "legal_authenticator_org_ext"}],
                                                      name: ""}
                   }
    }

    Qrda::Header.new(header_hash)
  end
end
{'fraction_non_alphanumeric': 0.1515630488233228, 'fraction_numerical': 0.06708816297857394, 'mean_word_length': 2.2729885057471266, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 8, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4914621', 'n_tokens_mistral': 2148, 'n_tokens_neox': 1913, 'n_words': 249}