1. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 9/11/2017 8:05:37 AM 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.

1.1 Files compared

# Location File Last Modified
1 MHV_CIF_2017.4.0.0.zip\MHV_CIF_2017.4.0.0\MHV_CIF_2017.4.0.0\ap_redesign\mhv_source\mhv_admin\mhv-admin-main\src\main\java\gov\va\med\mhv\admin\service\impl\mhvusers InPersonAuthenticationServiceImpl.java Mon Jul 24 21:04:58 2017 UTC
2 MHV_CIF_2017.4.0.0.zip\MHV_CIF_2017.4.0.0\MHV_CIF_2017.4.0.0\ap_redesign\mhv_source\mhv_admin\mhv-admin-main\src\main\java\gov\va\med\mhv\admin\service\impl\mhvusers InPersonAuthenticationServiceImpl.java Thu Sep 7 18:49:40 2017 UTC

1.2 Comparison summary

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

1.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

1.4 Active regular expressions

No regular expressions were active.

1.5 Comparison detail

  1   package go v.va.med.m hv.admin.s ervice.imp l.mhvusers ;
  2  
  3   import jav a.sql.Time stamp;
  4   import jav a.util.Arr ayList;
  5   import jav a.util.Dat e;
  6   import jav a.util.Lin kedHashMap ;
  7   import jav a.util.Lis t;
  8  
  9   import jav ax.ws.rs.C onsumes;
  10   import jav ax.ws.rs.G ET;
  11   import jav ax.ws.rs.P OST;
  12   import jav ax.ws.rs.P ath;
  13   import jav ax.ws.rs.P athParam;
  14   import jav ax.ws.rs.P roduces;
  15   import jav ax.ws.rs.c ore.MediaT ype;
  16  
  17   import org .apache.lo gging.log4 j.LogManag er;
  18   import org .apache.lo gging.log4 j.Logger;
  19   import org .springfra mework.bea ns.factory .annotatio n.Autowire d;
  20   import org .springfra mework.ste reotype.Co mponent;
  21   import org .springfra mework.ste reotype.Se rvice;
  22   import org .springfra mework.ste reotype.Co mponent;
  23   import org .springfra mework.tra nsaction.a nnotation. Transactio nal;
  24  
  25   import gov .va.med.mh v.admin.co nverter.Pa tientLocal Converter;
  26   import gov .va.med.mh v.admin.co nverter.Us erProfileL ocalConver ter;
  27   import gov .va.med.mh v.admin.en ums.Activi tyActionTy peEnumerat ion;
  28   import gov .va.med.mh v.admin.en ums.Activi tyActorTyp eEnumerati on;
  29   import gov .va.med.mh v.admin.en ums.Activi tyTypeEnum eration;
  30   import gov .va.med.mh v.admin.en ums.Authen ticationSt atusEnumer ation;
  31   import gov .va.med.mh v.admin.en ums.Patien tCorrelati onStatusEn umeration;
  32   import gov .va.med.mh v.admin.ex ception.MH VRuntimeEx ception;
  33   import gov .va.med.mh v.admin.re pository.I nPersonAut henticatio nRepositor y;
  34   import gov .va.med.mh v.admin.re pository.P atientRepo sitory;
  35   import gov .va.med.mh v.admin.re pository.E mployeeRep ository;
  36   import gov .va.med.mh v.admin.se rvice.mhvu sers.InPer sonAuthent icationSer vice;
  37   import gov .va.med.mh v.admin.se rvice.mhvu sers.MviIn tegrationS ervice;
  38   import gov .va.med.mh v.admin.ut il.Message sUtil;
  39   import gov .va.med.mh v.admin.se rvice.mhvu sers.Activ ityService ;
  40   import gov .va.med.mh v.common.a pi.dto.InP ersonAuthe nticationD TO;
  41   import gov .va.med.mh v.common.a pi.dto.Pat ientDTO;
  42   import gov .va.med.mh v.common.a pi.dto.Use rProfileDT O;
  43   import gov .va.med.mh v.common.a pi.excepti on.MHVExce ption;
  44   import gov .va.med.mh v.common.a pi.util.Re sponseUtil ;
  45   import gov .va.med.mh v.common.d ata.conver ter.InPers onAuthenti cationConv erter;
  46   import gov .va.med.mh v.common.d ata.conver ter.InPers onAuthenti cationLigh tConverter ;
  47   import gov .va.med.mh v.common.d ata.conver ter.Patien tConverter ;
  48   import gov .va.med.mh v.common.d ata.model. InPersonAu thenticati on;
  49   import gov .va.med.mh v.common.d ata.model. Patient;
  50   import gov .va.med.mh v.admin.mo del.Employ ee;
  51  
  52   @Path("/")
  53   @Service(" inPersonAu thenticati onService" )
  54   @Component
  55   public cla ss InPerso nAuthentic ationServi ceImpl imp lements In PersonAuth entication Service {
  56  
  57           pr ivate stat ic final I nPersonAut henticatio nConverter  IPA_CONVE RTER = new  InPersonA uthenticat ionConvert er();
  58           pr ivate stat ic final I nPersonAut henticatio nLightConv erter IPAL IGHT_CONVE RTER = new  InPersonA uthenticat ionLightCo nverter();
  59           pr ivate stat ic final P atientConv erter PATI ENT_CONVER TER = new  PatientCon verter();
  60  
  61           pr ivate stat ic Logger  log = LogM anager.get Logger(InP ersonAuthe nticationS erviceImpl .class);
  62  
  63           @A utowired
  64           pr ivate InPe rsonAuthen ticationRe pository i npersonAut henticatio nRepositor y;
  65  
  66           @A utowired
  67           pr ivate Pati entReposit ory patien tRepositor y;
  68  
  69           @A utowired
  70           pr ivate Empl oyeeReposi tory emplo yeeReposit ory;
  71  
  72           @A utowired
  73           In PersonAuth entication Converter  converter;
  74  
  75           @A utowired
  76           Us erProfileL ocalConver ter userPr ofileConve rter;
  77  
  78           @A utowired
  79           Mv iIntegrati onService  mviService ;
  80  
  81           @A utowired
  82           pr ivate Acti vityServic e activity Service;
  83  
  84           @A utowired
  85           Pa tientLocal Converter  patientCon verter;
  86           
  87           @A utowired
  88           pr ivate Mess agesUtil m essagesUti l;
  89           
  90  
  91           @O verride
  92           @G ET
  93           @P ath("/isPa tientAuthe nticated/{ patientId} ")
  94           @P roduces(Me diaType.AP PLICATION_ JSON)
  95           pu blic Boole an isPatie ntAuthenti cated(@Pat hParam("pa tientId")  Long patie ntId) thro ws MHVExce ption {
  96                    Syst em.out.pri ntln("**** ********** ********** ********** *********  isPatientA uthenticat ed method"  + patient Id);
  97                    List <InPersonA uthenticat ion> ipaPa tients = n ull;
  98                    InPe rsonAuthen tication i paPatient  = null;
  99                    Bool ean isPati entAUthent icated = f alse;
  100                    try  {
  101                             ipaPat ients = in personAuth entication Repository .getAuthen ticationFo rPatient(p atientId);
  102  
  103                             if (nu ll != ipaP atients &&  ipaPatien ts.size()  > 0) {
  104                                      ipaPatie nt = ipaPa tients.get (0);
  105                             } else  {
  106                                      throw ne w MHVExcep tion(
  107                                                       "E rror in ge tting pati net detail s from get Authentica tionForPat ient() " +  patientId );
  108                             }
  109  
  110                             if (nu ll != ipaP atient.get Status() & & ipaPatie nt.getStat us()
  111                                               .equalsIgn oreCase(Au thenticati onStatusEn umeration. AUTHENTICA TED.getDes cription() )) {
  112                                      isPatien tAUthentic ated = tru e;
  113                             } else  {
  114                                      isPatien tAUthentic ated = fal se;
  115                             }
  116                    } ca tch (Excep tion e) {
  117                             log.er ror("Error  in gettin g patinet  details fr om getAuth entication ForPatient () " + pat ientId, e) ;
  118                             throw  new MHVRun timeExcept ion(
  119                                               "Error in  getting pa tinet deta ils from g etAuthenti cationForP atient() "  + patient Id);
  120                    }
  121  
  122                    retu rn isPatie ntAUthenti cated;
  123           }
  124  
  125           @O verride
  126           @G ET
  127           @P ath("/getI PAPatientB yId/{patie ntId}")
  128           @P roduces(Me diaType.AP PLICATION_ JSON)
  129           pu blic InPer sonAuthent icationDTO  getIPAPat ientById(@ PathParam( "patientId ") Long pa tientId) t hrows MHVE xception {
  130                    List <InPersonA uthenticat ion> ipaPa tients = n ull;
  131                    InPe rsonAuthen tication i paPatient  = null;
  132                    InPe rsonAuthen ticationDT O inPerson Authentica tionDTO =  null;
  133                    try  {
  134                             ipaPat ients = in personAuth entication Repository .getAuthen ticationFo rPatient(p atientId);
  135  
  136                             if (nu ll != ipaP atients &&  ipaPatien ts.size()  > 0) {
  137                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - getIPAP atientById  - ipaPati ents is no t null");
  138                                      ipaPatie nt = ipaPa tients.get (0);
  139                             }
  140                             if (ip aPatient ! = null) {
  141                                      inPerson Authentica tionDTO =  converter. convertDom ainInperso nAuthentic ation(ipaP atient);
  142                                      converte r.addFacil ityInfoDto (ipaPatien t, inPerso nAuthentic ationDTO);
  143                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - getIPAP atientById  - inPerso nAuthentic ationDTO -  id:"+inPe rsonAuthen ticationDT O.getId()) ;
  144                             }
  145                    } ca tch (Excep tion e) {
  146                             log.er ror("Error  in gettin g patinet  details fr om getAuth entication ForPatient () " + pat ientId, e) ;
  147                             throw  new MHVRun timeExcept ion(
  148                                               "Error in  getting pa tinet deta ils from g etAuthenti cationForP atient() "  + patient Id);
  149                    }
  150  
  151                    retu rn inPerso nAuthentic ationDTO;
  152           }
  153  
  154           @O verride
  155           @P OST
  156           @P ath("/forc eUnauthent icateUnCor relateWith AdminUserN ame/{ipaId }/{adminUs erName}")
  157           @C onsumes(Me diaType.AP PLICATION_ JSON)
  158           @P roduces(Me diaType.AP PLICATION_ JSON)
  159           pu blic InPer sonAuthent icationDTO  forceUnau thenticate UnCorrelat eWithAdmin UserName(@ PathParam( "ipaId") L ong ipaId,
  160                             @PathP aram("admi nUserName" ) String a dminUserNa me) throws  MHVExcept ion {
  161                    Resp onseUtil<P atient> re sponse = n ew Respons eUtil();
  162                    InPe rsonAuthen tication i pa = null;
  163                    try  {
  164                             ipa =  inpersonAu thenticati onReposito ry.findOne (ipaId);
  165                             //Auth entication StatusEnum eration st atus = Aut henticatio nStatusEnu meration.U NAUTHENTIC ATED;
  166                             ipa.se tParticipa tionFormSi gned(Boole an.FALSE);
  167                             ipa.se tIdentific ationPrese nted(Boole an.FALSE);
  168                             ipa.se tApprovedF orRecordsA ccess(Bool ean.FALSE) ;
  169                             ipa.se tDeferment Reason(nul l);
  170                             ipa.se tAuthentic atingFacil ity(null);
  171                             ipa.se tAuthentic ationDate( null);
  172  
  173                             // Jaz z Id: 2309 89 - addin g HL7v3 Ve rsion code  in MVI Re quest
  174                             // Hea der.
  175                             mviSer vice.mviAu thenticate WithVersio n(patientC onverter.c onvertDoma inPatient( ipa.getPat ient()),
  176                                               userProfil eConverter .convertDo mainUserPr ofile(ipa. getPatient ().getUser Profile()) , false, f alse,
  177                                               adminUserN ame);
  178  
  179                             ipa.se tMviAuthen ticationSt atus(null) ;
  180                             ipa =  saveIPA(ip a, "Unauth enticated" );
  181                             System .out.print ln(
  182                                               "&&&&&&&&& &&&&&&&&&& & InPerson Authentica tionServic eImpl - Un authentica ted &&&&&& &&&&&&&& " );
  183                             mviSer vice.force Uncorrelat ion(ipa.ge tPatient() .getId(),  ipa.getPat ient().get UserProfil e().getId( ),
  184                                               adminUserN ame, respo nse);
  185                             
  186                    } ca tch (Excep tion e) {
  187                             log.er ror("Error  in gettin g patinet  details fr om getAuth entication ForPatient () ");
  188                             throw  new MHVRun timeExcept ion("Error  in gettin g patinet  details fr om getAuth entication ForPatient () ");
  189                    }
  190                    
  191                    retu rn convert er.convert DomainInpe rsonAuthen tication(i pa);
  192           }
  193  
  194           @O verride
  195           @G ET
  196           @P ath("/getA uthenticat ionForPati ent/{patie ntId}")
  197           @P roduces(Me diaType.AP PLICATION_ JSON)
  198           pu blic InPer sonAuthent icationDTO  getAuthen ticationFo rPatient(@ PathParam( "patientId ") Long pa tientId)
  199                             throws  MHVExcept ion {
  200                    InPe rsonAuthen ticationDT O response  = null;
  201                    InPe rsonAuthen tication i pa = null;
  202                    try  {
  203                             System .out.print ln(
  204                                               ">>>> InPe rsonAuthen ticationSe rviceImpl  - getAuthe nticationF orPatient  - patient: " + patien tId);
  205                             List<I nPersonAut henticatio n> bos = i npersonAut henticatio nRepositor y.getAuthe nticationF orPatient( patientId) ;
  206                             if (!b os.isEmpty ()) {
  207                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - getAuth entication ForPatient  - inside  if");
  208                                      ipa = bo s.get(0);
  209                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - getAuth entication ForPatient  - inside  if - ipaId :"+ ipa.ge tId());
  210                             } else  {
  211                                      //TODO:  Verify the  functiona lity in th e legacy c ode where  there is n o IPA reco rd for the  patient
  212                                      System.o ut
  213                                                       .p rintln(">> >> InPerso nAuthentic ationServi ceImpl - g etAuthenti cationForP atient - i nside else ");
  214                                      InPerson Authentica tion ipa1  = new InPe rsonAuthen tication() ;
  215                                      ipa1.set Status("Un authentica ted");
  216                                      ipa1.set VideoViewe d(Boolean. FALSE);
  217                                      ipa1.set Participat ionFormSig ned(Boolea n.FALSE);
  218                                      ipa1.set Identifica tionPresen ted(Boolea n.FALSE);
  219                                      ipa1.set ApprovedFo rRecordsAc cess(Boole an.FALSE);
  220                                      Patient  patient =  new Patien t();
  221                                      patient. setId(pati entId);
  222                                      ipa1.set Patient(pa tient);
  223                                      
  224                                       
  225                                      ipa = sa veIPA(ipa1 , "Unauthe nticated") ;
  226                                      // enter InfoLog("g etAuthenti cationForP atient():c reating ne w
  227                                      // IPA",  "ipa id:" ,
  228                                      // respo nse.getInP ersonAuthe ntication( ).getId()+ "");
  229                             }
  230                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - getAu thenticati onForPatie nt -before  conversio n :"+ ipa. getPatient Id()+"::"+ ipa.getPat ient().get Id());
  231                             respon se = conve rter.conve rtDomainIn personAuth entication (ipa);
  232                             conver ter.addPat ientDto(ip a, respons e);
  233                             conver ter.addFac ilityInfoD to(ipa, re sponse);
  234                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - getAu thenticati onForPatie nt -after  conversion  :"+respon se.getPati ent().getI d());                     
  235                    } ca tch (Excep tion e) {
  236                             log.er ror("Error  in gettin g patinet  details fr om getAuth entication ForPatient () " + pat ientId, e) ;
  237                             throw  new MHVRun timeExcept ion(
  238                                               "Error in  getting pa tinet deta ils from g etAuthenti cationForP atient() "  + patient Id);
  239                    }
  240  
  241                    //re turn conve rter.conve rtDomainIn personAuth entication (ipa);
  242                    retu rn respons e;
  243           }
  244           
  245           @T ransaction al
  246       privat e InPerson Authentica tion saveI PA(InPerso nAuthentic ation ipa,
  247                String s tatus)
  248           {        
  249                             //ipa. setMviAuth entication Status(sta tus);
  250                             ipa.se tStatus(st atus);
  251                             System .out.print ln(
  252                                               "&&&&&&&&& &&&&&&&&&& & InPerson Authentica tionServic eImpl - Un authentica ted &&&&&& &&&&&&&& "  + status) ;
  253                ipa = in personAuth entication Repository .save(ipa) ;
  254                return i pa;
  255           }
  256  
  257           
  258           @O verride
  259           @P OST
  260           @P ath("/defe rAuthentic ation")
  261           @C onsumes(Me diaType.AP PLICATION_ JSON)
  262           @P roduces(Me diaType.AP PLICATION_ JSON)
  263           @T ransaction al
  264           pu blic Respo nseUtil<Li st<InPerso nAuthentic ationDTO>>  deferAuth entication (InPersonA uthenticat ionDTO ipa DTO)
  265                             throws  MHVExcept ion {
  266                    Resp onseUtil<L ist<InPers onAuthenti cationDTO> > response  = new Res ponseUtil< List<InPer sonAuthent icationDTO >>();
  267                    try  {
  268                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - ipa DTO.getId( ): " + ipa DTO.getId( ));
  269                             InPers onAuthenti cation ipa  = convert er.convert InpersonAu thenticati onDTO(ipaD TO);
  270                             conver ter.addPat ientProfil e(ipaDTO,  ipa);
  271                             conver ter.addFac ilityInfo( ipaDTO, ip a);
  272                             
  273                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - Aft er convers ion - ipa. getId(): "  + ipa.get Id());                      
  274  
  275                             Boolea n formSign ed = ipa.g etParticip ationFormS igned() ==  null ? Bo olean.FALS E : ipa.ge tParticipa tionFormSi gned();
  276                             Boolea n idPresen ted = ipa. getIdentif icationPre sented() = = null ? B oolean.FAL SE : ipa.g etIdentifi cationPres ented();
  277                             Authen ticationSt atusEnumer ation stat us = null;
  278                             
  279                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - for mSigned: "  + formSig ned);
  280                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - idP resented:  " + idPres ented);
  281                             
  282                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - ipa .getPatien t().getId( ):" + ipa. getPatient ().getId() );
  283                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - ipa .getPatien tId():" +  ipa.getPat ientId());
  284  
  285                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - ipa .getAuthen ticatingFa cility().g etId():" +  ipa.getAu thenticati ngFacility ().getId() );
  286                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - ipa .getAuthen ticatingFa cilityId() :" + ipa.g etAuthenti catingFaci lityId());                               
  287                                                                                  
  288                             if (fo rmSigned.b ooleanValu e() && idP resented.b ooleanValu e()) {
  289                                      status =  Authentic ationStatu sEnumerati on.PREREQU ISITESCOMP LETE;
  290                             } else  {
  291                                      status =  Authentic ationStatu sEnumerati on.INPROCE SS;
  292                             }
  293                             ipa.se tRemovalRe ason(null) ;
  294                             ipa.se tStatus(st atus.getDe scription( ));          
  295                             
  296                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - Jus t before s aving - ip a.getId():  " + ipa.g etId());
  297                             ipa =  inpersonAu thenticati onReposito ry.save(ip a);
  298                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - Jus t After sa ving - ipa .getId():  " + ipa.ge tId());
  299  
  300                             List<I nPersonAut henticatio nDTO> ipas  = new Arr ayList<InP ersonAuthe nticationD TO>();
  301                             ipas.a dd(convert er.convert DomainInpe rsonAuthen tication(i pa));
  302                             respon se.setPojo Object(ipa s);
  303                             respon se.setFail ure(false) ;
  304                             respon se.setSucc ess(true);
  305                             respon se.setFail ureMessage ("");
  306                             respon se.setSucc essMessage ("The sele cted prere quisite in formation  has been s uccessfull y saved.") ;
  307  
  308                             if (nu ll == resp onse.getVa lidationEr rors()) {
  309                                      LinkedHa shMap<Stri ng, String > validati onErrors =  new Linke dHashMap<S tring, Str ing>();
  310                                      validati onErrors.p ut("deferA uthenticat ion", "The re are no  Validation  Errors.") ;
  311                                      response .setValida tionErrors (validatio nErrors);
  312                             } else  {
  313                                      response .getValida tionErrors ().put("de ferAuthent ication",  "There are  no Valida tion Error s.");
  314                             }
  315  
  316                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - set  ResponseU til - 6.") ;
  317  
  318                             if (nu ll == resp onse.getIn foMessages ()) {
  319                                      LinkedHa shMap<Stri ng, String > infoMess ages = new  LinkedHas hMap<Strin g, String> ();
  320                                      infoMess ages.put(" deferAuthe ntication" ,"The sele cted prere quisite in formation  has been s uccessfull y saved.") ;
  321                                      response .setInfoMe ssages(inf oMessages) ;
  322                             } else  {
  323                                      response .getInfoMe ssages().p ut("deferA uthenticat ion", "The  selected  prerequisi te informa tion has b een succes sfully sav ed.");
  324                             }
  325  
  326                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - defer Authentica tion - ret urning Res ponseUtil< List<InPer sonAuthent icationDTO >> object. ");
  327                             return  response;
  328  
  329                    } ca tch (Excep tion e) {
  330                             log.er ror(">>>>  Error in I nPersonAut henticatio nServiceIm pl - defer Authentica tion - Err or during  Defer Auth entication ." + e);
  331                             System .out.print ln(">>>> E rror in In PersonAuth entication ServiceImp l - deferA uthenticat ion - Erro r during D efer Authe ntication. ");
  332                             throw  new MHVRun timeExcept ion(">>>>  Error in I nPersonAut henticatio nServiceIm pl - defer Authentica tion - Err or during  Defer Auth entication .");
  333                    }
  334           }
  335           
  336           @O verride
  337           @P OST
  338           @P ath("/matc h/{adminUs erName}")
  339           @C onsumes(Me diaType.AP PLICATION_ JSON)
  340           @P roduces(Me diaType.AP PLICATION_ JSON)
  341           @T ransaction al
  342           pu blic Respo nseUtil<Li st<InPerso nAuthentic ationDTO>>  match(InP ersonAuthe nticationD TO ipaDTO,  @PathPara m("adminUs erName") S tring admi nUserName)  throws MH VException  {
  343                    Resp onseUtil<L ist<InPers onAuthenti cationDTO> > response  = new Res ponseUtil< List<InPer sonAuthent icationDTO >>();
  344                    Resp onseUtil<P atientDTO>  responseR t = new Re sponseUtil <PatientDT O>();            
  345                    try  {
  346                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - match  - ipaDTO. getId(): "  + ipaDTO. getId());
  347                             InPers onAuthenti cation ipa  = convert er.convert InpersonAu thenticati onDTO(ipaD TO);
  348                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - match  - 0a");                        
  349                             conver ter.addPat ientProfil e(ipaDTO,  ipa);
  350                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - match  - 0b");                        
  351                             //conv erter.addF acilityInf o(ipaDTO,  ipa);
  352                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - match  - 0c");
  353                             
  354                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - match  - ipaDTO. getPatient ().getId() : " + ipaD TO.getPati ent().getI d());
  355                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - match  - Calling  MVI Servi ce for Mat ch.");
  356                             
  357                             // TOD O should c hange the  return to  responseUt il<Patient DTO>
  358                             respon seRt = mvi Service.ma tchPersonI nIPAWithVe rsion(user ProfileCon verter.con vertDomain UserProfil e(ipa.getP atient().g etUserProf ile()), ad minUserNam e);
  359  
  360                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - match  - after t he call -  1");      
  361                             
  362                             Patien tDTO patie ntDTO = (P atientDTO)  response. getPojoObj ect();
  363                             Patien t patient  = patientC onverter.c onvertDTOP rofile(pat ientDTO);
  364                             
  365                             /*
  366                             if(pat ient != nu ll) {
  367                                      //curren tIPA.setPa tient(pati ent);
  368                                      setSelec tedUserPro fileAccoun tStatus(ge tAccountSt atus(patie nt));
  369                             }
  370                             
  371                             
  372                             // upd ateSearchR esults();
  373                             // det ermineMatc hStatus();
  374                             // det ermineDisp layButtons ();
  375                                                       
  376                             */
  377                                                       
  378                             List<I nPersonAut henticatio nDTO> ipas  = new Arr ayList<InP ersonAuthe nticationD TO>();
  379                             ipas.a dd(convert er.convert DomainInpe rsonAuthen tication(i pa));
  380                             respon se.setPojo Object(ipa s);
  381  
  382                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - match  - after t he call -  2");                        
  383                             
  384                             if (re sponseRt.i sFailure() ) {
  385                                      response .setFailur e(true);
  386                                      response .setSucces s(false);
  387                                      response .setFailur eMessage(r esponseRt. getFailure Message()) ;     
  388                                      
  389                                      Activity ActorTypeE numeration  authentic ator = Act ivityActor TypeEnumer ation.MHV_ AUTHENTICA TOR;
  390                                      if (admi nUserName  != null &&  adminUser Name.equal s("SYSTEM" )) {
  391                                               authentica tor = Acti vityActorT ypeEnumera tion.SYSTE M;
  392                                      }
  393                                      activity Service.au ditMviEven t(userProf ileConvert er.convert DomainUser Profile(ip a.getPatie nt().getUs erProfile( )), authen ticator,
  394                                                       fa lse, Activ ityActionT ypeEnumera tion.UPGRA DE_TO_ADVA NCED, Acti vityTypeEn umeration. ACCOUNT_UP GRADE, res ponse);
  395                                      
  396                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - match -  after the  call - 3" );                                 
  397                             }
  398                             else {
  399                                      response .setSucces s(true);
  400                                      response .setFailur e(false);
  401                                      response .setFailur eMessage(" ");
  402                                      response .setSucces sMessage(" The Match  process fo r MHV User  "+ ipa.ge tPatient() .getUserPr ofile().ge tFirstName ()+" "+ ip a.getPatie nt().getUs erProfile( ).getLastN ame()+" ha s been suc cessfully  completed. ");
  403  
  404                                      Activity ActorTypeE numeration  authentic ator = Act ivityActor TypeEnumer ation.MHV_ AUTHENTICA TOR;
  405                                      if (admi nUserName  != null &&  adminUser Name.equal s("SYSTEM" )) {
  406                                               authentica tor = Acti vityActorT ypeEnumera tion.SYSTE M;
  407                                      }
  408                                      activity Service.au ditMviEven t(userProf ileConvert er.convert DomainUser Profile(ip a.getPatie nt().getUs erProfile( )), authen ticator,
  409                                                       tr ue, Activi tyActionTy peEnumerat ion.UPGRAD E_TO_ADVAN CED, Activ ityTypeEnu meration.A CCOUNT_UPG RADE, resp onse);
  410                                      
  411                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - match -  after the  call - 3a ");                                
  412                             }
  413                             
  414                             if (nu ll == resp onseRt.get Validation Errors())  {
  415                                      LinkedHa shMap<Stri ng, String > validati onErrors =  new Linke dHashMap<S tring, Str ing>();
  416                                      validati onErrors.p ut("match" , "There a re no Vali dation Err ors.");
  417                                      response .setValida tionErrors (validatio nErrors);
  418                             } else  {
  419                                      response .setValida tionErrors (responseR t.getValid ationError s());
  420                             }
  421                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - match  - after t he call -  4");
  422                             if (nu ll == resp onseRt.get InfoMessag es()) {
  423                                      LinkedHa shMap<Stri ng, String > infoMess ages = new  LinkedHas hMap<Strin g, String> ();
  424                                      infoMess ages.put(" match","Th e Match pr ocess for  MHV User " + ipa.getP atient().g etUserProf ile().getF irstName() +" "+ ipa. getPatient ().getUser Profile(). getLastNam e()+" has  been succe ssfully co mpleted.") ;
  425                                      response .setInfoMe ssages(inf oMessages) ;
  426                             } else  {
  427                                      response .setInfoMe ssages(res ponseRt.ge tInfoMessa ges());
  428                             }
  429                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - match  - after t he call -  5");
  430  
  431                             return  response;
  432                    } ca tch (Excep tion e) {
  433                             log.er ror(">>>>  Error in I nPersonAut henticatio nServiceIm pl - match  - Error d uring Matc h Process. " + e);
  434                             System .out.print ln(">>>> E rror in In PersonAuth entication ServiceImp l - match  - Error du ring Match  Process." );
  435                             throw  new MHVRun timeExcept ion(">>>>  Error in I nPersonAut henticatio nServiceIm pl - match  - Error d uring Matc h Process. ");
  436                    }
  437           }        
  438           
  439  
  440           @O verride
  441           @P OST
  442           @P ath("/sync Correlate/ {adminUser Name}")
  443           @C onsumes(Me diaType.AP PLICATION_ JSON)
  444           @P roduces(Me diaType.AP PLICATION_ JSON)
  445           @T ransaction al
  446           pu blic Respo nseUtil<Li st<InPerso nAuthentic ationDTO>>  syncCorre late(InPer sonAuthent icationDTO  ipaDTO, @ PathParam( "adminUser Name") Str ing adminU serName) t hrows MHVE xception {
  447                    Resp onseUtil<L ist<InPers onAuthenti cationDTO> > response  = new Res ponseUtil< List<InPer sonAuthent icationDTO >>();
  448                    Resp onseUtil<P atientDTO>  responseR t = new Re sponseUtil <PatientDT O>();            
  449                    try  {
  450                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - syncC orrelate -  ipaDTO.ge tId(): " +  ipaDTO.ge tId());
  451                             InPers onAuthenti cation ipa  = convert er.convert InpersonAu thenticati onDTO(ipaD TO);
  452                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - syncC orrelate -  0a");                        
  453                             conver ter.addPat ientProfil e(ipaDTO,  ipa);
  454                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - syncC orrelate -  0b");                        
  455                             //conv erter.addF acilityInf o(ipaDTO,  ipa);
  456                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - syncC orrelate -  0c");
  457                             
  458                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - syncC orrelate -  ipaDTO.ge tPatient() .getId():  " + ipaDTO .getPatien t().getId( ));
  459                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - syncC orrelate -  Calling M VI Service  for syncC orrelate." );
  460                             
  461                             Patien tDTO patie ntDTO = pa tientConve rter.conve rtDomainPa tient(ipa. getPatient ());
  462                             
  463                             // TOD O should c hange the  return to  responseUt il<Patient DTO>
  464                             respon seRt = mvi Service.ad dPersonFor Correlatio nForIPAWit hVersion(p atientDTO,  userProfi leConverte r.convertD omainUserP rofile(ipa .getPatien t().getUse rProfile() ), adminUs erName);
  465  
  466                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - syncC orrelate -  after the  call - 1" );      
  467                             
  468                             Patien t patient  = patientC onverter.c onvertDTOP rofile(pat ientDTO);
  469                                                       
  470                             List<I nPersonAut henticatio nDTO> ipas  = new Arr ayList<InP ersonAuthe nticationD TO>();
  471                             ipas.a dd(convert er.convert DomainInpe rsonAuthen tication(i pa));
  472                             respon se.setPojo Object(ipa s);
  473  
  474                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - syncC orrelate -  after the  call - 2" );                        
  475                             
  476                             if (re sponseRt.i sFailure() ) {
  477                                      response .setFailur e(true);
  478                                      response .setSucces s(false);
  479                                      response .setFailur eMessage(r esponseRt. getFailure Message()) ;     
  480                                      
  481                                      Activity ActorTypeE numeration  authentic ator = Act ivityActor TypeEnumer ation.MHV_ AUTHENTICA TOR;
  482                                      if (admi nUserName  != null &&  adminUser Name.equal s("SYSTEM" )) {
  483                                               authentica tor = Acti vityActorT ypeEnumera tion.SYSTE M;
  484                                      }
  485                                      activity Service.au ditMviEven t(userProf ileConvert er.convert DomainUser Profile(ip a.getPatie nt().getUs erProfile( )), authen ticator,
  486                                                       fa lse, Activ ityActionT ypeEnumera tion.UPGRA DE_TO_ADVA NCED, Acti vityTypeEn umeration. ACCOUNT_UP GRADE, res ponse);
  487                                      
  488                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - syncCor relate - a fter the c all - 3");                                 
  489                             }
  490                             else {
  491                                      response .setSucces s(true);
  492                                      response .setFailur e(false);
  493                                      response .setFailur eMessage(" ");
  494                                      response .setSucces sMessage(" Correlatio n was succ essful for  MHV User  "+ ipa.get Patient(). getUserPro file().get FirstName( )+" "+ ipa .getPatien t().getUse rProfile() .getLastNa me());
  495  
  496                                      Activity ActorTypeE numeration  authentic ator = Act ivityActor TypeEnumer ation.MHV_ AUTHENTICA TOR;
  497                                      if (admi nUserName  != null &&  adminUser Name.equal s("SYSTEM" )) {
  498                                               authentica tor = Acti vityActorT ypeEnumera tion.SYSTE M;
  499                                      }
  500                                      activity Service.au ditMviEven t(userProf ileConvert er.convert DomainUser Profile(ip a.getPatie nt().getUs erProfile( )), authen ticator,
  501                                                       tr ue, Activi tyActionTy peEnumerat ion.UPGRAD E_TO_ADVAN CED, Activ ityTypeEnu meration.A CCOUNT_UPG RADE, resp onse);
  502                                      
  503                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - syncCor relate - a fter the c all - 3a") ;                               
  504                             }
  505                             
  506                             if (nu ll == resp onseRt.get Validation Errors())  {
  507                                      LinkedHa shMap<Stri ng, String > validati onErrors =  new Linke dHashMap<S tring, Str ing>();
  508                                      validati onErrors.p ut("syncCo rrelate",  "There are  no Valida tion Error s.");
  509                                      response .setValida tionErrors (validatio nErrors);
  510                             } else  {
  511                                      response .setValida tionErrors (responseR t.getValid ationError s());
  512                             }
  513                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - syncC orrelate -  after the  call - 4" );
  514                             if (re sponseRt.g etInfoMess ages().siz e() == 0)  {
  515                                      LinkedHa shMap<Stri ng, String > infoMess ages = new  LinkedHas hMap<Strin g, String> ();
  516                                      infoMess ages.put(m essagesUti l.getMviIp aCorrelati onSuccess( ), String. format(mes sagesUtil. getMviIpaC orrelation Success(),  ipa.getPa tient().ge tUserProfi le().getFi rstName()+ " "+ ipa.g etPatient( ).getUserP rofile().g etLastName ()));                                                      
  517                                      response .setInfoMe ssages(inf oMessages) ;
  518                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - syncCor relate - a fter the c all - 4a") ;
  519                             } else  {
  520                                      response .setInfoMe ssages(res ponseRt.ge tInfoMessa ges());
  521                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - syncCor relate - a fter the c all - 4b -  Count:"+  responseRt .getInfoMe ssages().s ize());
  522                             }
  523                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - syncC orrelate -  after the  call - 5" );
  524  
  525                             return  response;
  526                    } ca tch (Excep tion e) {
  527                             log.er ror(">>>>  Error in I nPersonAut henticatio nServiceIm pl - syncC orrelate -  Error dur ing Correl attion Pro cess." + e );
  528                             System .out.print ln(">>>> E rror in In PersonAuth entication ServiceImp l - syncCo rrelate -  Error duri ng Correla ttion Proc ess.");
  529                             throw  new MHVRun timeExcept ion(">>>>  Error in I nPersonAut henticatio nServiceIm pl - syncC orrelate -  Error dur ing Correl attion Pro cess.");
  530                    }
  531           }        
  532           
  533           
  534           @O verride
  535           @P OST
  536           @P ath("/term inateAuthe ntication" )
  537           @C onsumes(Me diaType.AP PLICATION_ JSON)
  538           @P roduces(Me diaType.AP PLICATION_ JSON)
  539           @T ransaction al
  540           pu blic Respo nseUtil<Li st<InPerso nAuthentic ationDTO>>  terminate Authentica tion(InPer sonAuthent icationDTO  ipaDTO)
  541                             throws  MHVExcept ion {
  542                    Resp onseUtil<L ist<InPers onAuthenti cationDTO> > response  = new Res ponseUtil< List<InPer sonAuthent icationDTO >>();
  543                    try  {
  544                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - termi nateAuthen tication -  ipaDTO.ge tId(): " +  ipaDTO.ge tId());
  545                             InPers onAuthenti cation ipa  = convert er.convert InpersonAu thenticati onDTO(ipaD TO);
  546                             conver ter.addPat ientProfil e(ipaDTO,  ipa);
  547                             conver ter.addFac ilityInfo( ipaDTO, ip a);
  548                             
  549                             Authen ticationSt atusEnumer ation stat us = null;                    
  550                             status  = Authent icationSta tusEnumera tion.UNAUT HENTICATED ;
  551                             ipa.se tStatus(st atus.getDe scription( ));
  552                             
  553                    ipa. setPartici pationForm Signed(Boo lean.FALSE );
  554                    ipa. setIdentif icationPre sented(Boo lean.FALSE );
  555                    ipa. setApprove dForRecord sAccess(Bo olean.FALS E);
  556                    ipa. setDeferme ntReason(n ull);
  557                    ipa. setAuthent icatingFac ility(null );
  558                    ipa. setRemoval Reason(nul l);
  559                    ipa. setAuthent icationDat e(null);
  560                    ipa. setAuthent icatedBy(n ull);
  561                    ipa. setMviAuth entication Status(nul l);            
  562                             
  563                             ipa =  inpersonAu thenticati onReposito ry.save(ip a);
  564  
  565                             List<I nPersonAut henticatio nDTO> ipas  = new Arr ayList<InP ersonAuthe nticationD TO>();
  566                             ipas.a dd(convert er.convert DomainInpe rsonAuthen tication(i pa));
  567                             respon se.setPojo Object(ipa s);
  568                             respon se.setFail ure(false) ;
  569                             respon se.setSucc ess(true);
  570                             respon se.setFail ureMessage ("");
  571                             respon se.setSucc essMessage ("The Auth entication  process f or MHV Use r "+ ipa.g etPatient( ).getUserP rofile().g etFirstNam e()+" "+ i pa.getPati ent().getU serProfile ().getMidd leName()+"  "+ipa.get Patient(). getUserPro file().get LastName() +" has bee n successf ully termi nated.");
  572  
  573                             if (nu ll == resp onse.getVa lidationEr rors()) {
  574                                      LinkedHa shMap<Stri ng, String > validati onErrors =  new Linke dHashMap<S tring, Str ing>();
  575                                      validati onErrors.p ut("termin ateAuthent ication",  "There are  no Valida tion Error s.");
  576                                      response .setValida tionErrors (validatio nErrors);
  577                             } else  {
  578                                      response .getValida tionErrors ().put("te rminateAut henticatio n", "There  are no Va lidation E rrors.");
  579                             }
  580  
  581                             if (nu ll == resp onse.getIn foMessages ()) {
  582                                      LinkedHa shMap<Stri ng, String > infoMess ages = new  LinkedHas hMap<Strin g, String> ();
  583                                      infoMess ages.put(" terminateA uthenticat ion","The  Authentica tion proce ss for MHV  User "+ i pa.getPati ent().getU serProfile ().getFirs tName()+"  "+ ipa.get Patient(). getUserPro file().get MiddleName ()+" "+ ip a.getPatie nt().getUs erProfile( ).getLastN ame()+" ha s been suc cessfully  terminated .");
  584                                      response .setInfoMe ssages(inf oMessages) ;
  585                             } else  {
  586                                      response .getInfoMe ssages().p ut("termin ateAuthent ication",  "The Authe ntication  process fo r MHV User  "+ ipa.ge tPatient() .getUserPr ofile().ge tFirstName ()+" "+ ip a.getPatie nt().getUs erProfile( ).getMiddl eName()+"  "+ ipa.get Patient(). getUserPro file().get LastName() +" has bee n successf ully termi nated.");
  587                             }
  588  
  589                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - termi nateAuthen tication -  returning  ResponseU til<List<I nPersonAut henticatio nDTO>> obj ect.");
  590                             return  response;
  591  
  592                    } ca tch (Excep tion e) {
  593                             log.er ror(">>>>  Error in I nPersonAut henticatio nServiceIm pl - termi nateAuthen tication -  Error dur ing Termin ate Authen tication."  + e);
  594                             System .out.print ln(">>>> E rror in In PersonAuth entication ServiceImp l - termin ateAuthent ication -  Error duri ng Termina te Authent ication.") ;
  595                             throw  new MHVRun timeExcept ion(">>>>  Error in I nPersonAut henticatio nServiceIm pl - termi nateAuthen tication -  Error dur ing Termin ate Authen tication." );
  596                    }
  597           }        
  598  
  599           @O verride
  600           @P OST
  601           @P ath("/auth enticateWi thAdminUse rName/{ipa Id}/{admin UserName}/ {authentic atingFacil ityId}")
  602           @C onsumes(Me diaType.AP PLICATION_ JSON)
  603           @P roduces(Me diaType.AP PLICATION_ JSON)
  604           @T ransaction al
  605           pu blic Respo nseUtil<Li st<InPerso nAuthentic ationDTO>>  authentic ateWithAdm inUserName (@PathPara m("ipaId")  Long ipaI d,
  606                             @PathP aram("admi nUserName" ) String a dminUserNa me, @PathP aram("dela yReason")  Long authe nticatingF acilityId)  throws MH VException  {
  607                    try  {
  608                             System .out.print ln(
  609                                               ">>>> InPe rsonAuthen ticationSe rviceImpl  - authenti cateWithAd minUserNam e - ipaId:  " + ipaId );
  610                             InPers onAuthenti cation ipa  = inperso nAuthentic ationRepos itory.find One(ipaId) ;
  611                             return  mviAuthen ticate(ipa , adminUse rName, aut henticatin gFacilityI d);
  612                    } ca tch (Excep tion e) {
  613                             log.er ror(">>>>  Error in I nPersonAut henticatio nServiceIm pl - authe nticateWit hAdminUser Name - Err or during  Authentica tion." + e );
  614                             System .out.print ln(">>>> E rror in In PersonAuth entication ServiceImp l - authen ticateWith AdminUserN ame - Erro r during A uthenticat ion.");
  615                             throw  new MHVRun timeExcept ion(">>>>  Error in I nPersonAut henticatio nServiceIm pl - authe nticateWit hAdminUser Name - Err or during  Authentica tion.");
  616                    }
  617           }
  618  
  619           pr ivate Resp onseUtil<L ist<InPers onAuthenti cationDTO> > mviAuthe nticate(In PersonAuth entication  ipa, Stri ng adminUs erName, Lo ng authent icatingFac ilityId) {
  620                    Resp onseUtil<L ist<InPers onAuthenti cationDTO> > response  = new Res ponseUtil< List<InPer sonAuthent icationDTO >>();
  621                    Resp onseUtil<P atientDTO>  responseR t = new Re sponseUtil <PatientDT O>();            
  622                    try  {
  623                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - mviAu thenticate  - ipaId:  " + ipa.ge tId());
  624                             Authen ticationSt atusEnumer ation stat us = Authe nticationS tatusEnume ration.AUT HENTICATED ;
  625                             ipa.se tParticipa tionFormSi gned(Boole an.TRUE);
  626                             ipa.se tIdentific ationPrese nted(Boole an.TRUE);
  627                             ipa.se tApprovedF orRecordsA ccess(Bool ean.TRUE);
  628                             ipa.se tDeferment Reason(nul l);
  629                             ipa.se tAuthentic atingFacil ityId(auth enticating FacilityId );
  630                             ipa.se tAuthentic atedBy(get EmployeeNa me(adminUs erName));   // e.g. H all, Lisa  (vhaiswhal ll)
  631                             ipa.se tAuthentic ationDate( new Timest amp(new Da te().getTi me()));
  632                             ipa.se tStatus(st atus.getDe scription( ));
  633  
  634                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - mviAu thenticate  - Inside  else block .. Calling  mviServic e.mviAuthe nticateWit hVersion") ;                       
  635                             respon seRt = mvi Service.mv iAuthentic ateWithVer sion(patie ntConverte r.convertD omainPatie nt(ipa.get Patient()) ,
  636                                                       us erProfileC onverter.c onvertDoma inUserProf ile(ipa.ge tPatient() .getUserPr ofile()),  true, fals e, adminUs erName);
  637  
  638                             // Boo lean mviSe rviceRespo nse = resp onse.getFa ilure();
  639                             if (!r esponseRt. isFailure( )) {
  640                                      if (log. isDebugEna bled()) {
  641                                               log.debug( ">>>> InPe rsonAuthen ticationSe rviceImpl  - mviAuthe nticate -  SUCCESS un authentica ting patie nt with IC N:"+ ipa.g etPatient( ).getIcn() );
  642                                      }
  643                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - mviAuth enticate -  SUCCESS u nauthentic ating pati ent with I CN:"+ ipa. getPatient ().getIcn( ));
  644                                      ipa.setM viAuthenti cationStat us("OK");
  645                                      response .setSucces s(true);
  646                                      response .setFailur e(false);
  647                                      response .setSucces sMessage(r esponseRt. getSuccess Message()) ;
  648                                      Activity ActorTypeE numeration  authentic ator = Act ivityActor TypeEnumer ation.MHV_ AUTHENTICA TOR;
  649                                      if (admi nUserName  != null &&  adminUser Name.equal s("SYSTEM" )) {
  650                                               authentica tor = Acti vityActorT ypeEnumera tion.SYSTE M;
  651                                      }
  652                                      activity Service.au ditMviEven t(userProf ileConvert er.convert DomainUser Profile(ip a.getPatie nt().getUs erProfile( )), authen ticator,
  653                                                       tr ue, Activi tyActionTy peEnumerat ion.UPGRAD E_TO_PREMI UM, Activi tyTypeEnum eration.AC COUNT_UPGR ADE, respo nse);                                         
  654                                                                         
  655                             } else  {
  656                                      if (log. isDebugEna bled()) {
  657                                               log.debug( ">>>> InPe rsonAuthen ticationSe rviceImpl  - mviAuthe nticate -  ERROR unau thenticati ng patient  with ICN: "+ ipa.get Patient(). getIcn());
  658                                      }
  659                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - mviAuth enticate -  ERROR una uthenticat ing patien t with ICN :"+ ipa.ge tPatient() .getIcn()) ;
  660                                      response .setFailur e(true);
  661                                      response .setSucces s(false);
  662                                      response .setFailur eMessage(r esponseRt. getFailure Message()) ;
  663  
  664                                      Activity ActorTypeE numeration  authentic ator = Act ivityActor TypeEnumer ation.MHV_ AUTHENTICA TOR;
  665                                      if (admi nUserName  != null &&  adminUser Name.equal s("SYSTEM" )) {
  666                                               authentica tor = Acti vityActorT ypeEnumera tion.SYSTE M;
  667                                      }
  668                                      activity Service.au ditMviEven t(userProf ileConvert er.convert DomainUser Profile(ip a.getPatie nt().getUs erProfile( )), authen ticator,
  669                                                       fa lse, Activ ityActionT ypeEnumera tion.UPGRA DE_TO_PREM IUM, Activ ityTypeEnu meration.A CCOUNT_UPG RADE, resp onse);                                        
  670                                      
  671                             }
  672                             ipa =  inpersonAu thenticati onReposito ry.save(ip a);
  673                             List<I nPersonAut henticatio nDTO> ipas  = new Arr ayList<InP ersonAuthe nticationD TO>();
  674                             ipas.a dd(convert er.convert DomainInpe rsonAuthen tication(i pa));
  675                             respon se.setPojo Object(ipa s);
  676  
  677                             if (nu ll == resp onseRt.get Validation Errors())  {
  678                                      LinkedHa shMap<Stri ng, String > validati onErrors =  new Linke dHashMap<S tring, Str ing>();
  679                                      validati onErrors.p ut("mviAut henticate" , "There a re no Vali dation Err ors.");
  680                                      response .setValida tionErrors (validatio nErrors);
  681                             } else  {
  682                                      response .setValida tionErrors (responseR t.getValid ationError s());
  683                             }
  684  
  685                             if (nu ll == resp onseRt.get InfoMessag es()) {
  686                                      LinkedHa shMap<Stri ng, String > infoMess ages = new  LinkedHas hMap<Strin g, String> ();
  687                                      //infoMe ssages.put ("mviAuthe nticate",  "Authentic ation was  successful  for MHV U ser "+ ipa .getPatien t().getUse rProfile() .getFirstN ame()+" "+  ipa.getPa tient().ge tUserProfi le().getLa stName()+" .");
  688                                      response .setInfoMe ssages(inf oMessages) ;
  689                             } else  {
  690                                      response .setInfoMe ssages(res ponseRt.ge tInfoMessa ges());
  691                             }
  692  
  693                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - mviAu thenticate  - returni ng Respons eUtil<List <InPersonA uthenticat ionDTO>> o bject.");
  694                             return  response;
  695                    } ca tch (Excep tion e) {
  696                             log.er ror(">>>>  Error in I nPersonAut henticatio nServiceIm pl - mviAu thenticate  - Error d uring Auth entication . "+ e);
  697                             System .out.print ln(">>>> E rror in In PersonAuth entication ServiceImp l - mviAut henticate  - Error du ring Authe ntication. ");
  698                             throw  new MHVRun timeExcept ion(">>>>  Error in I nPersonAut henticatio nServiceIm pl - mviAu thenticate  - Error d uring Auth entication .");
  699                    }
  700           }
  701  
  702           @O verride
  703           @P OST
  704           @P ath("/unau thenticate WithAdminU serName/{i paId}/{adm inUserName }/{removeA uthenticat ingReason} ")
  705           @C onsumes(Me diaType.AP PLICATION_ JSON)
  706           @P roduces(Me diaType.AP PLICATION_ JSON)
  707           @T ransaction al
  708           pu blic Respo nseUtil<Li st<InPerso nAuthentic ationDTO>>  unauthent icateWithA dminUserNa me(@PathPa ram("ipaId ") Long ip aId,
  709                             @PathP aram("admi nUserName" ) String a dminUserNa me, @PathP aram("remo veAuthenti catingReas on") Strin g removeAu thenticati ngReason)  throws MHV Exception  {
  710                    try  {
  711                             System .out.print ln(
  712                                               ">>>> InPe rsonAuthen ticationSe rviceImpl  - unauthen ticateWith AdminUserN ame - ipaI d:" + ipaI d + " - re moveAuthen ticatingRe ason:"+rem oveAuthent icatingRea son);
  713                             InPers onAuthenti cation ipa  = inperso nAuthentic ationRepos itory.find One(ipaId) ;
  714                             return  mviUnauth enticate(i pa, adminU serName, r emoveAuthe nticatingR eason);
  715                    } ca tch (Excep tion e) {
  716                             log.er ror(">>>>  Error in I nPersonAut henticatio nServiceIm pl - unaut henticateW ithAdminUs erName - E rror durin g Remove A uthenticat ion." + e) ;
  717                             System .out.print ln(">>>> E rror in In PersonAuth entication ServiceImp l - unauth enticateWi thAdminUse rName - Er ror during  Remove Au thenticati on.");
  718                             throw  new MHVRun timeExcept ion(">>>>  Error in I nPersonAut henticatio nServiceIm pl - unaut henticateW ithAdminUs erName - E rror durin g Remove A uthenticat ion.");
  719                    }
  720           }
  721  
  722           pr ivate Resp onseUtil<L ist<InPers onAuthenti cationDTO> > mviUnaut henticate( InPersonAu thenticati on ipa, St ring admin UserName,  String rem oveAuthent icatingRea son) {
  723                    Resp onseUtil<L ist<InPers onAuthenti cationDTO> > response  = new Res ponseUtil< List<InPer sonAuthent icationDTO >>();
  724                    Resp onseUtil<P atientDTO>  responseR t = new Re sponseUtil <PatientDT O>();
  725                    try  {
  726                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - mviUn authentica te - ipaId :" + ipa.g etId());
  727                             Authen ticationSt atusEnumer ation stat us = Authe nticationS tatusEnume ration.UNA UTHENTICAT ED;
  728                             ipa.se tParticipa tionFormSi gned(Boole an.FALSE);
  729                             ipa.se tIdentific ationPrese nted(Boole an.FALSE);
  730                             ipa.se tApprovedF orRecordsA ccess(Bool ean.FALSE) ;
  731                             ipa.se tRemovalRe ason(remov eAuthentic atingReaso n);
  732                             ipa.se tDeferment Reason(nul l);
  733                             ipa.se tAuthentic atingFacil ity(null);
  734                             ipa.se tAuthentic ationDate( null);
  735                             ipa.se tStatus(st atus.getDe scription( ));
  736                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - mviUn authentica te - statu s:" + stat us.getDesc ription()) ;
  737                             // JAZ Z: Task#19 823 - When  a IPA use r unauthen ticates a  user that  is not mat ched and/o r
  738                             // Cor related, t hen the sy stem will  not send t he unauth  flags to M VI since t he user is  not corre lated
  739                             Patien t patient  = ipa.getP atient();
  740                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - mviUn authentica te - patie nt:" + pat ient.getId ());
  741                             if (pa tient.getC orrelation Status() = = PatientC orrelation StatusEnum eration.UN CORRELATED .getValue( )
  742                                               || patient .getCorrel ationStatu s() == Pat ientCorrel ationStatu sEnumerati on.MVIDATA MATCH.getV alue()) {
  743                                      ipa.setM viAuthenti cationStat us("OK");
  744                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - mviUnau thenticate  - Inside  if block") ;
  745                                      patient. setPatient Synchroniz ations(nul l);
  746                                      patientR epository. save(patie nt);
  747                             } else  {
  748                                      // MHV_C odeCR1514  - US12.4 M VI Complia nce Implem entation -  If the MV I flag is  turned on  call, MVI  call inste ad of MPI  call
  749                                      ipa.setM viAuthenti cationStat us("PENDIN G_UNAUTH") ;
  750                                      // Jazz  Id: 230989  - adding  HL7v3 Vers ion code i n MVI Requ est Header .
  751                                      // For n ow skipped  calling t he patient  service.  Calling di rectly Mvi Integratio nService
  752                                      // patie ntServiceR esponse =  ServiceFac tory.creat ePatientSe rvice().mv iUnauthent icateWithA dminUserNa me(ipa.get Patient(),  adminUser Name);
  753                                      System.o ut.println (">>>> InP ersonAuthe nticationS erviceImpl  - mviUnau thenticate  - Inside  else block .. Calling  mviServic e.mviAuthe nticateWit hVersion") ;
  754                                      response Rt = mviSe rvice.mviA uthenticat eWithVersi on(patient Converter. convertDom ainPatient (ipa.getPa tient()),
  755                                                       us erProfileC onverter.c onvertDoma inUserProf ile(ipa.ge tPatient() .getUserPr ofile()),  false, fal se, adminU serName);
  756  
  757                                      // Boole an mviServ iceRespons e = respon se.getFail ure();
  758                                      if (!res ponseRt.is Failure())  {
  759                                               if (log.is DebugEnabl ed()) {
  760                                                       lo g.debug("> >>> InPers onAuthenti cationServ iceImpl -  mviUnauthe nticate -  SUCCESS un authentica ting patie nt with IC N:"+ ipa.g etPatient( ).getIcn() );
  761                                               }
  762                                               System.out .println(" >>>> InPer sonAuthent icationSer viceImpl -  mviUnauth enticate -  SUCCESS u nauthentic ating pati ent with I CN:"+ ipa. getPatient ().getIcn( ));
  763                                               // JAZZ: T ask#19820  - Remove u n-correlat ion call w hen user†™s account  is unauth enticated
  764                                               ipa.setMvi Authentica tionStatus ("OK");
  765                                               // MHV_Cod eCR1918 -  US12.4.x M VI Complia nce Implem entation -  If the pa tient stat us is corr eleated or  pending c orr/uncorr  try to un correlate.  Only
  766                                               response.s etSuccess( true);
  767                                               response.s etFailure( false);
  768                                               response.s etSuccessM essage(res ponseRt.ge tSuccessMe ssage());
  769  
  770                                               ActivityAc torTypeEnu meration a uthenticat or = Activ ityActorTy peEnumerat ion.MHV_AU THENTICATO R;
  771                                               if (adminU serName !=  null && a dminUserNa me.equals( "SYSTEM"))  {
  772                                                       au thenticato r = Activi tyActorTyp eEnumerati on.SYSTEM;
  773                                               }
  774                                               activitySe rvice.audi tMviEvent( userProfil eConverter .convertDo mainUserPr ofile(ipa. getPatient ().getUser Profile()) , authenti cator,
  775                                                                true , Activity ActionType Enumeratio n.PREMIUM_ ACCOUNT_RE VOKED, Act ivityTypeE numeration .ACCOUNT_U PGRADE, re sponse);                                            
  776                                              
  777                                      } else {
  778                                               if (log.is DebugEnabl ed()) {
  779                                                       lo g.debug("> >>> InPers onAuthenti cationServ iceImpl -  mviUnauthe nticate -  ERROR unau thenticati ng patient  with ICN: "+ ipa.get Patient(). getIcn());
  780                                               }
  781                                               System.out .println(" >>>> InPer sonAuthent icationSer viceImpl -  mviUnauth enticate -  ERROR una uthenticat ing patien t with ICN :"+ ipa.ge tPatient() .getIcn()) ;
  782                                               response.s etFailure( true);
  783                                               response.s etSuccess( false);
  784                                               response.s etFailureM essage(res ponseRt.ge tFailureMe ssage());
  785  
  786                                               ActivityAc torTypeEnu meration a uthenticat or = Activ ityActorTy peEnumerat ion.MHV_AU THENTICATO R;
  787                                               if (adminU serName !=  null && a dminUserNa me.equals( "SYSTEM"))  {
  788                                                       au thenticato r = Activi tyActorTyp eEnumerati on.SYSTEM;
  789                                               }
  790                                               activitySe rvice.audi tMviEvent( userProfil eConverter .convertDo mainUserPr ofile(ipa. getPatient ().getUser Profile()) , authenti cator,
  791                                                                fals e, Activit yActionTyp eEnumerati on.PREMIUM _ACCOUNT_R EVOKED, Ac tivityType Enumeratio n.ACCOUNT_ UPGRADE, r esponse);                                           
  792                                      }
  793                             }
  794                             
  795                             ipa =  inpersonAu thenticati onReposito ry.save(ip a);
  796                             List<I nPersonAut henticatio nDTO> ipas  = new Arr ayList<InP ersonAuthe nticationD TO>();
  797                             ipas.a dd(convert er.convert DomainInpe rsonAuthen tication(i pa));
  798                             respon se.setPojo Object(ipa s);
  799                             
  800                             if (nu ll == resp onseRt.get Validation Errors())  {
  801                                      LinkedHa shMap<Stri ng, String > validati onErrors =  new Linke dHashMap<S tring, Str ing>();
  802                                      validati onErrors.p ut("mviUna uthenticat e", "There  are no Va lidation E rrors.");
  803                                      response .setValida tionErrors (validatio nErrors);
  804                             } else  {
  805                                      response .setValida tionErrors (responseR t.getValid ationError s());
  806                             }
  807  
  808                             if (nu ll == resp onseRt.get InfoMessag es()) {
  809                                      LinkedHa shMap<Stri ng, String > infoMess ages = new  LinkedHas hMap<Strin g, String> ();
  810                                      //infoMe ssages.put ("mviUnaut henticate" , "The aut henticatio n for MHV  User "+ ip a.getPatie nt().getUs erProfile( ).getFirst Name()+" " + ipa.getP atient().g etUserProf ile().getL astName()+ " has been  successfu lly remove d.");
  811                                      response .setInfoMe ssages(inf oMessages) ;
  812                             } else  {
  813                                      response .setInfoMe ssages(res ponseRt.ge tInfoMessa ges());
  814                             }
  815  
  816                             System .out.print ln(">>>> I nPersonAut henticatio nServiceIm pl - mviUn authentica te - retur ning Respo nseUtil<Li st<InPerso nAuthentic ationDTO>>  object.") ;
  817                             return  response;
  818                    } ca tch (Excep tion e) {
  819                             log.er ror(">>>>  Error in I nPersonAut henticatio nServiceIm pl - mviUn authentica te - Error  during Re move Authe ntication.  "+ e);
  820                             System .out.print ln(">>>> E rror in In PersonAuth entication ServiceImp l - mviUna uthenticat e - Error  during Rem ove Authen tication." );
  821                             throw  new MHVRun timeExcept ion(">>>>  Error in I nPersonAut henticatio nServiceIm pl - mviUn authentica te - Error  during Re move Authe ntication. ");
  822                    }
  823           }
  824           
  825           pr ivate Stri ng getEmpl oyeeName(S tring user Name) {
  826                    //MH V_CodeCR15 14 - US12. 4 MVI Comp liance Imp lementatio n - Sectio n 3.7 Add  Authentica ted By
  827  
  828                    Empl oyee emplo yee = empl oyeeReposi tory.findE mployeeByU serName(us erName);                  
  829  
  830                     //Set up t he Authent icated by  in this fo rmat: VA S taff -    Smith, Jan DNS     SMITHJ
  831                    retu rn employe e.getLastN ame() + ",  " +
  832                             employ ee.getFirs tName()+ "  " + "(" +  employee. getUserNam e() + ")";
  833           }        
  834  
  835   /*      pr ivate Stri ng getAcco untStatus( Patient pa tient) {
  836                    Bool ean isPati entAuthent icated = f alse;
  837                    if(p atient !=  null){
  838                             isPati entAuthent icated = i sPatientAu thenticate d(patient. getId());
  839                             if (pa tient.getM atchedDate Time() ==  null){
  840                                      return A ccountStat usEnumerat ion.BASIC;
  841                             } else  if(isPati entAuthent icated !=  null) {
  842                                      if(isPat ientAuthen ticated &&  patient.g etCorrelat ionStatus( ).equals(P atientCorr elationSta tusUtils.C ORRELATED) )
  843                                               return Acc ountStatus Enumeratio n.PREMIUM;
  844                                      else if( isPatientA uthenticat ed && !pat ient.getCo rrelationS tatus().eq uals(Patie ntCorrelat ionStatusU tils.CORRE LATED))
  845                                               return Acc ountStatus Enumeratio n.ADVANCED ;
  846                             else i f(!isPatie ntAuthenti cated && p atient.get MatchedDat eTime() !=  null)
  847                                      return A ccountStat usEnumerat ion.ADVANC ED;
  848                             }else{
  849                                      return A ccountStat usEnumerat ion.ADVANC ED;
  850                             }
  851                    }els e{
  852                             return  AccountSt atusEnumer ation.BASI C;
  853                    }
  854                    retu rn Account StatusEnum eration.AD VANCED;
  855           }
  856           */
  857   }
  858