<commit_before>class RecordsController < ApplicationController

  skip_before_filter :verify_authenticity_token
  before_filter :authenticate

  def create
    xml_file = params[:content].tempfile.read
    doc = Nokogiri::XML(xml_file)
    doc.root.add_namespace_definition('cda', 'urn:hl7-org:v3')
    patient = nil
    root_element_name = doc.root.name

    if root_element_name == 'ClinicalDocument'
      patient = QME::Importer::PatientImporter.instance.parse_c32(doc)
    elsif root_element_name == 'ContinuityOfCareRecord'
      if RUBY_PLATFORM =~ /java/
        ccr_importer = CCRImporter.instance
        patient_raw_json = ccr_importer.create_patient(xml_file)
        patient = JSON.parse(patient_raw_json)
      else
        render :text => 'CCR Support is currently disabled', :status => 500
      end
    else
      render :text => 'Unknown XML Format', :status => 400
    end

    if patient
      mongo['records'] << patient
      QME::QualityReport.destroy_all
      Atna.log(@user.username, :phi_import)
      Log.create(:username => @user.username, :event => 'patient record imported', :patient_id => patient['patient_id'])
      render :text => 'Patient imported', :status => 201<commit_msg>bug fix on uploading continuity of care data with the new importer that uses apache http commons for authentication<commit_after>class RecordsController < ApplicationController

  skip_before_filter :verify_authenticity_token
  before_filter :authenticate

  def create
    xml_file = request.body
    doc = Nokogiri::XML(xml_file)
    doc.root.add_namespace_definition('cda', 'urn:hl7-org:v3')
    patient = nil
    root_element_name = doc.root.name

    if root_element_name == 'ClinicalDocument'
      patient = QME::Importer::PatientImporter.instance.parse_c32(doc)
    elsif root_element_name == 'ContinuityOfCareRecord'
      if RUBY_PLATFORM =~ /java/
        ccr_importer = CCRImporter.instance
        patient_raw_json = ccr_importer.create_patient(xml_file)
        patient = JSON.parse(patient_raw_json)
      else
        render :text => 'CCR Support is currently disabled', :status => 500
      end
    else
      render :text => 'Unknown XML Format', :status => 400
    end

    if patient
      mongo['records'] << patient
      QME::QualityReport.destroy_all
      Atna.log(@user.username, :phi_import)
      Log.create(:username => @user.username, :event => 'patient record imported', :patient_id => patient['patient_id'])
      render :text => 'Patient imported', :status => 201
{'fraction_non_alphanumeric': 0.10127591706539076, 'fraction_numerical': 0.01036682615629984, 'mean_word_length': 3.6809701492537314, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '4875715', 'n_tokens_mistral': 787, 'n_tokens_neox': 735, 'n_words': 171}