35. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 8/31/2017 11:16:53 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.

35.1 Files compared

# Location File Last Modified
1 JLV_2.6.zip\JLV_2.6\JLV_2.6\Joint Legacy Viewer\jMeadows\src\main\java\gov\va\med\jmeadows\dataservicehandler PDWSServiceHandler.java Thu Aug 31 12:13:08 2017 UTC
2 JLV_2.6.zip\JLV_2.6\JLV_2.6\Joint Legacy Viewer\jMeadows\src\main\java\gov\va\med\jmeadows\dataservicehandler PDWSServiceHandler.java Thu Aug 31 13:29:02 2017 UTC

35.2 Comparison summary

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

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

35.4 Active regular expressions

No regular expressions were active.

35.5 Comparison detail

  1   /**
  2    * Janus 4 .0 (c)
  3    * Copyrig ht (c) 201 1 Hawaii R esource Gr oup LLC. A ll Rights  Reserved.
  4    * Develop ed for the  Pacific T elehealth  & Technolo gy Hui and  the Pacif ic Joint I nformation  Technolog y Center
  5    * Contrib utors:
  6    *     Hon orable Sen ator Danie l K. Inouy e
  7    *     VA  Pacific Is lands Heal th Care Sy stem
  8    *     Tri pler Army  Medical Ce nter
  9    */
  10  
  11   package go v.va.med.j meadows.da taserviceh andler;
  12  
  13   import gov .va.med.jm eadows.com mon.AppCon fig;
  14   import gov .va.med.jm eadows.com mon.JMeado wsExceptio n;
  15   import gov .va.med.jm eadows.com mon.Langua geCache;
  16   import gov .va.med.jm eadows.dao .beans.PDW SQueryBean ;
  17   import gov .va.med.jm eadows.dao .beans.Res ponsePatie ntQuery;
  18   import gov .va.med.jm eadows.dao .hdd.Codin gSystem;
  19   import gov .va.med.pd ws.*;
  20   import gov .va.med.pd ws.ObjectF actory;
  21   import gov .va.med.vd s.webservi ce.*;
  22   import gov .va.med.vh ahon.commo n.Utils;
  23   import org .apache.co mmons.lang 3.StringUt ils;
  24   import org .slf4j.Log ger;
  25   import org .slf4j.Log gerFactory ;
  26  
  27   import jav ax.xml.bin d.JAXBElem ent;
  28   import jav ax.xml.nam espace.QNa me;
  29   import jav ax.xml.ws. BindingPro vider;
  30   import jav ax.xml.ws. handler.Ha ndler;
  31   import jav a.io.Seria lizable;
  32   import jav a.math.Big Integer;
  33   import jav a.text.Par seExceptio n;
  34   import jav a.text.Sim pleDateFor mat;
  35   import jav a.util.*;
  36  
  37   import jav ax.xml.bin d.JAXBElem ent;
  38   import jav ax.xml.dat atype.Data typeConfig urationExc eption;
  39   import jav ax.xml.dat atype.Data typeFactor y;
  40   import jav ax.xml.dat atype.XMLG regorianCa lendar;
  41   import jav ax.xml.nam espace.QNa me;
  42   import jav ax.xml.ws. BindingPro vider;
  43   import jav ax.xml.ws. handler.Ha ndler;
  44  
  45   import org .apache.co mmons.lang 3.StringUt ils;
  46   import org .slf4j.Log ger;
  47   import org .slf4j.Log gerFactory ;
  48  
  49   public cla ss PDWSSer viceHandle r extends  DataServic eHandler {
  50       privat e static f inal Logge r LOGGER =  LoggerFac tory.getLo gger(PDWSS erviceHand ler.class) ;
  51       privat e final St ring AGENC Y_DOD = AP P_CONFIG.g etAgencyDO D();
  52       privat e final St ring AGENC Y_VA = APP _CONFIG.ge tAgencyVA( );
  53       privat e final St ring PERSO N_SEARCH_U RL = APP_C ONFIG.getP dwsPsUrl() ;
  54       privat e final St ring PERSO N_RETRIEVE _URL = APP _CONFIG.ge tPdwsPrUrl ();
  55       privat e final St ring FAMIL Y_SEARCH_U RL = APP_C ONFIG.getP dwsFsUrl() ;
  56       privat e final St ring FAMIL Y_RETRIEVE _URL = APP _CONFIG.ge tPdwsFrUrl ();
  57       privat e final Bo olean DEBU G_SOAP_OUT PUT;
  58       privat e final En tityPatien tInquiry e ntityPatie ntInquiry  = new Enti tyPatientI nquiry();
  59       privat e static f inal Simpl eDateForma t simpleDa teFormat =  new Simpl eDateForma t("yyyyMMd d");
  60  
  61       public  PDWSServi ceHandler( ) {
  62           su per();
  63           se rviceName  = "PDWSSer vice";
  64             serviceNam espace = " http://web service.pd ws. URL         /";
  65           qS erviceName  = new QNa me(service Namespace,  serviceNa me);
  66           St ring debug  = AppConf ig.getInst ance().get Properties ().getProp erty("DEBU G_SOAP_OUT PUT", "fal se");
  67           if  ("true".e qualsIgnor eCase(debu g)) {
  68                DEBUG_SO AP_OUTPUT  = true;
  69           }  else {
  70                DEBUG_SO AP_OUTPUT  = false;
  71           }
  72       }
  73  
  74       privat e EntityPa tientSearc hPortType  getEntityP atientSear chPort() {
  75           En tityPatien tSearchPor tType port  = entityP atientInqu iry.getEnt ityPatient SearchPort Soap11();
  76  
  77           Bi ndingProvi der prov =  (BindingP rovider) p ort;
  78           pr ov.getRequ estContext ().put(Bin dingProvid er.ENDPOIN T_ADDRESS_ PROPERTY,  PERSON_SEA RCH_URL);
  79           pr ov.getRequ estContext ().put("co m.sun.xml. internal.w s.connect. timeout",  serviceCon nectionTim eoutMS);
  80           pr ov.getRequ estContext ().put("co m.sun.xml. internal.w s.request. timeout",  serviceReq uestTimeou tMS);
  81           pr ov.getRequ estContext ().put("co m.sun.xml. ws.connect .timeout",  serviceCo nnectionTi meoutMS);
  82           pr ov.getRequ estContext ().put("co m.sun.xml. ws.request .timeout",  serviceRe questTimeo utMS);
  83  
  84           if  (DEBUG_SO AP_OUTPUT)  {
  85                prov.get Binding(). getHandler Chain().ad d(new SOAP LoggingHan dler());
  86                List<Han dler> hand lerList =  prov.getBi nding().ge tHandlerCh ain();
  87                handlerL ist.add(ne w SOAPLogg ingHandler ());
  88                prov.get Binding(). setHandler Chain(hand lerList);
  89           }
  90  
  91           re turn port;
  92       }
  93  
  94       privat e EntityPa tientRetri evePortTyp e getEntit yPatientRe trievePort () {
  95           En tityPatien tRetrieveP ortType po rt = entit yPatientIn quiry.getE ntityPatie ntRetrieve PortSoap11 ();
  96  
  97           Bi ndingProvi der prov =  (BindingP rovider) p ort;
  98           pr ov.getRequ estContext ().put(Bin dingProvid er.ENDPOIN T_ADDRESS_ PROPERTY,  PERSON_RET RIEVE_URL) ;
  99           pr ov.getRequ estContext ().put("co m.sun.xml. internal.w s.connect. timeout",  serviceCon nectionTim eoutMS);
  100           pr ov.getRequ estContext ().put("co m.sun.xml. internal.w s.request. timeout",  serviceReq uestTimeou tMS);
  101           pr ov.getRequ estContext ().put("co m.sun.xml. ws.connect .timeout",  serviceCo nnectionTi meoutMS);
  102           pr ov.getRequ estContext ().put("co m.sun.xml. ws.request .timeout",  serviceRe questTimeo utMS);
  103  
  104           if  (DEBUG_SO AP_OUTPUT)  {
  105                prov.get Binding(). getHandler Chain().ad d(new SOAP LoggingHan dler());
  106                List<Han dler> hand lerList =  prov.getBi nding().ge tHandlerCh ain();
  107                handlerL ist.add(ne w SOAPLogg ingHandler ());
  108                prov.get Binding(). setHandler Chain(hand lerList);
  109           }
  110  
  111           re turn port;
  112       }
  113  
  114       privat e EntityPa tientFamil ySearchPor tType getE ntityFamil ySearchPor t() {
  115           En tityPatien tFamilySea rchPortTyp e port = e ntityPatie ntInquiry. getEntityP atientFami lySearchPo rtSoap11() ;
  116  
  117           Bi ndingProvi der prov =  (BindingP rovider) p ort;
  118           pr ov.getRequ estContext ().put(Bin dingProvid er.ENDPOIN T_ADDRESS_ PROPERTY,  FAMILY_SEA RCH_URL);
  119           pr ov.getRequ estContext ().put("co m.sun.xml. internal.w s.connect. timeout",  serviceCon nectionTim eoutMS);
  120           pr ov.getRequ estContext ().put("co m.sun.xml. internal.w s.request. timeout",  serviceReq uestTimeou tMS);
  121           pr ov.getRequ estContext ().put("co m.sun.xml. ws.connect .timeout",  serviceCo nnectionTi meoutMS);
  122           pr ov.getRequ estContext ().put("co m.sun.xml. ws.request .timeout",  serviceRe questTimeo utMS);
  123  
  124           if  (DEBUG_SO AP_OUTPUT)  {
  125                prov.get Binding(). getHandler Chain().ad d(new SOAP LoggingHan dler());
  126                List<Han dler> hand lerList =  prov.getBi nding().ge tHandlerCh ain();
  127                handlerL ist.add(ne w SOAPLogg ingHandler ());
  128                prov.get Binding(). setHandler Chain(hand lerList);
  129           }
  130  
  131           re turn port;
  132       }
  133  
  134       privat e EntityPa tientFamil yRetrieveP ortType ge tEntityFam ilyRetriev ePort() {
  135           En tityPatien tFamilyRet rievePortT ype port =  entityPat ientInquir y.getEntit yPatientFa milyRetrie vePortSoap 11();
  136  
  137           Bi ndingProvi der prov =  (BindingP rovider) p ort;
  138           pr ov.getRequ estContext ().put(Bin dingProvid er.ENDPOIN T_ADDRESS_ PROPERTY,  FAMILY_RET RIEVE_URL) ;
  139           pr ov.getRequ estContext ().put("co m.sun.xml. internal.w s.connect. timeout",  serviceCon nectionTim eoutMS);
  140           pr ov.getRequ estContext ().put("co m.sun.xml. internal.w s.request. timeout",  serviceReq uestTimeou tMS);
  141           pr ov.getRequ estContext ().put("co m.sun.xml. ws.connect .timeout",  serviceCo nnectionTi meoutMS);
  142           pr ov.getRequ estContext ().put("co m.sun.xml. ws.request .timeout",  serviceRe questTimeo utMS);
  143  
  144           if  (DEBUG_SO AP_OUTPUT)  {
  145                prov.get Binding(). getHandler Chain().ad d(new SOAP LoggingHan dler());
  146                List<Han dler> hand lerList =  prov.getBi nding().ge tHandlerCh ain();
  147                handlerL ist.add(ne w SOAPLogg ingHandler ());
  148                prov.get Binding(). setHandler Chain(hand lerList);
  149           }
  150  
  151           re turn port;
  152       }
  153  
  154       privat e PRPAIN20 1305UV02 g enerateReq uest(PDWSQ ueryBean q ueryBean)  {
  155           MC CIMT000100 UV01Device  device;
  156           En Given enGi ven;
  157           II  ii;
  158           CS  cs;
  159           EN  en;
  160           ST  st;
  161           AD  ad;
  162  
  163           Us er user =  queryBean. getUser();
  164           Si te host =  user.getHo stSite();
  165           St ring agenc y = user.g etAgency() ;
  166           St ring dmisI d = "";
  167           St ring siteI d = "";
  168  
  169           if  (host !=  null) {
  170                dmisId =  host.getD misId();
  171                siteId =  host.getS iteCode();
  172           }
  173  
  174           Ob jectFactor y factory  = new Obje ctFactory( );
  175           PR PAIN201305 UV02 reque st = facto ry.createP RPAIN20130 5UV02();
  176  
  177           // id
  178           ii  = factory .createII( );
  179           ii .setRoot(" 2.16.840.1 .113883.3. 2017");
  180           ii .setExtens ion("DMDC" );
  181           re quest.setI d(ii);
  182  
  183           // creationTi me
  184           TS  ts = fact ory.create TS();
  185           Si mpleDateFo rmat simpl eDateForma t = new Si mpleDateFo rmat("yyyy MMddhhmmss ", Locale. getDefault ());
  186           ts .setValue( simpleDate Format.for mat(new Da te()));
  187           re quest.setC reationTim e(ts);
  188  
  189           // interactio nId
  190           ii  = factory .createII( );
  191           ii .setRoot(" 2.16.840.1 .113883.1. 6");
  192           ii .setExtens ion("PRPA_ IN201305UV 02");
  193           re quest.setI nteraction Id(ii);
  194  
  195           // processing Code
  196           cs  = factory .createCS( );
  197           cs .setCode(A PP_CONFIG. getPDWSPro cCode());
  198           re quest.setP rocessingC ode(cs);
  199  
  200           // processing ModeCode
  201           cs  = factory .createCS( );
  202           cs .setCode(" I");
  203           re quest.setP rocessingM odeCode(cs );
  204  
  205           // acceptAckC ode
  206           cs  = factory .createCS( );
  207           cs .setCode(" AL");
  208           re quest.setA cceptAckCo de(cs);
  209  
  210           // receiver
  211           MC CIMT000100 UV01Receiv er receive r = factor y.createMC CIMT000100 UV01Receiv er();
  212           re quest.getR eceiver(). add(receiv er);
  213  
  214           // receiver/t ypeCode
  215           re ceiver.set TypeCode(C ommunicati onFunction Type.RCV);
  216  
  217           // receiver/d evice
  218           de vice = fac tory.creat eMCCIMT000 100UV01Dev ice();
  219           re ceiver.set Device(dev ice);
  220  
  221           // receiver/d evice/clas sCode
  222           de vice.setCl assCode(En tityClassD evice.DEV) ;
  223  
  224           // receiver/d evice/dete rminerCode
  225           de vice.setDe terminerCo de("INSTAN CE");
  226  
  227           // receiver/d evice/id
  228           ii  = factory .createII( );
  229           ii .setRoot(" 1.3.6.1.4. 1.21367.20 09.1.3.1.1 45");
  230           de vice.getId ().add(ii) ;
  231  
  232           // sender
  233           MC CIMT000100 UV01Sender  sender =  factory.cr eateMCCIMT 000100UV01 Sender();
  234           re quest.setS ender(send er);
  235  
  236           // sender/typ eCode
  237           se nder.setTy peCode(Com munication FunctionTy pe.SND);
  238  
  239           // sender/dev ice
  240           de vice = fac tory.creat eMCCIMT000 100UV01Dev ice();
  241           se nder.setDe vice(devic e);
  242  
  243           // sender/dev ice/classC ode
  244           de vice.setCl assCode(En tityClassD evice.DEV) ;
  245  
  246           // sender/dev ice/determ inerCode
  247           de vice.setDe terminerCo de("INSTAN CE");
  248  
  249           // sender/dev ice/id
  250           ii  = factory .createII( );
  251           ii .setRoot(" 2.16.840.1 .113883.3. 2017.11.7" );
  252           ii .setExtens ion(APP_CO NFIG.getPD WSSndDevId ());
  253           de vice.getId ().add(ii) ;
  254  
  255           // sender/dev ice/asAgen t
  256           MC CIMT000100 UV01Agent  agent = fa ctory.crea teMCCIMT00 0100UV01Ag ent();
  257           de vice.setAs Agent(fact ory.create MCCIMT0001 00UV01Devi ceAsAgent( agent));
  258  
  259           // sender/dev ice/asAgen t/classCod e
  260           ag ent.getCla ssCode().a dd("AGNT") ;
  261  
  262           // sender/dev ice/asAgen t/represen tedOrganiz ation
  263           MC CIMT000100 UV01Organi zation org anization  = factory. createMCCI MT000100UV 01Organiza tion();
  264           ag ent.setRep resentedOr ganization (factory.c reateMCCIM T000100UV0 1AgentRepr esentedOrg anization( organizati on));
  265  
  266           // sender/dev ice/asAgen t/represen tedOrganiz ation/clas sCode
  267           or ganization .setClassC ode("ORG") ;
  268  
  269           // sender/dev ice/asAgen t/represen tedOrganiz ation/dete rminerCode
  270           or ganization .setDeterm inerCode(" INSTANCE") ;
  271  
  272           // sender/dev ice/asAgen t/represen tedOrganiz ation/id
  273           ii  = factory .createII( );
  274           if  (AGENCY_D OD.equalsI gnoreCase( agency)) {
  275                ii.setRo ot("2.16.8 40.1.11388 3.3.42.100 02.100001. 8");
  276                ii.setEx tension(dm isId);
  277           }  else if (A GENCY_VA.e qualsIgnor eCase(agen cy)) {
  278                ii.setRo ot("2.16.8 40.1.11388 3.4.349");
  279                ii.setEx tension(si teId);
  280           }
  281           or ganization .getId().a dd(ii);
  282  
  283           // controlAct Process
  284           PR PAIN201305 UV02QUQIMT 021001UV01 ControlAct Process co ntrolActPr ocess = fa ctory.crea tePRPAIN20 1305UV02QU QIMT021001 UV01Contro lActProces s();
  285           re quest.setC ontrolActP rocess(con trolActPro cess);
  286  
  287           // controlAct Process/cl assCode
  288           co ntrolActPr ocess.setC lassCode(A ctClassCon trolAct.CA CT);
  289  
  290           // controlAct Process/mo odCode
  291           co ntrolActPr ocess.setM oodCode(XA ctMoodInte ntEvent.EV N);
  292  
  293           // controlAct Process/co de
  294           CD  cd = fact ory.create CD();
  295           cd .setCode(" PRPA_TE201 305UV02");
  296           co ntrolActPr ocess.setC ode(cd);
  297  
  298           // controlAct Process/co deSystem
  299           cd .setCodeSy stem("2.16 .840.1.113 883.1.6");
  300  
  301           // controlAct Process/da taEnterer
  302           QU QIMT021001 UV01DataEn terer data Enterer =  factory.cr eateQUQIMT 021001UV01 DataEntere r();
  303           co ntrolActPr ocess.getD ataEnterer ().add(dat aEnterer);
  304  
  305           // controlAct Process/da taEnterer/ typeCode
  306           da taEnterer. getTypeCod e().add("E NT");
  307  
  308           // controlAct Process/da taEnterer/ contextCon trolCode
  309           da taEnterer. setContext ControlCod e("AP");
  310  
  311           // controlAct Process/da taEnterer/ assignedPe rson
  312           CO CTMT090100 UV01Assign edPerson a ssignedPer son = fact ory.create COCTMT0901 00UV01Assi gnedPerson ();
  313           da taEnterer. setAssigne dPerson(as signedPers on);
  314  
  315           // controlAct Process/da taEnterer/ assignedPe rson/class Code
  316           as signedPers on.setClas sCode("ASS IGNED");
  317  
  318           // controlAct Process/da taEnterer/ assignedPe rson/id
  319           ii  = factory .createII( );
  320           if  (AGENCY_D OD.equalsI gnoreCase( agency)) {
  321                ii.setRo ot("2.16.8 40.1.11388 3.3.42.127 .100001.79 ");
  322                ii.setEx tension(us er.getUser Ien() + "^ " + dmisId );
  323           }  else if (A GENCY_VA.e qualsIgnor eCase(agen cy)) {
  324                ii.setRo ot("2.16.8 40.1.11388 3.4.349");
  325                ii.setEx tension(us er.getUser Ien() + "^ " + siteId );
  326           }
  327           as signedPers on.getId() .add(ii);
  328  
  329           // controlAct Process/da taEnterer/ assignedPe rson/Perso n
  330           CO CTMT090100 UV01Person  person1 =  factory.c reateCOCTM T090100UV0 1Person();
  331           as signedPers on.setAssi gnedPerson (factory.c reateCOCTM T090100UV0 1AssignedP ersonAssig nedPerson( person1));
  332  
  333           // controlAct Process/da taEnterer/ assignedPe rson/Perso n/name
  334           en  = factory .createEN( );
  335           en .getConten t().add(qu eryBean.ge tUser().ge tName());
  336           pe rson1.getN ame().add( en);
  337  
  338           // controlAct Process/qu eryByParam eter
  339           PR PAMT201306 UV02QueryB yParameter  queryByPa rameter =  factory.cr eatePRPAMT 201306UV02 QueryByPar ameter();
  340           co ntrolActPr ocess.setQ ueryByPara meter(fact ory.create PRPAIN2013 05UV02QUQI MT021001UV 01ControlA ctProcessQ ueryByPara meter(quer yByParamet er));
  341  
  342           // controlAct Process/qu eryByParam eter/query Id
  343           ii  = factory .createII( );
  344           ii .setRoot(" 2.16.840.1 .113883.3. 2017");
  345           ii .setExtens ion("33333 4433");
  346           qu eryByParam eter.setQu eryId(ii);
  347  
  348           // controlAct Process/qu eryByParam eter/statu sCode
  349           cs  = factory .createCS( );
  350           cs .setCode(" new");
  351           qu eryByParam eter.setSt atusCode(c s);
  352  
  353           // controlAct Process/qu eryByParam eter/initi alQuantity
  354           IN T i = fact ory.create INT();
  355           i. setValue(B igInteger. valueOf(10 ));
  356           qu eryByParam eter.setIn itialQuant ity(i);
  357  
  358           // controlAct Process/qu eryByParam eter/param eterList
  359           PR PAMT201306 UV02Parame terList pa rameterLis t = factor y.createPR PAMT201306 UV02Parame terList();
  360           qu eryByParam eter.setPa rameterLis t(paramete rList);
  361  
  362           // controlAct Process/qu eryByParam eter/param eterList/l ivingSubje ctId
  363           if  (!"".equa ls(queryBe an.getPati entId()) & & !"".equa ls(queryBe an.getPati entIdType( ))) {
  364                ii = fac tory.creat eII();
  365                ii.setEx tension(qu eryBean.ge tPatientId ());
  366  
  367                String t ype = quer yBean.getP atientIdTy pe();
  368                if ("SSN ".equalsIg noreCase(t ype)) {
  369                    ii.s etRoot("2. 16.840.1.1 13883.4.1" );
  370                } else i f ("TIN".e qualsIgnor eCase(type )) {
  371                    ii.s etRoot("2. 16.840.1.1 13883.3.42 .10001.100 001.225");
  372                } else i f ("FIN".e qualsIgnor eCase(type )) {
  373                    ii.s etRoot("2. 16.840.1.1 13883.3.42 .10001.100 001.224");
  374                } else i f ("ITIN". equalsIgno reCase(typ e)) {
  375                    ii.s etRoot("2. 16.840.1.1 13883.4.2" );
  376                } else i f ("PIN".e qualsIgnor eCase(type )) {
  377                    ii.s etRoot("2. 16.840.1.1 13883.3.42 .10001.100 001.226");
  378                } else i f ("EDIPI" .equalsIgn oreCase(ty pe)) {
  379                    ii.s etRoot("2. 16.840.1.1 13883.3.42 .10001.100 001.12");
  380                }
  381  
  382                PRPAMT20 1306UV02Li vingSubjec tId living SubjectId  = factory. createPRPA MT201306UV 02LivingSu bjectId();
  383                livingSu bjectId.ge tValue().a dd(ii);
  384                paramete rList.getL ivingSubje ctId().add (livingSub jectId);
  385  
  386                //contro lActProces s/queryByP arameter/p arameterLi st/livingS ubjectId/s emanticsTe xt
  387                st = fac tory.creat eST();
  388                st.getCo ntent().ad d("LivingS ubject.id" );
  389                livingSu bjectId.se tSemantics Text(st);
  390           }
  391  
  392           // controlAct Process/qu eryByParam eter/param eterList/l ivingSubje ctAdminist rativeGend er
  393           if  (queryBea n.getGende r() != nul l) {
  394                PRPAMT20 1306UV02Li vingSubjec tAdministr ativeGende r adminGen der = fact ory.create PRPAMT2013 06UV02Livi ngSubjectA dministrat iveGender( );
  395                CE ce =  factory.cr eateCE();
  396                ce.setCo de(queryBe an.getGend er());
  397                adminGen der.getVal ue().add(c e);
  398                paramete rList.getL ivingSubje ctAdminist rativeGend er().add(a dminGender );
  399  
  400                //contro lActProces s/queryByP arameter/p arameterLi st/livingS ubjectAdmi nistrative Gender/sem anticsText
  401                st = fac tory.creat eST();
  402                st.getCo ntent().ad d("LivingS ubject.adm inistrativ eGender");
  403                adminGen der.setSem anticsText (st);
  404           }
  405  
  406           // controlAct Process/qu eryByParam eter/param eterList/l ivingSubje ctBirthTim e
  407           PR PAMT201306 UV02Living SubjectBir thTime bir thTime = f actory.cre atePRPAMT2 01306UV02L ivingSubje ctBirthTim e();
  408           IV LTS ivlts  = factory. createIVLT S();
  409           iv lts.setVal ue(queryBe an.getDob( ));
  410           bi rthTime.ge tValue().a dd(ivlts);
  411           pa rameterLis t.getLivin gSubjectBi rthTime(). add(birthT ime);
  412  
  413           // controlAct Process/qu eryByParam eter/param eterList/l ivingSubje ctBirthTim e/semantic sText
  414           st  = factory .createST( );
  415           st .getConten t().add("L ivingSubje ct.birthTi me");
  416           bi rthTime.se tSemantics Text(st);
  417  
  418           // controlAct Process/qu eryByParam eter/param eterList/l ivingSubje ctName
  419           PR PAMT201306 UV02Living SubjectNam e name = f actory.cre atePRPAMT2 01306UV02L ivingSubje ctName();
  420           en  = factory .createEN( );
  421           en .getUse(). add("L");
  422  
  423           if  (StringUt ils.isNotB lank(query Bean.getFi rstName()) ) {
  424                enGiven  = factory. createEnGi ven();
  425                enGiven. getContent ().add(que ryBean.get FirstName( ));
  426                en.getCo ntent().ad d(factory. createENGi ven(enGive n));
  427           }
  428  
  429           if  (StringUt ils.isNotB lank(query Bean.getMi ddleName() )) {
  430                enGiven  = factory. createEnGi ven();
  431                enGiven. getContent ().add(que ryBean.get MiddleName ());
  432                en.getCo ntent().ad d(factory. createENGi ven(enGive n));
  433           }
  434  
  435           if  (StringUt ils.isNotB lank(query Bean.getLa stName()))  {
  436                EnFamily  enFamily  = factory. createEnFa mily();
  437                enFamily .getConten t().add(qu eryBean.ge tLastName( ));
  438                en.getCo ntent().ad d(factory. createENFa mily(enFam ily));
  439           }
  440  
  441           na me.getValu e().add(en );
  442           pa rameterLis t.getLivin gSubjectNa me().add(n ame);
  443  
  444           // controlAct Process/qu eryByParam eter/param eterList/l ivingSubje ctName/sem anticsText
  445           st  = factory .createST( );
  446           st .getConten t().add("L ivingSubje ct.name");
  447           na me.setSema nticsText( st);
  448  
  449           // controlAct Process/qu eryByParam eter/param eterList/p atientAddr ess/value
  450           PR PAMT201306 UV02Patien tAddress a ddress = f actory.cre atePRPAMT2 01306UV02P atientAddr ess();
  451           ad  = factory .createAD( );
  452           ad .getUse(). add("HP");
  453  
  454           // controlAct Process/qu eryByParam eter/param eterList/p atientAddr ess/value/ [@use="HP" ]/streetAd dressLine
  455           if  (StringUt ils.isNotB lank(query Bean.getAd dress()))  {
  456                AdxpStre etAddressL ine addres sLine = fa ctory.crea teAdxpStre etAddressL ine();
  457                addressL ine.getCon tent().add (queryBean .getAddres s());
  458                ad.getCo ntent().ad d(factory. createADSt reetAddres sLine(addr essLine));
  459           }
  460  
  461           // controlAct Process/qu eryByParam eter/param eterList/p atientAddr ess/value/ [@use="HP" ]/city
  462           if  (StringUt ils.isNotB lank(query Bean.getCi ty())) {
  463                AdxpCity  city = fa ctory.crea teAdxpCity ();
  464                city.get Content(). add(queryB ean.getCit y());
  465                ad.getCo ntent().ad d(factory. createADCi ty(city));
  466           }
  467  
  468           // controlAct Process/qu eryByParam eter/param eterList/p atientAddr ess/value/ [@use="HP" ]/state
  469           if  (StringUt ils.isNotB lank(query Bean.getSt ate())) {
  470                AdxpStat e state =  factory.cr eateAdxpSt ate();
  471                state.ge tContent() .add(query Bean.getSt ate());
  472                ad.getCo ntent().ad d(factory. createADSt ate(state) );
  473           }
  474  
  475           // controlAct Process/qu eryByParam eter/param eterList/p atientAddr ess/value/ [@use="HP" ]/zip
  476           if  (StringUt ils.isNotB lank(query Bean.getZi p())) {
  477                AdxpPost alCode zip  = factory .createAdx pPostalCod e();
  478                zip.getC ontent().a dd(queryBe an.getZip( ));
  479                ad.getCo ntent().ad d(factory. createADPo stalCode(z ip));
  480           }
  481  
  482           ad dress.getV alue().add (ad);
  483           pa rameterLis t.getPatie ntAddress( ).add(addr ess);
  484  
  485           // controlAct Process/qu eryByParam eter/param eterList/o therIDsSco pingOrgani zation
  486           PR PAMT201306 UV02OtherI DsScopingO rganizatio n otherIDs ScopingOrg anization  = factory. createPRPA MT201306UV 02OtherIDs ScopingOrg anization( );
  487           pa rameterLis t.getOther IDsScoping Organizati on().add(o therIDsSco pingOrgani zation);
  488  
  489           // controlAct Process/qu eryByParam eter/param eterList/o therIDsSco pingOrgani zation/val ue/id
  490           ii  = factory .createII( );
  491           ii .setRoot(" 2.16.840.1 .113883.4. 1");
  492           ot herIDsScop ingOrganiz ation.getV alue().add (ii);
  493  
  494           // controlAct Process/qu eryByParam eter/param eterList/o therIDsSco pingOrgani zation/sem anticsText
  495           st  = factory .createST( );
  496           st .getConten t().add("O therIDs.sc opingOrgan ization.id ");
  497           ot herIDsScop ingOrganiz ation.setS emanticsTe xt(st);
  498  
  499           // controlAct Process/qu eryByParam eter/param eterList/p atientTelc om
  500           if  (StringUt ils.isNotB lank(query Bean.getTe l())) {
  501                PRPAMT20 1306UV02Pa tientTelec om telecom  = factory .createPRP AMT201306U V02Patient Telecom();
  502                TEL tel  = factory. createTEL( );
  503                tel.setV alue(query Bean.getTe l());
  504                tel.getU se().add(" H");
  505                telecom. getValue() .add(tel);
  506                paramete rList.getP atientTele com().add( telecom);
  507           }
  508  
  509           re turn reque st;
  510       }
  511  
  512       privat e Response PatientQue ry parseRe sponse(PRP AIN201306U V02 respon se, String  inquiryTy pe) {
  513           Re sponsePati entQuery r espPatQuer y = new Re sponsePati entQuery() ;
  514           bo olean done  = false;
  515           
  516           //  Initially  set to fa ilure with  generic e rror messa ge. Will o nly be
  517           //  set to su ccess if t here are n o acknowle dgement er rors and n o
  518           //  errors re trieving p atient lis t, even if  the list  is empty
  519           re spPatQuery .setSucces s(false);
  520           re spPatQuery .setErrorM sg("Error  retrieving  patients. "
  521                    + "< br><br>Ple ase try ag ain."
  522                    + "< br><br>If  the proble m persists , notify y our system  administr ator or he lp desk.") ;
  523  
  524           //  Create li st of resu lt patient s
  525           Li st<Patient > resultPa tientList  = new Arra yList<Pati ent>();
  526  
  527           if  (response  != null)  {
  528                if (resp onse.getAc knowledgem ent() != n ull) {
  529                    Ackn owledgemen tDetailTyp e ackDetai lTypeCode;
  530                    Stri ng ackCode ;
  531                    Stri ng ackDeta ilCode;
  532                    Stri ng display Message;
  533                    CS c s;
  534                    CE c e;
  535  
  536                    for  (MCCIMT000 300UV01Ack nowledgeme nt acknowl edgement :  response. getAcknowl edgement() ) {
  537                         cs = ackno wledgement .getTypeCo de();
  538                         if (cs ==  null) { co ntinue; }
  539  
  540                         ackCode =  cs.getCode ();
  541  
  542                         if (acknow ledgement. getAcknowl edgementDe tail() ==  null) { co ntinue; }
  543                         for (MCCIM T000300UV0 1Acknowled gementDeta il ackDeta il : ackno wledgement .getAcknow ledgementD etail()) {
  544                             ackDet ailTypeCod e = ackDet ail.getTyp eCode();
  545  
  546                             ce = a ckDetail.g etCode();
  547                             if (ce  == null)  { continue ; }
  548  
  549                             ackDet ailCode =  ce.getCode ();
  550                             displa yMessage =  ce.getDis playName() ;
  551  
  552                             if ("A A".equalsI gnoreCase( ackCode))  {
  553                                 if  (ackDetai lTypeCode  == Acknowl edgementDe tailType.W  
  554                                          && a ckDetailCo de.contain s("PN") ||  ackDetail Code.conta ins("FM"))  {
  555                                      respPatQ uery.setEr rorMsg(dis playMessag e);
  556                                 }
  557                             } else  if ("AE". equalsIgno reCase(ack Code) 
  558                                      && ackDe tailTypeCo de == Ackn owledgemen tDetailTyp e.E 
  559                                      && !ackD etailCode. contains(" PN") && !a ckDetailCo de.contain s("FM")) {
  560                                 re spPatQuery .setErrorM sg(display Message);
  561                                 re spPatQuery .setSucces s(false);
  562                                 do ne = true;
  563                                 br eak;
  564                             }
  565                         }
  566                    }
  567                }
  568                if (!don e) {
  569                    PRPA IN201306UV 02MFMIMT70 0711UV01Co ntrolActPr ocess cont rolActProc ess = resp onse.getCo ntrolActPr ocess();
  570                    if ( (controlAc tProcess ! = null) &&  (controlA ctProcess. getSubject () != null )) {
  571                         PRPAIN2013 06UV02MFMI MT700711UV 01Registra tionEvent  registrati onEvent;
  572                         PRPAIN2013 06UV02MFMI MT700711UV 01Subject2  subject1;
  573                         PRPAMT2013 10UV02Pati ent patien t;
  574                         PRPAMT2013 10UV02Pers on patient Person;
  575                         CE ce;
  576                         TS ts;
  577                         CS cs;
  578                         SC sc;
  579                         Code code;
  580                         List<Patie nt> person alRelation shipList;
  581                         List<Perso n> sponsor List;
  582                         List<PRPAM T201310UV0 2ContactPa rty> conta ctPartyLis t;
  583                         Patient re sultPatien t;
  584                         PatientDem ographics  resultDemo graphics;
  585                         PatientDem ographics  tempDemogr aphics;
  586  
  587                         for (PRPAI N201306UV0 2MFMIMT700 711UV01Sub ject1 subj ect : cont rolActProc ess.getSub ject()) {
  588                             regist rationEven t = subjec t.getRegis trationEve nt();
  589                             if (re gistration Event == n ull) { con tinue; }
  590       
  591                             subjec t1 = regis trationEve nt.getSubj ect1();
  592                             if (su bject1 ==  null) { co ntinue; }
  593       
  594                             patien t = subjec t1.getPati ent();
  595                             if (pa tient == n ull) { con tinue; }
  596       
  597                             result Patient =  new Patien t();
  598                             result Demographi cs = new P atientDemo graphics() ;
  599                             tempDe mographics  = new Pat ientDemogr aphics();
  600       
  601                             // Pat ient EDIPI
  602                             if (pa tient.getI d() != nul l) {
  603                                 fo r (II ii :  patient.g etId()) {
  604                                      resultPa tient.setE DIPI(ii.ge tExtension ());
  605                                 }
  606                             }
  607       
  608                             if (pa tient.getP atientPers on() != nu ll) {
  609                                 pa tientPerso n = patien t.getPatie ntPerson() .getValue( );
  610                                 if  (patientP erson != n ull) {
  611                                      // Patie nt gender
  612                                      ce = pat ientPerson .getAdmini strativeGe nderCode() ;
  613                                      if (ce ! = null) {
  614                                          resu ltPatient. setGender( ce.getCode ());
  615                                      }
  616       
  617                                      // Patie nt date of  birth
  618                                      ts = pat ientPerson .getBirthT ime();
  619                                      if (ts ! = null) {
  620                                          resu ltPatient. setDob(ts. getValue() );
  621                                      }
  622       
  623                                      // Patie nt name
  624                                      if (pati entPerson. getName()  != null) {
  625                                          for  (PN pn : p atientPers on.getName ()) {
  626                                               if (pn.get Use() == n ull) { con tinue; }
  627                                               for (Strin g use : pn .getUse())  {
  628                                                   if ("L ".equalsIg noreCase(u se)) {
  629                                                       re sultPatien t.setName( parseName( pn));
  630                                                   }
  631                                               }
  632                                          }
  633                                      }
  634                                      // Patie nt SSN
  635                                      if (pati entPerson. getAsOther IDs() != n ull) {
  636                                          for  (PRPAMT201 310UV02Oth erIDs othe rIDs : pat ientPerson .getAsOthe rIDs()) {
  637                                               if (otherI Ds.getId()  == null)  { continue ; }
  638                                               for (II ii  : otherID s.getId())  {
  639                                                   cs = o therIDs.ge tStatusCod e();
  640                                                   if (cs  == null)  { continue ; }
  641                                                   if ("2 .16.840.1. 113883.4.1 ".equalsIg noreCase(i i.getRoot( ))
  642                                                            && "acti ve".equals IgnoreCase (cs.getCod e())) {
  643                                                       re sultPatien t.setSSN(i i.getExten sion());
  644                                                   }
  645                                               }
  646                                          }
  647                                      }
  648                                      if ("PR" .equalsIgn oreCase(in quiryType) ) {
  649                                          // P atient ran k
  650                                          if ( patientPer son.getAsE mployee()  != null) {
  651                                               for (PRPAM T201310UV0 2Employee  employee :  patientPe rson.getAs Employee() ) {
  652                                                   sc = e mployee.ge tJobTitleN ame();
  653                                                   if (sc  == null)  { continue ; }
  654                                                   result Demographi cs.setRank (sc.getDis playName() );
  655                                               }
  656                                          }
  657       
  658                                          // P atient rac e code
  659                                          if ( patientPer son.getRac eCode() !=  null) {
  660                                               code = new  Code();
  661                                               for (CE ce 1 : patien tPerson.ge tRaceCode( )) {
  662                                                   code.s etCode(ce1 .getCode() );
  663                                                   code.s etSystem(C odingSyste m.CDC_RACE .getDispla yName());
  664                                                   result Demographi cs.getRace ().add(cod e);
  665                                               }
  666                                          }
  667                                          
  668                                          // P atient Lan guage (cur rently is  a string b ut can be  a code)
  669                                          if ( patientPer son.getLan guageCommu nication()  != null)  {
  670                                               code = new  Code();
  671                                               for (PRPAM T201310UV0 2LanguageC ommunicati on lc1 : p atientPers on.getLang uageCommun ication())  {
  672                                                   String  langDispl ay = lc1.g etLanguage Code().get Code();
  673                                                   result Demographi cs.getLang uages().ad d(Language Cache.getL abel(langD isplay));
  674                                               }
  675                                          }
  676  
  677                                          // P atient hom e & work t elephone n umbers
  678                                          if ( patientPer son.getTel ecom() !=  null) {
  679                                               for (TEL t el : patie ntPerson.g etTelecom( )) {
  680                                                   if ((t el.getUse( ) == null)
  681                                                            || (tel. getUse().s ize() > 1)
  682                                                            || (tel. getValue() .contains( "mailto"))
  683                                                            || (tel. getValue() .contains( "@"))) {
  684                                                       co ntinue;
  685                                                   }
  686                                                   for (S tring use  : tel.getU se()) {
  687                                                       if  ("HP".equ alsIgnoreC ase(use))  {
  688                                                            resultDe mographics .setPhone1 (parsePhon eNumber(te l.getValue ()));
  689                                                       }  else if (" WP".equals IgnoreCase (use)) {
  690                                                            resultDe mographics .setPhone2 (parsePhon eNumber(te l.getValue ()));
  691                                                       }
  692                                                   }
  693                                               }
  694                                          }
  695       
  696                                          // P atient's a ddress
  697                                          pars eAddress(p atientPers on, tempDe mographics );
  698       
  699                                          // S ponsors
  700                                          spon sorList =  parseSpons ors(patien tPerson);
  701                                          if(s ponsorList  != null & & sponsorL ist.size()  > 0) {
  702                                               resultDemo graphics.g etSponsors ().addAll( sponsorLis t);
  703                                          }
  704  
  705                                          BL o rganDonorI nd = patie ntPerson.g etOrganDon orInd();
  706                                          if ( organDonor Ind != nul l && organ DonorInd.i sValue() ! = null) {
  707                                               resultDemo graphics.s etOrganDon orInd(Stri ng.valueOf (organDono rInd.isVal ue()));
  708                                          }
  709  
  710                                          List <PRPAMT201 310UV02Sub ject4> sub jectOf2 =  patient.ge tSubjectOf 2();
  711                                          if ( subjectOf2  != null)  {
  712                                               for (int i  = 0; i <  subjectOf2 .size(); i ++) {
  713                                                   PRPAMT 201310UV02 Subject4 p rpamt20131 0UV02Subje ct4 = subj ectOf2.get (i);
  714                                                   PRPAMT 201310UV02 Administra tiveObserv ation admi nistrative Observatio n = prpamt 201310UV02 Subject4.g etAdminist rativeObse rvation();
  715                                                   if (ad ministrati veObservat ion != nul l) {
  716                                                       CD  code1 = a dministrat iveObserva tion.getCo de();
  717                                                       if  (code1 !=  null && c ode1.getCo de() != nu ll) {
  718                                                            String c odeString  = code1.ge tCode().tr im();
  719                                                            //blood  donor indi cation dat e
  720                                                            if ("2.1 6.840.1.11 3883.3.201 7.11.6.2.2 ".equals(c odeString)
  721                                                                     && adminis trativeObs ervation.g etEffectiv eTime() !=  null
  722                                                                     && adminis trativeObs ervation.g etEffectiv eTime().si ze() > 0
  723                                                                     //note thi s assumes  the date i s the firs t entry
  724                                                                     && adminis trativeObs ervation.g etEffectiv eTime().ge t(0) != nu ll) {
  725                                                                IVLT S sxcmts =  (IVLTS) a dministrat iveObserva tion.getEf fectiveTim e().get(0) ;
  726                                                                if ( sxcmts !=  null) {
  727                                                                     List<JAXBE lement<? e xtends QTY >> rest =  sxcmts.get Rest();
  728                                                                     if (rest ! = null &&  rest.size( ) > 0) {
  729                                                                         JAXBEl ement jaxb Element =  rest.get(0 );
  730                                                                         IVXBTS  ixIvxbts  = (IVXBTS)  jaxbEleme nt.getValu e();
  731                                                                         if (ix Ivxbts !=  null) {
  732                                                                             St ring value  = ixIvxbt s.getValue ();
  733                                                                             if  (value !=  null) {
  734                                                                                  Date d =  null;
  735  
  736                                                                                  try {
  737                                                                                      d =  simpleDate Format.par se(value);
  738                                                                                  } catch  (ParseExce ption e) {
  739                                                                                      LOGG ER.error(" Error pars ing organ  donor ind  date: ", e );
  740                                                                                  }
  741                                                                                  Gregoria nCalendar  orgIndDate GregorianC alendar =  new Gregor ianCalenda r();
  742                                                                                  orgIndDa teGregoria nCalendar. setTime(d) ;
  743                                                                                  Datatype Factory da tatypeFact ory = null ;
  744                                                                                  try {
  745                                                                                      data typeFactor y = Dataty peFactory. newInstanc e();
  746                                                                                  } catch  (DatatypeC onfigurati onExceptio n e) {
  747                                                                                      LOGG ER.error(" Error crea ting Datat ypeFactory : ", e);
  748                                                                                  }
  749                                                                                  XMLGrego rianCalend ar xd = da tatypeFact ory.newXML GregorianC alendar(or gIndDateGr egorianCal endar);
  750  
  751                                                                                  resultDe mographics .setOrganD onorIndDat e(xd);
  752                                                                             }
  753                                                                         }
  754                                                                     }
  755                                                                }
  756                                                            }
  757                                                            //blood  type
  758                                                            else if  ("2.16.840 .1.113883. 3.2017.11. 6.2.3".equ als(codeSt ring)
  759                                                                     && adminis trativeObs ervation.g etValue()  != null) {
  760                                                                CD v alue1 = (C D) adminis trativeObs ervation.g etValue();
  761                                                                if ( value1 !=  null) {
  762                                                                     resultDemo graphics.s etBloodTyp e(value1.g etDisplayN ame());
  763                                                                }
  764                                                            }
  765                                                       }
  766                                                   }
  767                                               }
  768                                          }
  769  
  770  
  771                                          // E mergency C ontact/Nex t of Kin
  772                                          cont actPartyLi st = patie ntPerson.g etContactP arty();
  773                                          if ( (contactPa rtyList !=  null) &&  (!contactP artyList.i sEmpty()))  {
  774                                               for (PRPAM T201310UV0 2ContactPa rty contac tParty : c ontactPart yList)
  775                                               {
  776                                                   if ("E CON".equal sIgnoreCas e(contactP arty.getCl assCode(). name()))
  777                                                   {
  778                                                       Pe rson perso n = parseP erson(cont actParty);
  779                                                       re sultDemogr aphics.get EmergencyC ontact().a dd(person) ;
  780                                                   }
  781                                                   else i f ("NOK".e qualsIgnor eCase(cont actParty.g etClassCod e().name() ))
  782                                                   {
  783                                                       Pe rson perso n = parseP erson(cont actParty);
  784                                                       re sultDemogr aphics.get NextOfKin( ).add(pers on);
  785                                                   }
  786                                               }
  787                                          }
  788  
  789                                      } else i f ("FR".eq ualsIgnore Case(inqui ryType)) {
  790                                          // F amily memb ers (depen dents)
  791                                          pers onalRelati onshipList  = parsePe rsonalRela tionship(p atientPers on);
  792                                          if ( personalRe lationship List != nu ll) {
  793                                               for (Patie nt patient 1 : person alRelation shipList)  {
  794                                                   // Set  sponsor S SN for eac h family m ember
  795                                                   patien t1.setSpon sorSSN(res ultPatient .getSSN()) ;
  796                                               }
  797                                               resultPati entList.ad dAll(perso nalRelatio nshipList) ;
  798                                          }
  799                                      }
  800                                 }
  801                             }
  802                             if (!" FR".equals IgnoreCase (inquiryTy pe)) {
  803                                 //  Set patie nt data
  804                                 re sultPatien tList.add( resultPati ent);
  805                             }
  806                             if ("P R".equalsI gnoreCase( inquiryTyp e)) {
  807                                 //  Patient's  primary c are manage r (PCM)
  808                                 pa rsePrimary CareManage r(patient,  tempDemog raphics);
  809       
  810                                 //  Set demog raphics da ta
  811                                 Ad dress addr ess = new  Address();
  812                                 re sultDemogr aphics.set EDIPI(resu ltPatient. getEDIPI() );
  813                                 re sultDemogr aphics.set SSN(result Patient.ge tSSN());
  814                                 re sultDemogr aphics.set Name(resul tPatient.g etName());
  815                                 re sultDemogr aphics.set Gender(res ultPatient .getGender ());
  816                                 re sultDemogr aphics.set Dob(result Patient.ge tDob());
  817                                 if (tempDemog raphics.ge tAddress()  != null & & tempDemo graphics.g etAddress( ).size() >  0) {
  818   //                                   addres s.setStree t1(tempDem ographics. getAddress ().get(0). getStreet1 ());
  819   //                                   addres s.setStree t2(tempDem ographics. getAddress ().get(0). getStreet2 ());
  820   //                                   addres s.setCity( tempDemogr aphics.get Address(). get(0).get City());
  821   //                                   addres s.setState Province(t empDemogra phics.getA ddress().g et(0).getS tateProvin ce());
  822   //                                   addres s.setPosta lCode(temp Demographi cs.getAddr ess().get( 0).getPost alCode());
  823                                      resultDe mographics .getAddres s().addAll (tempDemog raphics.ge tAddress() );
  824                                 }
  825                                 re sultDemogr aphics.set PrimaryPro vider(temp Demographi cs.getPrim aryProvide r());
  826                                 re sultDemogr aphics.set PcmDates(t empDemogra phics.getP cmDates()) ;
  827                                 re sultDemogr aphics.set PcmClinic( tempDemogr aphics.get PcmClinic( ));
  828                                 re spPatQuery .setDemogr aphics(res ultDemogra phics);
  829                             }
  830                         }
  831                         respPatQue ry.setSucc ess(true);
  832                         respPatQue ry.setErro rMsg(null) ;
  833                         respPatQue ry.setPati ents(resul tPatientLi st);
  834                    }
  835                }
  836           }
  837           re turn respP atQuery;
  838       }
  839  
  840       privat e void par seAddress( PRPAMT2013 10UV02Pers on person,  PatientDe mographics  patientDe mographics ) {
  841           Li st<String>  streetAdd ressList =  new Array List<Strin g>();
  842           Li st<Seriali zable> ser ializableL ist;
  843           Ob ject objec t;
  844           Bo olean isBa dAddress;
  845           Bo olean isCo nfidential ;
  846  
  847           Li st<Address > homeList  = new Arr ayList<Add ress>();
  848           Li st<Address > tempList  = new Arr ayList<Add ress>();
  849           Li st<Address > workList  = new Arr ayList<Add ress>();
  850           Li st<Address > postalLi st = new A rrayList<A ddress>();
  851           Li st<Address > pharmLis t = new Ar rayList<Ad dress>();
  852  
  853           //  Check for  home prim ary addres s and bad  address
  854           fo r (AD ad :  person.ge tAddr()) {
  855  
  856                Address  address =  new Addres s();
  857  
  858                isBadAdd ress = fal se;
  859                isConfid ential = f alse;
  860  
  861                if (ad.g etUse() ==  null) {
  862                    cont inue;
  863                }
  864  
  865                for (Str ing use :  ad.getUse( )) {
  866                    if ( use.contai ns("BAD"))  {
  867                         isBadAddre ss = true;
  868                         address.se tType("BAD ");
  869                    } el se if (use .contains( "DIR")) {
  870                         isConfiden tial = tru e;
  871                         address.se tType("CON FIDENTIAL" );
  872                    } el se if (use .contains( "HP")) {
  873                         address.se tType("Hom e");
  874                    } el se if (use .contains( "TMP")) {
  875                         address.se tType("Tem porary");
  876                    } el se if (use .contains( "PST")) {
  877                         address.se tType("Pos tal");
  878                    } el se if (use .contains( "WP")) {
  879                         address.se tType("Wor k");
  880                    } el se if (use .contains( "PHYS")) {
  881                         address.se tType("Pha rmacy");
  882                    }
  883                }
  884  
  885                // If no t home pri mary addre ss or addr ess is bad  or addres s content  is null, t hen skip t o next
  886                if (isCo nfidential  || isBadA ddress ||  (ad.getCon tent() ==  null)) {
  887                    cont inue;
  888                }
  889  
  890                streetAd dressList. clear();
  891  
  892                for (Ser ializable  serializab le : ad.ge tContent() ) {
  893                    if ( serializab le instanc eof JAXBEl ement) {
  894                         object = ( (JAXBEleme nt) serial izable).ge tValue();
  895                         if (object  == null)  {
  896                             contin ue;
  897                         }
  898  
  899                         // Street  address
  900                         if (object  instanceo f AdxpStre etAddressL ine) {
  901                             serial izableList  = ((AdxpS treetAddre ssLine) ob ject).getC ontent();
  902                             if ((s erializabl eList != n ull) && !s erializabl eList.isEm pty()) {
  903                                 st reetAddres sList.add( serializab leList.get (0).toStri ng());
  904                             }
  905                         } else if  (object in stanceof A dxpCity) {                       // City
  906                             serial izableList  = ((AdxpC ity) objec t).getCont ent();
  907                             if ((s erializabl eList != n ull) && !s erializabl eList.isEm pty()) {
  908                                 ad dress.setC ity(serial izableList .get(0).to String());
  909                             }
  910                         } else if  (object in stanceof A dxpState)  {                      // State
  911                             serial izableList  = ((AdxpS tate) obje ct).getCon tent();
  912                             if ((s erializabl eList != n ull) && !s erializabl eList.isEm pty()) {
  913                                 ad dress.setS tateProvin ce(seriali zableList. get(0).toS tring());
  914                             }
  915                         }
  916                         // Zip cod e
  917                         if (object  instanceo f AdxpPost alCode) {
  918                             serial izableList  = ((AdxpP ostalCode)  object).g etContent( );
  919                             if ((s erializabl eList != n ull) && !s erializabl eList.isEm pty()) {
  920                                 ad dress.setP ostalCode( serializab leList.get (0).toStri ng());
  921                             }
  922                         }
  923                    }
  924                }
  925  
  926                // Set s treet addr ess from l ist
  927                if (!str eetAddress List.isEmp ty()) {
  928                    addr ess.setStr eet1(stree tAddressLi st.get(0)) ;
  929                    if ( streetAddr essList.si ze() > 1)  {
  930                         address.se tStreet2(s treetAddre ssList.get (1));
  931                    }
  932                }
  933  
  934                //patien tDemograph ics.getAdd ress().add (address);
  935                if (addr ess.getTyp e().equals IgnoreCase ("Home"))  {
  936                    home List.add(a ddress);
  937                } else i f (address .getType() .equalsIgn oreCase("T emporary") ) {
  938                    temp List.add(a ddress);
  939                } else i f (address .getType() .equalsIgn oreCase("P ostal")) {
  940                    post alList.add (address);
  941                } else i f (address .getType() .equalsIgn oreCase("W ork")) {
  942                    work List.add(a ddress);
  943                } else i f (address .getType() .equalsIgn oreCase("P harmacy"))  {
  944                    phar mList.add( address);
  945                }
  946           }
  947  
  948           if (homeList. size()>0)  patientDem ographics. getAddress ().addAll( homeList);
  949           if (tempList. size()>0)  patientDem ographics. getAddress ().addAll( tempList);
  950           if (postalLis t.size()>0 ) patientD emographic s.getAddre ss().addAl l(postalLi st);
  951           if (workList. size()>0)  patientDem ographics. getAddress ().addAll( workList);
  952           if (pharmList .size()>0)  patientDe mographics .getAddres s().addAll (pharmList );
  953       }
  954  
  955       privat e Person p arsePerson (PRPAMT201 310UV02Con tactParty  contactPar ty) {
  956           Pe rson perso n = new Pe rson();
  957           if  (contactP arty.getTe lecom() !=  null) {
  958                for (TEL  tel : con tactParty. getTelecom ()) {
  959                    if ( (tel.getUs e() == nul l)
  960   //                          || ( tel.getUse ().size()  > 1) //?
  961                             || (te l.getValue ().contain s("mailto" ))
  962                             || (te l.getValue ().contain s("@"))) {
  963                         continue;
  964                    }
  965                    Stri ng telStr= "";
  966                    for  (int i = 0 ; i < tel. getUse().s ize(); i++ ) {
  967                         String use  = tel.get Use().get( i);
  968                         if (i>0)
  969                             telStr  = telStr. concat(",  ");
  970                         telStr = t elStr.conc at(parsePh oneNumber( tel.getVal ue()));
  971                    }
  972  
  973                    Tele com teleco m = new Te lecom();
  974                    tele com.setVal ue(telStr) ;
  975                    pers on.getTelc oms().add( telecom);
  976                }
  977           }
  978  
  979           //  Name
  980           if  (contactP arty.getCo ntactPerso n().getVal ue().getNa me() != nu ll) {
  981                for (EN  en : conta ctParty.ge tContactPe rson().get Value().ge tName() )  {
  982                    if ( en.getUse( ) == null)  { continu e; }
  983                    for  (String us e : en.get Use()) {
  984                         if ("L".eq ualsIgnore Case(use))  {  //? PD WS_Ext_Ser v_Desc_R17 .docx p86
  985                             person .setName(p arseName(e n));
  986                         }
  987                    }
  988                }
  989           }
  990  
  991           Pa tientDemog raphics te mpDemograp hics = new  PatientDe mographics ();
  992           pa rseAddress ContactPar ty(contact Party, tem pDemograph ics);
  993  
  994           if (tempDemog raphics.ge tAddress()  != null & & tempDemo graphics.g etAddress( ).size() >  0) {
  995                Address  address =  new Addres s();
  996                address. setStreet1 (tempDemog raphics.ge tAddress() .get(0).ge tStreet1() );
  997                address. setStreet2 (tempDemog raphics.ge tAddress() .get(0).ge tStreet2() );
  998                address. setCity(te mpDemograp hics.getAd dress().ge t(0).getCi ty());
  999                address. setStatePr ovince(tem pDemograph ics.getAdd ress().get (0).getSta teProvince ());
  1000                address. setPostalC ode(tempDe mographics .getAddres s().get(0) .getPostal Code());
  1001  
  1002                person.g etAddress( ).add(addr ess);
  1003           }
  1004  
  1005           if  (contactP arty.getCo de()!=null  && contac tParty.get Code().get DisplayNam e()!=null)
  1006                person.s etRelation ship(conta ctParty.ge tCode().ge tDisplayNa me());
  1007  
  1008           re turn perso n;
  1009       }
  1010  
  1011  
  1012       privat e void par seAddressC ontactPart y(PRPAMT20 1310UV02Co ntactParty  person, P atientDemo graphics p atientDemo graphics)  {
  1013           Li st<String>  streetAdd ressList =  new Array List<Strin g>();
  1014           Li st<Seriali zable> ser ializableL ist;
  1015           Ob ject objec t;
  1016           Bo olean isBa dAddress;
  1017           Bo olean isHo mePrimary;
  1018           Bo olean isTe mpAddress;
  1019  
  1020           //  Check for  home prim ary addres s and bad  address
  1021           fo r (AD ad :  person.ge tAddr()) {
  1022                isBadAdd ress = fal se;
  1023                isHomePr imary = fa lse;
  1024                isTempAd dress = fa lse;
  1025  
  1026                if (ad.g etUse() ==  null) { c ontinue; }
  1027  
  1028                for (Str ing use :  ad.getUse( )) {
  1029                    if ( use.contai ns("H")) {   //? PDWS _Ext_Serv_ Desc_R17.d ocx p84
  1030                         isHomePrim ary = true ;
  1031                    } el se if (use .contains( "BAD")) {
  1032                         isBadAddre ss = true;
  1033                    } el se if (use .contains( "TMP")) {
  1034                         isTempAddr ess = true ;
  1035                    }
  1036                }
  1037  
  1038                // If no t home pri mary addre ss or addr ess is bad  or addres s content  is null, t hen skip t o next
  1039                if ((!is HomePrimar y && !isTe mpAddress)  || isBadA ddress ||  (ad.getCon tent() ==  null)) { c ontinue; }
  1040  
  1041                streetAd dressList. clear();
  1042  
  1043                Address  address =  new Addres s();
  1044  
  1045                for (Ser ializable  serializab le : ad.ge tContent() ) {
  1046                    if ( serializab le instanc eof JAXBEl ement) {
  1047                         object = ( (JAXBEleme nt) serial izable).ge tValue();
  1048                         if (object  == null)  { continue ; }
  1049  
  1050                         // Street  address
  1051                         if (object  instanceo f AdxpStre etAddressL ine) {
  1052                             serial izableList  = ((AdxpS treetAddre ssLine) ob ject).getC ontent();
  1053                             if ((s erializabl eList != n ull) && !s erializabl eList.isEm pty()) {
  1054                                 st reetAddres sList.add( serializab leList.get (0).toStri ng());
  1055                             }
  1056                         } else if  (object in stanceof A dxpCity) {                       // City
  1057                             serial izableList  = ((AdxpC ity) objec t).getCont ent();
  1058                             if ((s erializabl eList != n ull) && !s erializabl eList.isEm pty()) {
  1059                                 ad dress.setC ity(serial izableList .get(0).to String());
  1060                             }
  1061                         } else if  (object in stanceof A dxpState)  {                      // State
  1062                             serial izableList  = ((AdxpS tate) obje ct).getCon tent();
  1063                             if ((s erializabl eList != n ull) && !s erializabl eList.isEm pty()) {
  1064                                 ad dress.setS tateProvin ce(seriali zableList. get(0).toS tring());
  1065                             }
  1066                         }
  1067                         // Zip cod e
  1068                         if (object  instanceo f AdxpPost alCode) {
  1069                             serial izableList  = ((AdxpP ostalCode)  object).g etContent( );
  1070                             if ((s erializabl eList != n ull) && !s erializabl eList.isEm pty()) {
  1071                                 ad dress.setP ostalCode( serializab leList.get (0).toStri ng());
  1072                             }
  1073                         }
  1074                    }
  1075                }
  1076  
  1077                // Set s treet addr ess from l ist
  1078                if (!str eetAddress List.isEmp ty()) {
  1079                    addr ess.setStr eet1(stree tAddressLi st.get(0)) ;
  1080  
  1081                    if ( streetAddr essList.si ze() > 1)  {
  1082                         address.se tStreet2(s treetAddre ssList.get (1));
  1083                    }
  1084                }
  1085                patientD emographic s.getAddre ss().add(a ddress);
  1086           }
  1087       }
  1088  
  1089       privat e void par sePrimaryC areManager (PRPAMT201 310UV02Pat ient patie nt, Patien tDemograph ics patien tDemograph ics) {
  1090           if  (patient. getCovered PartyOf()  == null) {  return; }
  1091  
  1092           CO CTMT510000 UV06Covera geRecord c overageRec ord;
  1093           CO CTMT510000 UV06Policy OrProgram  policyOrPr ogram;
  1094           CO CTMT510000 UV06Benefi t benefit;
  1095           CO CTMT530000 UVObservat ion observ ation;
  1096           CO CTMT090000 UV01Assign edEntity a ssignedEnt ity;
  1097           CO CTMT090000 UV01Person  person;
  1098           IV LTS ivlts;
  1099           IV XBTS ivxbt s;
  1100  
  1101           fo r (PRPAMT2 01310UV02C overedPart y coveredP arty : pat ient.getCo veredParty Of()) {
  1102                coverage Record = c overedPart y.getCover ageRecord( );
  1103                if (cove rageRecord  == null)  { continue ; }
  1104  
  1105                if (cove rageRecord .getCompon ent() == n ull) { con tinue; }
  1106  
  1107                for (COC TMT510000U V06Compone nt compone nt : cover ageRecord. getCompone nt()) {
  1108                    if ( component. getPolicyO rProgram()  == null)  { continue ; }
  1109  
  1110                    poli cyOrProgra m = compon ent.getPol icyOrProgr am();
  1111                    for  (COCTMT510 000UV06Cov erage2 cov erage2 : p olicyOrPro gram.getCo verageOf() ) {
  1112                         if (covera ge2.getBen efit() ==  null) { co ntinue; }
  1113  
  1114                         benefit =  coverage2. getBenefit ();
  1115                         for (COCTM T510000UV0 6Definitio n definiti on : benef it.getDefi nition())  {
  1116                             if (de finition.g etObservat ion() == n ull) { con tinue; }
  1117  
  1118                             observ ation = de finition.g etObservat ion().getV alue();
  1119                             if (ob servation  == null) {  continue;  }
  1120  
  1121                             if (ob servation. getPerform er() == nu ll) { cont inue; }
  1122                             for (C OCTMT53000 0UVPerform er perform er : obser vation.get Performer( )) {
  1123                                 if  (performe r.getAssig nedEntity( ) == null)  { continu e; }
  1124  
  1125                                 as signedEnti ty = perfo rmer.getAs signedEnti ty().getVa lue();
  1126                                 if  (assigned Entity ==  null) { co ntinue; }
  1127  
  1128                                 if (patientDe mographics .getPrimar yProvider( ) == null) {
  1129                                      patientD emographic s.setPrima ryProvider ("");
  1130                                 }
  1131                                 // patientDem ographics. setPcmDate s(null);
  1132                                 if (patientDe mographics .getPcmCli nic() == n ull){
  1133                                      patientD emographic s.setPcmCl inic("");
  1134                                 }
  1135  
  1136                                 //  PCM name
  1137                                 if  (assigned Entity.get AssignedPe rson() !=  null) {
  1138                                      person =  assignedE ntity.getA ssignedPer son().getV alue();
  1139                                      if ((per son != nul l) && (per son.getNam e() != nul l)) {
  1140                                          for  (EN en : p erson.getN ame()) {
  1141                                               if (en.get Content()  == null) {  continue;  }
  1142                                               for (Seria lizable co ntent : en .getConten t()) {
  1143                                                   patien tDemograph ics.setPri maryProvid er(content .toString( ));
  1144                                               }
  1145                                          }
  1146                                      }
  1147                                 }
  1148  
  1149                                 //  PCM date
  1150                                 if  (assigned Entity.get EffectiveT ime() != n ull) {
  1151                                      ivlts =  assignedEn tity.getEf fectiveTim e();
  1152                                      if (ivlt s.getRest( ) != null)  {
  1153                                          for  (JAXBEleme nt element  : ivlts.g etRest())  {
  1154                                               if (!"low" .equalsIgn oreCase(el ement.getN ame().getL ocalPart() )) { conti nue; }
  1155  
  1156                                               ivxbts = ( IVXBTS) el ement.getV alue();
  1157                                               if (ivxbts  == null)  { continue ; }
  1158  
  1159                                               // YYYYMMD D format ( 8 characte rs)
  1160                                               if (ivxbts .getValue( ).length()  != 8) { c ontinue; }
  1161                                               patientDem ographics. setPcmDate s(Utils.to XMLGregori anCalendar (ivxbts.ge tValue())) ;
  1162                                          }
  1163                                      }
  1164                                 }
  1165  
  1166                                 //  PCM clini c
  1167                                 //  Note: Cur rently PDW S does not  return th e PCM clin ic. Set to  empty str ing until
  1168                                 //  PDWS retu rns the cl inic name.
  1169                             }
  1170                         }
  1171                    }
  1172                }
  1173           }
  1174       }
  1175  
  1176       privat e String p arseName(E N en) {
  1177           St ringBuilde r familyNa me = new S tringBuild er();
  1178           St ringBuilde r givenNam e = new St ringBuilde r();
  1179           St ringBuilde r prefixNa me = new S tringBuild er();
  1180           St ringBuilde r suffixNa me = new S tringBuild er();
  1181           Li st<Seriali zable> ser ializableL ist1;
  1182           Li st<Seriali zable> ser ializableL ist2;
  1183           St ring rtc;
  1184           Ob ject objec t;
  1185  
  1186           se rializable List1 = en .getConten t();
  1187           if  (serializ ableList1  == null) {
  1188                rtc = nu ll;
  1189           }  else {
  1190       
  1191                for (Ser ializable  serializab le1 : seri alizableLi st1) {
  1192                    if ( !(serializ able1 inst anceof JAX BElement))  { continu e; }
  1193       
  1194                    obje ct = ((JAX BElement)  serializab le1).getVa lue();
  1195                    if ( object ==  null) { co ntinue; }
  1196       
  1197                    if ( object ins tanceof En Family) {
  1198                         serializab leList2 =  ((EnFamily ) object). getContent ();
  1199                         if (serial izableList 2 == null)  { continu e; }
  1200       
  1201                         for (Seria lizable se rializable 2 : serial izableList 2) {
  1202                             family Name.appen d(serializ able2.toSt ring());
  1203                             family Name.appen d(" ");
  1204                         }
  1205                    } el se if (obj ect instan ceof EnGiv en) {
  1206                         serializab leList2 =  ((EnGiven)  object).g etContent( );
  1207                         if (serial izableList 2 == null)  { continu e; }
  1208       
  1209                         for (Seria lizable se rializable 2 : serial izableList 2) {
  1210                             givenN ame.append (serializa ble2.toStr ing());
  1211                             givenN ame.append (" ");
  1212                         }
  1213                    } el se if (obj ect instan ceof EnPre fix) {
  1214                         serializab leList2 =  ((EnPrefix ) object). getContent ();
  1215                         if (serial izableList 2 == null)  { continu e; }
  1216       
  1217                         for (Seria lizable se rializable 2 : serial izableList 2) {
  1218                             prefix Name.appen d(serializ able2.toSt ring());
  1219                             prefix Name.appen d(" ");
  1220                         }
  1221                    } el se if (obj ect instan ceof EnSuf fix) {
  1222                         serializab leList2 =  ((EnSuffix ) object). getContent ();
  1223                         if (serial izableList 2 == null)  { continu e; }
  1224       
  1225                         for (Seria lizable se rializable 2 : serial izableList 2) {
  1226                             suffix Name.appen d(serializ able2.toSt ring());
  1227                             suffix Name.appen d(" ");
  1228                         }
  1229                    }
  1230                }
  1231       
  1232                // add p refix befo re given n ame
  1233                if (pref ixName.len gth() > 0)  {
  1234                    give nName = pr efixName.a ppend(give nName);
  1235                }
  1236       
  1237   //             // add  suffix af ter family  name
  1238   //             if (su ffixName.l ength() >  0) {
  1239   //                 fa milyName.a ppend(suff ixName);
  1240   //             }
  1241  
  1242                // add s uffix afte r given na me
  1243                if (suff ixName.len gth() > 0)  {
  1244                    give nName = gi venName.ap pend(suffi xName);
  1245                }
  1246       
  1247                rtc = fa milyName.t oString(). trim() + " ," + given Name.toStr ing().trim ();
  1248           }
  1249           re turn rtc;
  1250       }
  1251  
  1252       privat e String p arsePhoneN umber(Stri ng telecom ) {
  1253           St ringBuilde r phoneNum ber = new  StringBuil der();
  1254           St ringTokeni zer tokeni zer = new  StringToke nizer(tele com, " ");
  1255           St ring token ;
  1256           ch ar code;
  1257  
  1258           wh ile (token izer.hasMo reTokens() ) {
  1259                token =  tokenizer. nextToken( );
  1260                code = t oken.toLow erCase(Loc ale.getDef ault()).ch arAt(0);
  1261                // Do no t accept t okens that  begin wit h (p)riori ty, (y)es  text, (n)o  text
  1262                if ((cod e != 'p')  && (code ! = 'y') &&  (code != ' n')) {
  1263                    phon eNumber.ap pend(token );
  1264                    phon eNumber.ap pend(" ");
  1265                }
  1266           }
  1267  
  1268           re turn phone Number.toS tring().tr im();
  1269       }
  1270  
  1271       privat e List<Per son> parse Sponsors(P RPAMT20131 0UV02Perso n person)  {
  1272           Li st<Person>  sponsorLi st = new A rrayList<P erson>();
  1273  
  1274           if  (person.g etPersonal Relationsh ip() != nu ll) {
  1275                COCTMT03 0007UVPers on person1 ;
  1276  
  1277                for (PRP AMT201310U V02Persona lRelations hip person alRelation ship : per son.getPer sonalRelat ionship())  {
  1278                    Pers on sponsor  = new Per son();
  1279                    if ( personalRe lationship .getRelati onshipHold er1() == n ull) { con tinue; }
  1280  
  1281                    pers on1 = pers onalRelati onship.get Relationsh ipHolder1( ).getValue ();
  1282                    if ( person1 ==  null) { c ontinue; }
  1283  
  1284                    // N ame
  1285                    if ( person1.ge tName() !=  null) {
  1286                         for (EN en  : person1 .getName() ) {
  1287                             if (en .getUse()  == null) {  continue;  }
  1288                             for (S tring use  : en.getUs e()) {
  1289                                 if  ("L".equa lsIgnoreCa se(use)) {
  1290                                      sponsor. setName(pa rseName(en ));
  1291                                 }
  1292                             }
  1293                         }
  1294                    }
  1295  
  1296                    // R elation
  1297                    if ( personalRe lationship .getCode()  != null)  {
  1298                         sponsor.se tRelations hip(person alRelation ship.getCo de().getDi splayName( ));
  1299                    }
  1300  
  1301                    // S SN
  1302                    if ( person1.ge tAsOtherID s() != nul l) {
  1303                         for (COCTM T030007UVO therIDs ot herIDs : p erson1.get AsOtherIDs ()) {
  1304                             if (ot herIDs.get Id() == nu ll) { cont inue; }
  1305                             for (I I ii : oth erIDs.getI d()) {
  1306                                 if  ("2.16.84 0.1.113883 .4.1".equa lsIgnoreCa se(ii.getR oot())) {
  1307                                      sponsor. setIdentif ier(ii.get Extension( ));
  1308                                 }
  1309                             }
  1310                         }
  1311                    }
  1312  
  1313                    spon sorList.ad d(sponsor) ;
  1314                }
  1315           }
  1316  
  1317           re turn spons orList;
  1318       }
  1319  
  1320       privat e List<Pat ient> pars ePersonalR elationshi p(PRPAMT20 1310UV02Pe rson perso n) {
  1321           Li st<Patient > patientL ist = new  ArrayList< Patient>() ;
  1322  
  1323           if  (person.g etPersonal Relationsh ip() != nu ll) {
  1324                COCTMT03 0007UVPers on person1 ;
  1325                Patient  patient;
  1326  
  1327                for (PRP AMT201310U V02Persona lRelations hip person alRelation ship : per son.getPer sonalRelat ionship())  {
  1328                    if ( personalRe lationship .getRelati onshipHold er1() == n ull) { con tinue; }
  1329  
  1330                    pers on1 = pers onalRelati onship.get Relationsh ipHolder1( ).getValue ();
  1331                    if ( person1 ==  null) { c ontinue; }
  1332  
  1333                    pati ent = new  Patient();
  1334  
  1335                    // E DIPI
  1336                    if ( person1.ge tId() != n ull) {
  1337                         for (II ii  : person1 .getId())  {
  1338                             if ("2 .16.840.1. 113883.3.4 2.10001.10 0001.12".e qualsIgnor eCase(ii.g etRoot()))  {
  1339                                 pa tient.setE DIPI(ii.ge tExtension ());
  1340                             }
  1341                         }
  1342                    }
  1343  
  1344                    // N ame
  1345                    if ( person1.ge tName() !=  null) {
  1346                         for (EN en  : person1 .getName() ) {
  1347                             if (en .getUse()  == null) {  continue;  }
  1348                             for (S tring use  : en.getUs e()) {
  1349                                 if  ("L".equa lsIgnoreCa se(use)) {
  1350                                      patient. setName(pa rseName(en ));
  1351                                 }
  1352                             }
  1353                         }
  1354                    }
  1355  
  1356                    // G ender
  1357                    if ( person1.ge tAdministr ativeGende rCode() !=  null) {
  1358                         patient.se tGender(pe rson1.getA dministrat iveGenderC ode().getC ode());
  1359                    }
  1360  
  1361                    // D ate of bir th
  1362                    if ( person1.ge tBirthTime () != null ) {
  1363                         patient.se tDob(perso n1.getBirt hTime().ge tValue());
  1364                    }
  1365  
  1366                    // S SN
  1367                    if ( person1.ge tAsOtherID s() != nul l) {
  1368                         for (COCTM T030007UVO therIDs ot herIDs : p erson1.get AsOtherIDs ()) {
  1369                             if (ot herIDs.get Id() == nu ll) { cont inue; }
  1370                             for (I I ii : oth erIDs.getI d()) {
  1371                                 if  ("2.16.84 0.1.113883 .4.1".equa lsIgnoreCa se(ii.getR oot())) {
  1372                                      patient. setSSN(ii. getExtensi on());
  1373                                 }
  1374                             }
  1375                         }
  1376                    }
  1377  
  1378                    pati entList.ad d(patient) ;
  1379                }
  1380           }
  1381  
  1382           re turn patie ntList;
  1383       }
  1384  
  1385       public  ResponseP atientQuer y lookupPa tient(PDWS QueryBean  queryBean)  throws JM eadowsExce ption {
  1386           PR PAIN201305 UV02 reque st = gener ateRequest (queryBean );
  1387           PR PAIN201306 UV02 respo nse;
  1388           Re sponsePati entQuery r tc = null;
  1389  
  1390           St ring inqui ryType = q ueryBean.g etInquiryT ype();
  1391           if  ("PS".equ alsIgnoreC ase(inquir yType)) {
  1392                // Perso n Search
  1393                response  = getEnti tyPatientS earchPort( ).entityPa tientSearc h(request) ;
  1394           }  else if (" PR".equals IgnoreCase (inquiryTy pe)) {
  1395                // Patie nt Retriev e
  1396                response  = getEnti tyPatientR etrievePor t().entity PatientRet rieve(requ est);
  1397           }  else if (" FS".equals IgnoreCase (inquiryTy pe)) {
  1398                // Famil y Search
  1399                response  = getEnti tyFamilySe archPort() .entityPat ientFamily Search(req uest);
  1400           }  else if (" FR".equals IgnoreCase (inquiryTy pe)) {
  1401                // Famil y Retrieve
  1402                response  = getEnti tyFamilyRe trievePort ().entityP atientFami lyRetrieve (request);
  1403           }  else {
  1404                // Inval id Inquiry Type
  1405                throw ne w JMeadows Exception( "Invalid I nquiryType :" + inqui ryType);
  1406           }
  1407  
  1408           if  (response  != null)  {
  1409                rtc = pa rseRespons e(response , inquiryT ype);
  1410                if (rtc  != null &&  !rtc.getP atients(). isEmpty())  {
  1411                    bool ean found  = true;
  1412                    whil e (found)  {
  1413                         found = fa lse;
  1414                         List<Patie nt> patien ts = rtc.g etPatients ();
  1415                         Patient bl acklisted  = null;
  1416                         for (Patie nt patient  : patient s) {
  1417                             if (PD WSBlackLis t.getInsta nce().isBl ackListed( patient.ge tEDIPI()))  {
  1418                                 fo und = true ;
  1419                                 bl acklisted  = patient;
  1420                                 br eak;
  1421                             }
  1422                         }
  1423                         if (blackl isted != n ull) {
  1424                             LOGGER .error("re moving bla cklisted p atient");
  1425                             patien ts.remove( blackliste d);
  1426                             rtc.se tPatients( patients);
  1427                         }
  1428                    }
  1429                }
  1430           }
  1431           re turn rtc;
  1432       }
  1433   }