2. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 8/4/2017 2:44:58 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

2.1 Files compared

# Location File Last Modified
1 CUI-Release-v2.2.0-source.zip\CUI-Release-v2.2.0-source\app\helpers exam_request_helper.rb Thu Jun 15 19:04:28 2017 UTC
2 CUI-Release-v2.2.0-source.zip\CUI-Release-v2.2.0-source\app\helpers exam_request_helper.rb Fri Aug 4 14:47:56 2017 UTC

2.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 968
Changed 1 2
Inserted 0 0
Removed 0 0

2.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

2.4 Active regular expressions

No regular expressions were active.

2.5 Comparison detail

  1   module Exa mRequestHe lper
  2     include  Contention ObjectHelp er, Reques tObjectHel per
  3  
  4     def proc essExamSch edulingReq uestCreate dEvent(exa m_request_ xml, exam_ request_ha sh)
  5       Active Record::Ba se.transac tion do
  6         #set Document(e xam_reques t_xml)
  7         exam Scheduling RequestCre atedEvent  = exam_req uest_hash[ 'feed']['e ntry']['co ntent']['E xamManagem entEventNo tification ']['ExamSc hedulingRe questCreat edEvent']
  8         clai m_informat ion = exam Scheduling RequestCre atedEvent[ 'ClaimInfo rmation']
  9         vete ran_servic e_member_i nfo = clai m_informat ion['Veter anServiceM emberInfo' ]
  10         ssn  = "" # ssn _assignmen t({vet_inf o: veteran _service_m ember_info })
  11         vbms ClaimId =  claim_info rmation['c laimId']
  12  
  13         @cla im = creat e_or_updat e_claim({c laim_info:  claim_inf ormation,
  14                                            ve t_info: ve teran_serv ice_member _info,
  15                                            ss n: ssn,
  16                                            vb ms_claim_i d: vbmsCla imId})
  17  
  18   #      cre ate_geo_lo cation({cl aim_id: @c laim.id, v et_info_xm l: veteran _service_m ember_info })
  19   #      cre ate_servic e_periods( {claim_id:  @claim.id , vet_info _xml: vete ran_servic e_member_i nfo})
  20   #      cre ate_region al_office( {vet_info_ xml: veter an_service _member_in fo})
  21  
  22         orig _notificat ion = Noko giri::XML( exam_reque st_xml)
  23         dest ination_do c = XmlHel per.getDoc (orig_noti fication,  'Destinati on')
  24         proc ess_conten tions({ori g_notifica tion: orig _notificat ion, claim _id: @clai m.id})
  25  
  26         exam _request_i d = examSc hedulingRe questCreat edEvent['e xamSchedul ingRequest Id']
  27         exam _request_d ate = exam Scheduling RequestCre atedEvent[ 'eventDtg' ]
  28         spec ial_consid erations =  "" # find _special_c onsiderati ons({xml_d oc: exam_r equest_xml })
  29         site  = get_sit e(destinat ion_doc)
  30         syst em_name =  destinatio n_doc['par ticipating SystemName ']
  31         exam _request_s tate = Exa mRequestSt ate.find_b y_code("IN _PROGRESS" )
  32  
  33         @exa m_request  = ExamRequ est.create ( claim_id : @claim.i d,
  34                                                 particip ating_syst em_name: s ystem_name ,
  35                                                 request_ date: exam _request_d ate,
  36                                                 request_ id: exam_r equest_id,
  37                                                 special_ issues: sp ecial_cons iderations ,
  38                                                 site_id:  site.id.t o_s,
  39                                                 identifi er: Secure Random.uui d,
  40                                                 exam_req uest_state _id: exam_ request_st ate.id)
  41  
  42         crea teRequestO bject exam _request_x ml, @claim .id
  43         send _emails_to _triage_us ers site
  44       end
  45     end
  46  
  47     def proc ess_rework ed_exam_sc heduling_r equest_cre ated_event (exam_requ est_xml, e xam_reques t_hash)
  48       puts " Processing "
  49       Active Record::Ba se.transac tion do
  50         rewo rkedExamSc hedulingRe questCreat edEvent =  exam_reque st_hash['f eed']['ent ry']['cont ent']['Exa mManagemen tEventNoti fication'] ['Reworked ExamSchedu lingReques tCreatedEv ent']
  51         clai mInformati on = rewor kedExamSch edulingReq uestCreate dEvent['Cl aimInforma tion']
  52  
  53         vbms ClaimId =  claimInfor mation['cl aimId']
  54         clai mFromDb =  Claim.find _by_vbms_c laim_id vb msClaimId
  55  
  56         if c laimFromDb .nil?
  57           ra ise "Claim  with ID:  #{vbmsClai mId}, does  not exist ."
  58         end
  59  
  60         orig _notificat ion = Noko giri::XML( exam_reque st_xml)
  61         dest ination_do c = XmlHel per.getDoc (orig_noti fication,  'Destinati on')
  62  
  63         rewo rked_exam_ scheduling _request_c reated_eve nt = XmlHe lper.getDo c(orig_not ification,  'Reworked ExamSchedu lingReques tCreatedEv ent')
  64         exam _related_c ontentions  = XmlHelp er.getDoc( reworked_e xam_schedu ling_reque st_created _event, 'E xamReworkR elatedCont entions')
  65  
  66         exam _related_c ontentions .elements. each do |c ontention|
  67           de sc = XmlHe lper.getDo c(contenti on, 'Conte ntionDescr iption').t ext
  68  
  69           ex am_related _contentio n_id = con tention['e xamRelated Contention Id']
  70  
  71           pr eviously_w orked_cont ention_id  = contenti on['previo uslyWorked Contention Id']
  72  
  73           @c ontention  = Contenti on.create( exam_relat ed_content ion_id: ex am_related _contentio n_id, clai m_id: clai mFromDb.id , identifi er: Secure Random.uui d, insuffi cient: tru e, previou sly_worked _contentio n_id: prev iously_wor ked_conten tion_id)
  74           Co ntentionDe tail.creat e(descript ion: desc,  name: con tention['n ame'], con tention_id : @content ion.id, ac tive: true )
  75  
  76           ex am_priorit ization_sp ecial_issu es = XmlHe lper.getDo c(contenti on, 'ExamP rioritizat ionSpecial Issues')
  77           ex am_priorit ization_sp ecial_issu es.element s.each do  |special_i ssue|
  78              issue = Xm lHelper.ge tDoc(speci al_issue,  'SpecialIs sue').text
  79              @contentio n.exam_pri oritizatio n_special_ issues <<  ExamPriori tizationSp ecialIssue .create(sp ecial_issu e: issue.t o_s)
  80           en d
  81  
  82           re work_reaso ns = XmlHe lper.getAl l(contenti on, 'Rewor kReason')
  83           re work_reaso ns.each do  |rework_r eason|
  84              @contentio n.rework_r easons <<  ReworkReas on.create( reason: re work_reaso n.text.str ip)
  85           en d
  86  
  87           re work_reaso n_free_tex t_list = X mlHelper.g etAll(cont ention, 'R eworkReaso nFreetext' )
  88           re work_reaso n_free_tex t_list.eac h do |reas on|
  89              @contentio n.rework_r eason_free _texts <<  ReworkReas onFreeText .create(re ason: reas on.text.st rip)
  90           en d
  91  
  92           ad dOrUpdateC ontentionO bject(cont ention, re worked_exa m_scheduli ng_request _created_e vent)
  93         end
  94  
  95         site  = get_sit e(destinat ion_doc)
  96         crea te_exam_re quest exam _request_x ml, orig_n otificatio n, claimFr omDb, site
  97         #Req uestObject  processin g
  98         crea te_reworke d_request_ object(exa m_request_ xml, claim FromDb.id)
  99         send _emails_to _triage_us ers site
  100       end
  101     end
  102  
  103     def proc essExamSch edulingReq uestCancel lationEven t(notifica tionDoc)
  104       examSc hedulingRe questCance llationEve nt = XmlHe lper.getDo c(notifica tionDoc, " ExamSchedu lingReques tCancellat ionEvent")
  105       previo usEventId  = examSche dulingRequ estCancell ationEvent ['previous Event']
  106       examSc hedulingRe questId =  examSchedu lingReques tCancellat ionEvent[' examSchedu lingReques tId']
  107       if (pr eviousEven tId.nil? o r previous EventId.em pty? or ex amScheduli ngRequestI d.nil? or  examSchedu lingReques tId.empty? )
  108         rais e Exceptio n, "Invali d previous Event"
  109       end
  110       if (ex amScheduli ngRequestI d.nil? or  examSchedu lingReques tId.empty? )
  111         rais e Exceptio n, "Invali d examSche dulingRequ estId"
  112       end
  113       reques tObject =  getRequest ObjectByEv entId(prev iousEventI d)
  114       if (re questObjec t.nil?)
  115         rais e Exceptio n, "Invali d previous Event. Una ble to loc ate the Ex amRequest  record"
  116       end
  117       if (va lidExamReq uestCancel lationData (previousE ventId, ex amScheduli ngRequestI d, request Object))
  118         exam Request =  ExamReques t.find_by_ claim_id(r equestObje ct.claim_i d)
  119         if ( examReques t.nil?)
  120           ra ise Except ion, "Unab le to loca te the Exa mRequest r ecord"
  121         end
  122         canc elExamRequ estExamina tions(exam Request)
  123         canc elExamRequ est(notifi cationDoc,  examReque st, reques tObject)
  124         upda teRequestO bjectWithE xamSchedul ingRequest Cancellati onEvent(ex amScheduli ngRequestC ancellatio nEvent, ex amRequest,  requestOb ject)
  125       end
  126     end
  127  
  128     def upda teRequestO bjectWithE xamSchedul ingRequest Cancellati onEvent(ex amScheduli ngRequestC ancellatio nEvent, ex amRequest,  requestOb ject)
  129       handle ExamSchedu lingReques tCancellat ionEvent(e xamSchedul ingRequest Cancellati onEvent, e xamRequest , requestO bject)
  130     end
  131  
  132     def canc elExamRequ estExamina tions(exam Request)
  133       @exami nations =  examReques t.claim.ex aminations
  134       if (@e xamination s != nil & & @examina tions.coun t > 0)
  135         #can cel associ ated exami nations
  136         canc elledExami nationStat e = Examin ationState .find_by_c ode("CANCE LLED")
  137         @exa minations. each_with_ index do | examinatio n, index|
  138           ex amination. examinatio n_state_id  = cancell edExaminat ionState.i d
  139           ex amination. cancellati on_reason  = "This ex amination  is cancell ed because  the paren t exam req uest has b een cancel led"
  140           ex amination. save
  141  
  142           no tes = "Thi s examinat ion is can celled bec ause the p arent exam  request h as been ca ncelled"
  143           @e xamination _history =  Examinati onHistory. new(examin ation_id:  examinatio n.id, note s: notes)
  144           @e xamination _history.s ave
  145  
  146           no tes = "Exa mination "
  147           no tes = note s + "(" +  appendCont entionName s(examinat ion.conten tions) + " ) has been  cancelled  as a resu lt of Exam  Request c ancellatio n"
  148           @@ exam_reque st_history  = ExamReq uestHistor y.new(exam _request_i d: examReq uest.id, n otes: note s)
  149           @@ exam_reque st_history .save
  150         end
  151       end
  152     end
  153  
  154     def canc elExamRequ est(notifi cationDoc,  examReque st, reques tObject)
  155       examRe questState  = ExamReq uestState. find_by_co de("CANCEL LED")
  156       examRe quest.exam _request_s tate_id =  examReques tState.id
  157       examCa ncellation Reason = X mlHelper.g etDoc(noti ficationDo c, "ExamCa ncellation Reason")
  158       examRe quest.canc ellation_r eason = ex amCancella tionReason .content
  159       examRe quest.save
  160       notes  = "Exam Re quest has  been cance lled"
  161       @exam_ request_hi story = Ex amRequestH istory.new (exam_requ est_id: ex amRequest. id, notes:  notes)
  162       @exam_ request_hi story.save
  163     end
  164  
  165     def vali dExamReque stCancella tionData(p reviousEve ntId, exam Scheduling RequestIdF romCancell ationReque st, reques tObject)
  166       reques tObjectDoc  = XmlHelp er.convert ToDocument (requestOb ject.xml)
  167       examSc hedulingRe quest = Xm lHelper.ge tDoc(reque stObjectDo c, "ExamSc hedulingRe quest")
  168       examSc hedulingRe questId =  examSchedu lingReques t['examSch edulingReq uestId']
  169       if (ex amScheduli ngRequestI d != examS chedulingR equestIdFr omCancella tionReques t)
  170         rais e Exceptio n, "Invali d examSche dulingRequ estId. Una ble to loc ate the Ex amRequest  record"
  171       end
  172       return  true
  173     end
  174  
  175     def crea te_or_upda te_claim(a rgs = {})
  176       claim_ info = arg s[:claim_i nfo]
  177       vet_in fo = args[ :vet_info]
  178       ssn =  args[:ssn]
  179       vbms_c laim_id =  args[:vbms _claim_id]
  180  
  181       claim  = Claim.fi nd_or_crea te_by(vbms _claim_id:  vbms_clai m_id)
  182       claim. patient_ss n = ssn
  183       claim. claim_date  = claim_i nfo['claim Date']
  184       claim. label = cl aim_info[' claimLabel ']
  185       claim. end_produc t_code = c laim_info[ 'endProduc tCode']
  186       claim. vbms_claim _id = vbms _claim_id
  187       claim. edipi = ve t_info['ED IPI']
  188       claim. participan t_id = vet _info['par ticipantId ']
  189       claim. gender = v et_info['g ender']
  190       claim. vista_ien  = vet_info ['vistaIen ']
  191       claim. file_numbe r = vet_in fo['fileNu mber']
  192       claim. first_name  = vet_inf o['firstNa me']
  193       claim. middle_nam e = vet_in fo['middle Name']
  194       claim. last_name  = vet_info ['lastName ']
  195       claim. date_of_bi rth = vet_ info['date OfBirth']
  196       claim. email = ve t_info['em ailAddress ']
  197       #claim .phone_num ber = vet_ info.dig(' Phone','pr imaryPhone ')
  198       #claim .alternate _phone = v et_info.di g('Phone', 'alternate Phone')
  199       #claim .integrati on_control _number =  vet_info.d ig('Integr ationContr olNumber', 'Value')
  200       claim. poa_vso_na me = vet_i nfo['PoaVs oName']
  201       claim. poa_vso_nu mber = vet _info['Poa VsoNumber' ]
  202       #claim .regional_ office_id  = vet_info .dig('Regi onalOffice ','station Number')
  203       claim. benefit_ty pe = claim _info['ben efitProgra mType']
  204  
  205       claim. save
  206       claim
  207     end
  208  
  209     def ssn_ assignment (args = {} )
  210       ssn =  args[:vet_ info]['Soc ialSecurit yNumber'][ 'Value']
  211       ssn.ni l? ? "-" :  ssn
  212     end
  213  
  214     def get_ site(desti nation_doc )
  215       contra ctorName =  destinati on_doc['co ntractorNa me']
  216       siteFr omDb = Sit e.find_by_ name(contr actorName)
  217       siteFr omDb.nil?  ? raise(Ex ception, " Invalid Co ntractor : :: " + con tractorNam e) : siteF romDb
  218     end
  219  
  220     def crea te_geo_loc ation(args ={})
  221       claim_ id = args[ :claim_id]
  222       vet_in fo = args[ :vet_info_ xml]
  223       xml =  vet_info[' PreferredG eographicL ocation']
  224  
  225       return  if vet_in fo['Prefer redGeograp hicLocatio n'].nil?
  226       geo_lo cation = P referredGe oLocation. find_or_cr eate_by(cl aim_id: cl aim_id, zi p: xml['Zi pCode'])
  227       geo_lo cation.cla im_id = cl aim_id
  228       geo_lo cation.add ress_1 = x ml['Addres s1']
  229       geo_lo cation.add ress_2 = x ml['Addres s2']
  230       geo_lo cation.add ress_3 = x ml['Addres s3']
  231       geo_lo cation.cit y = xml['C ity']
  232       geo_lo cation.sta te = xml[' State']
  233       geo_lo cation.zip  = xml['Zi pCode']
  234       geo_lo cation.sav e
  235     end
  236  
  237     def crea te_service _periods(a rgs = {})
  238       claim_ id = args[ :claim_id]
  239       vet_in fo = args[ :vet_info_ xml]
  240       period s = vet_in fo['Period sOfService ']['Period ']
  241  
  242       return  if vet_in fo['Period sOfService ']['Period '].nil?
  243       Array. wrap(perio ds).each d o |period|
  244         eras  = ""
  245         entr y_date = p eriod['ent ryOnDuty'] .to_dateti me
  246         end_ date = per iod['servi ceEndDate' ].to_datet ime
  247         bran ch = perio d['branchO fService']
  248         peri od['Eras'] .each { |e ra| eras < < "#{era}  " } if per iod['Eras' ].present?
  249  
  250         serv ice_period  = Service Period.fin d_or_creat e_by(claim _id: claim _id, entry _on_duty:  entry_date )
  251         serv ice_period .entry_on_ duty = ent ry_date
  252         serv ice_period .service_e nd_date =  end_date
  253         serv ice_period .branch_of _service =  branch
  254         serv ice_period .eras = er as.strip
  255         serv ice_period .claim_id  = claim_id
  256         serv ice_period .save
  257       end
  258     end
  259  
  260     def crea te_regiona l_office(a rgs = {})
  261       vet_in fo = args[ :vet_info_ xml]
  262       xml =  vet_info[' RegionalOf fice']
  263       statio n_number =  xml['stat ionNumber' ]
  264  
  265       if Reg ionalOffic e.find_by_ station_nu mber(stati on_number) .nil?
  266         city  = xml['Ph ysicalAddr ess']['Cit y']
  267         stat e = xml['P hysicalAdd ress']['St ate']
  268         zip  = xml['Phy sicalAddre ss']['ZipC ode']
  269         coun try = xml[ 'PhysicalA ddress'][' Country']
  270         m_ci ty = xml[' MailingAdd ress']['Ci ty']
  271         m_st ate = xml[ 'MailingAd dress']['S tate']
  272         m_zi p = xml['M ailingAddr ess']['Zip Code']
  273         m_co untry = xm l['Mailing Address'][ 'Country']
  274  
  275         regi onal_offic e = Region alOffice.n ew
  276         regi onal_offic e.station_ number = s tation_num ber
  277         regi onal_offic e.physical _address =  "#{city}  #{state} # {zip} #{co untry}"
  278         regi onal_offic e.mailing_ address =  "#{m_city}  #{m_state } #{m_zip}  #{m_count ry}"
  279         regi onal_offic e.save
  280       end
  281     end
  282  
  283     def find _special_c onsiderati ons (args= {})
  284       orig_x ml = Nokog iri::XML(a rgs[:xml_d oc])
  285       specia l_xml_elem ent = orig _xml.at('/ /em:'+'Spe cialIssue' ,
  286                                              em: 'http: // DNS     /vler/sche mas/vlerSu persetSche ma/examMan agement/1. 0')
  287  
  288       specia l_consider ations = " "
  289       return  special_c onsiderati ons if spe cial_xml_e lement.nil ?
  290  
  291       specia l_xml_elem ent.childr en.each do  |c|
  292         spec ial_consid erations + = c.text +  ", "
  293       end
  294  
  295       specia l_consider ations.cho mp!(", ")
  296       specia l_consider ations
  297     end
  298  
  299     def proc ess_conten tions(args ={})
  300       orig_n otificatio n = args[: orig_notif ication]
  301       claim_ id = args[ :claim_id]
  302  
  303       exam_s cheduling_ request_cr eated_even t = XmlHel per.getDoc (orig_noti fication,  'ExamSched ulingReque stCreatedE vent')
  304       exam_r elated_con tentions =  XmlHelper .getDoc(ex am_schedul ing_reques t_created_ event, 'Ex amRelatedC ontentions ')
  305  
  306       exam_r elated_con tentions.e lements.ea ch do |con tention|
  307         desc  = XmlHelp er.getDoc( contention , 'Content ionDescrip tion').tex t
  308         exam RelatedCon tentionId  = contenti on['examRe latedConte ntionId']
  309         cont entionFrom Db = Conte ntion.find _by_exam_r elated_con tention_id _and_claim _id(examRe latedConte ntionId, c laim_id)
  310         if c ontentionF romDb.nil?
  311           @c ontention  = Contenti on.create( exam_relat ed_content ion_id: ex amRelatedC ontentionI d,
  312                                               claim_id:  claim_id,
  313                                               identifier : SecureRa ndom.uuid)
  314           Co ntentionDe tail.creat e(descript ion: desc,
  315                                      name: co ntention[' name'],
  316                                      contenti on_id: @co ntention.i d,
  317                                      active:  true)
  318         end
  319         addO rUpdateCon tentionObj ect(conten tion, exam _schedulin g_request_ created_ev ent)
  320       end
  321     end
  322  
  323     def crea teRequestO bject(exam _request_x ml, claimI d)
  324       # Get  nokogiri d oc version s of the r equest obj ect templa te and the  incoming  ExamSchedu lingReques t notifica tion0
  325       templa te_path =  File.join( Rails.root .to_s, 'ap p', 'xml',  'template s', 'reque st_object_ template.x ml')
  326       req_ob ject_doc =  Nokogiri: :XML(File. open(templ ate_path))
  327       orig_n otificatio n_doc = No kogiri::XM L(exam_req uest_xml)
  328  
  329       on_esr ce = XmlHe lper.getDo c(orig_not ification_ doc, 'Exam Scheduling RequestCre atedEvent' ).attribut es
  330       examSc hedulingRe quest = Xm lHelper.ge tDoc(req_o bject_doc,  'ExamSche dulingRequ est')
  331       examSc hedulingRe quest['exa mSchedulin gRequestId '] = on_es rce['examS chedulingR equestId']
  332  
  333       # Copy  ClaimInfo rmation No de into re questObjec t template  doc
  334       ro_cla im_info =  XmlHelper. getDoc(req _object_do c, 'ClaimI nformation ')
  335       on_cla im_info =  XmlHelper. getDoc(ori g_notifica tion_doc,  'ClaimInfo rmation')
  336       ro_cla im_info.re place on_c laim_info. clone
  337       #claim Id = on_cl aim_info.a ttributes[ 'claimId'] .value
  338  
  339       # Copy  Contentio ns Node in to request Object tem plate doc
  340       ro_con tentions =  XmlHelper .getDoc(re q_object_d oc, 'Conte ntions')
  341       on_con tentions =  XmlHelper .getDoc(or ig_notific ation_doc,  'ExamRela tedContent ions')
  342       ro_con tentions.r eplace on_ contention s.clone
  343       XmlHel per.getDoc (req_objec t_doc, 'Ex amRelatedC ontentions ').name =  "Contentio ns"
  344  
  345       # Copy  ExamSched ulingReque stCreatedE vent Node  into reque stObject t emplate do c
  346       ro_esr _created_e vent = Xml Helper.get Doc(req_ob ject_doc,  'ExamSched ulingReque stCreatedE vent')
  347       on_esr _created_e vent = Xml Helper.get Doc(orig_n otificatio n_doc, 'Ex amScheduli ngRequestC reatedEven t')
  348       ro_esr _created_e vent.repla ce on_esr_ created_ev ent.clone
  349  
  350       # Copy  EventSour ce Node in to request Object tem plate doc  (there are  multiple  occurrance s in reque st_object_ doc, hence  the searc h().each)
  351       req_ob ject_doc.s earch('//e m:EventSou rce').each  do |es|
  352         on_e vent_sourc e = XmlHel per.getDoc (orig_noti fication_d oc, 'Event Source')
  353         es.r eplace on_ event_sour ce.clone
  354       end
  355  
  356       # Copy  these val ues direct ly
  357       ro_era e = XmlHel per.getDoc (req_objec t_doc, 'Ex amRequestA cknowledge mentEvent' ).attribut es
  358      # on_es rce = XmlH elper.getD oc(orig_no tification _doc, 'Exa mSchedulin gRequestCr eatedEvent ').attribu tes
  359       ro_era e['examSch edulingReq uestId'].v alue = on_ esrce['exa mSchedulin gRequestId ']
  360       ro_era e['eventId '].value =  on_esrce[ 'eventId']
  361       ro_era e['eventDt g'].value  = on_esrce ['eventDtg ']
  362       ro_era e['modelVe rsion'].va lue = on_e srce['mode lVersion']
  363       eventI d = ro_era e['eventId '].value
  364  
  365       # Find  the most  recent req uestObject  record wh ich matche s the clai m_id from  the incomi ng request .
  366       # q
  367       # If p resent, se t active=f alse. Then  add the n ew active  requestObj ect record .
  368       reqObj ect = Requ estObject. all.order( 'created_a t desc').f ind_by_cla im_id clai mId
  369       if req Object.pre sent?
  370         reqO bject.upda te(active:  false)
  371         reqO bject.save
  372       end
  373       reqObj ect = Requ estObject. create(req uest_type:  "ExamSche dulingRequ estCreated Event_Noti fication",  event_id:  eventId,  claim_id:  claimId, a ctive: tru e, xml: re q_object_d oc.to_xml)
  374  
  375       examRe q = ExamRe quest.find _by_claim_ id(claimId )
  376       examAc kNotificat ion = Exam RequestAck nowledgeme ntNotifica tion.new
  377       eventI d = examAc kNotificat ion.build_ notificati on(orig_no tification _doc, req_ object_doc , examReq. site)
  378       VlerDA SJob.sendN otificatio n(examAckN otificatio n, eventId , claimId,  "Exam Req uest Ackno wledgement  Event Not ification" )
  379     end
  380  
  381     def crea te_reworke d_request_ object(exa m_request_ xml, claim Id)
  382       # Get  nokogiri d oc version s of the r equest obj ect templa te and the  incoming  ExamSchedu lingReques t notifica tion0
  383       templa te_path =  File.join( Rails.root .to_s, 'ap p', 'xml',  'template s', 'rewor ked_exam_s cheduling_ request_ob ject_templ ate.xml')
  384       req_ob ject_doc =  Nokogiri: :XML(File. open(templ ate_path))
  385       orig_n otificatio n_doc = No kogiri::XM L(exam_req uest_xml)
  386  
  387       on_esr ce = XmlHe lper.getDo c(orig_not ification_ doc, 'Rewo rkedExamSc hedulingRe questCreat edEvent'). attributes
  388       examSc hedulingRe quest = Xm lHelper.ge tDoc(req_o bject_doc,  'Reworked ExamSchedu lingReques t')
  389       examSc hedulingRe quest['exa mSchedulin gRequestId '] = on_es rce['examS chedulingR equestId'] .value
  390  
  391       # Copy  ClaimInfo rmation No de into re questObjec t template  doc
  392       ro_cla im_info =  XmlHelper. getDoc(req _object_do c, 'ClaimI nformation ')
  393       on_cla im_info =  XmlHelper. getDoc(ori g_notifica tion_doc,  'ClaimInfo rmation')
  394       ro_cla im_info.re place on_c laim_info. clone
  395       #claim Id = on_cl aim_info.a ttributes[ 'claimId'] .value
  396  
  397       # Copy  Contentio ns Node in to request Object tem plate doc
  398       ro_con tentions =  XmlHelper .getDoc(re q_object_d oc, 'Conte ntions')
  399       on_con tentions =  XmlHelper .getDoc(or ig_notific ation_doc,  'ExamRewo rkRelatedC ontentions ')
  400       ro_con tentions.r eplace on_ contention s.clone
  401       XmlHel per.getDoc (req_objec t_doc, 'Ex amReworkRe latedConte ntions').n ame = "Con tentions"
  402  
  403       # Copy  ExamSched ulingReque stCreatedE vent Node  into reque stObject t emplate do c
  404       ro_esr _created_e vent = Xml Helper.get Doc(req_ob ject_doc,  'ReworkedE xamSchedul ingRequest CreatedEve nt')
  405       on_esr _created_e vent = Xml Helper.get Doc(orig_n otificatio n_doc, 'Re workedExam Scheduling RequestCre atedEvent' )
  406       ro_esr _created_e vent.repla ce on_esr_ created_ev ent.clone
  407  
  408       # Copy  EventSour ce Node in to request Object tem plate doc  (there are  multiple  occurrance s in reque st_object_ doc, hence  the searc h().each)
  409       req_ob ject_doc.s earch('//e m:EventSou rce').each  do |es|
  410         on_e vent_sourc e = XmlHel per.getDoc (orig_noti fication_d oc, 'Event Source')
  411         es.r eplace on_ event_sour ce.clone
  412       end
  413  
  414       # Copy  these val ues direct ly
  415       ro_era e = XmlHel per.getDoc (req_objec t_doc, 'Ex amRequestA cknowledge mentEvent' ).attribut es
  416      # on_es rce = XmlH elper.getD oc(orig_no tification _doc, 'Exa mSchedulin gRequestCr eatedEvent ').attribu tes
  417       ro_era e['examSch edulingReq uestId'].v alue = on_ esrce['exa mSchedulin gRequestId ']
  418       ro_era e['eventId '].value =  on_esrce[ 'eventId']
  419       ro_era e['eventDt g'].value  = on_esrce ['eventDtg ']
  420       ro_era e['modelVe rsion'].va lue = on_e srce['mode lVersion']
  421       ro_era e['previou sEvent'].v alue = on_ esrce['eve ntId']
  422       eventI d = ro_era e['eventId '].value
  423  
  424       # Find  the most  recent req uestObject  record wh ich matche s the clai m_id from  the incomi ng request .
  425       # If p resent, se t active=f alse. Then  add the n ew active  requestObj ect record .
  426       reqObj ect = Requ estObject. all.order( 'created_a t desc').f ind_by_cla im_id clai mId
  427       if req Object.pre sent?
  428         reqO bject.upda te(active:  false)
  429         reqO bject.save
  430       end
  431       reqObj ect = Requ estObject. create(req uest_type:  "Reworked ExamSchedu lingReques tCreatedEv ent_Notifi cation", e vent_id: e ventId, cl aim_id: cl aimId, act ive: true,  xml: req_ object_doc .to_xml)
  432  
  433       examAc kNotificat ion = Exam RequestAck nowledgeme ntNotifica tion.new
  434       eventI d = examAc kNotificat ion.build_ notificati on(orig_no tification _doc, req_ object_doc )
  435       VlerDA SJob.sendN otificatio n(examAckN otificatio n, eventId , claimId,  "Reworked  Exam Requ est Acknow ledgement  Event Noti fication")
  436     end
  437  
  438     def prep are_examin ation_capt ion(select ed_content ions)
  439       examin ation_capt ion = "Exa mination f or"
  440       select ed_content ions.each_ with_index  do |conte ntion, ind ex|
  441         capt ion_separa tor = ""
  442         if i ndex > 0 & & index ==  selected_ contention s.length-1
  443           ca ption_sepa rator = "  and "
  444         elsi f index >  0
  445           ca ption_sepa rator = ",  "
  446         else
  447           ca ption_sepa rator = "  "
  448         end
  449         exam ination_ca ption = ex amination_ caption +  caption_se parator +  contention .contentio n_details[ 0].name
  450       end
  451  
  452       examin ation_capt ion
  453     end
  454  
  455     def time _select
  456       option s_for_sele ct(['00:00 ', '00:30' , '01:00',  '01:30',  '02:00',
  457                             '02:30 ', '03:00' , '03:30',  '04:00',  '04:30',
  458                             '05:00 ', '05:30' , '06:00',  '06:30',  '07:00',
  459                             '07:30 ', '08:00' , '08:30',  '09:00',  '09:30',
  460                             '10:00 ', '10:30' , '11:00',  '11:30',  '12:00',
  461                             '12:30 ', '13:00' , '13:30',  '14:00',  '14:30',
  462                             '15:00 ', '15:30' , '16:00',  '16:30',  '17:00',
  463                             '17:30 ', '18:00' , '18:30',  '19:00',  '19:30',
  464                             '20:00 ', '20:30' , '21:00',  '21:30',  '22:00',
  465                             '22:30 ', '23:00' , '23:30'] )
  466     end
  467  
  468     private
  469     def crea te_exam_re quest exam _request_x ml, orig_n otificatio n, claim,  site
  470       exam_r equest_sta te = ExamR equestStat e.find_by_ code("IN_P ROGRESS")
  471  
  472       if exa m_request_ state.nil?
  473         #FIX  ME: Dont  throw this  exception  to outsid e world
  474         rais e Exceptio n, "Invali d Exam Req uest State  Id"
  475       end
  476       @exam_ request =  ExamReques t.create(c laim_id: c laim.id, s ite_id: si te.id.to_s , identifi er: Secure Random.uui d, exam_re quest_stat e_id: exam _request_s tate.id)
  477     end
  478  
  479     def send _emails_to _triage_us ers site
  480       site_t riage_user s = User.a ll.include s(:sites). where(:sit es => {nam e: site.na me}).inclu des(:site_ role_sets) .where(:si te_role_se ts => {tri age: "true "})
  481       site_t riage_user s.try(:eac h){|st|
  482         # Ex amManageme ntMailer.e xam_schedu ling_reque st_created (st).deliv er_now
  483       }
  484     end
  485   end