Produced by Araxis Merge on 9/15/2018 10:48:58 PM Eastern 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.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | MHV_2018.4.0.0.zip\2018.4.0.0\national portal\mhv_source\mhv_user\mhv-usermgmt-portal-main\src\main\java\gov\va\med\mhv\usermgmt\main\service\adapter\impl | LookupPatientAdapterWithMiddleName.java | Thu Aug 23 20:55:30 2018 UTC |
| 2 | MHV_2018.4.0.0.zip\2018.4.0.0\national portal\mhv_source\mhv_user\mhv-usermgmt-portal-main\src\main\java\gov\va\med\mhv\usermgmt\main\service\adapter\impl | LookupPatientAdapterWithMiddleName.java | Sat Sep 15 22:55:24 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 644 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| 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 |
No regular expressions were active.
| 1 | package go v.va.med.m hv.usermgm t.main.ser vice.adapt er.impl; | |
| 2 | ||
| 3 | import jav a.io.IOExc eption; | |
| 4 | import jav a.io.Input Stream; | |
| 5 | import jav a.io.Input StreamRead er; | |
| 6 | import jav a.io.Outpu tStream; | |
| 7 | import jav a.net.Sock et; | |
| 8 | import jav a.net.Unkn ownHostExc eption; | |
| 9 | import jav a.util.Dat e; | |
| 10 | ||
| 11 | import org .apache.co mmons.lang 3.StringUt ils; | |
| 12 | import org .apache.co mmons.logg ing.Log; | |
| 13 | import org .apache.co mmons.logg ing.LogFac tory; | |
| 14 | import org .springfra mework.bea ns.factory .annotatio n.Autowire d; | |
| 15 | import org .springfra mework.ste reotype.Co mponent; | |
| 16 | ||
| 17 | import ca. uhn.hl7v2. HL7Excepti on; | |
| 18 | import ca. uhn.hl7v2. llp.LLPExc eption; | |
| 19 | import gov .va.med.mh v.common.d ata.model. Patient; | |
| 20 | import gov .va.med.mh v.usermgmt .main.serv ice.adapte r.LookupPa tientAdapt erWithMidd leNameServ ice; | |
| 21 | ||
| 22 | /** | |
| 23 | * Respons ible for a ccessing p atients fr om legacy Master Pat ient Index system. | |
| 24 | * New cla ss (Lookup PatientAda pterWithMi ddleName) has been c reated so that the | |
| 25 | * existin g class (L ookupPatie ntAdapter) is not ap proved to be touched | |
| 26 | * | |
| 27 | * @author DNS | |
| 28 | */ | |
| 29 | @Component | |
| 30 | public cla ss LookupP atientAdap terWithMid dleName im plements L ookupPatie ntAdapterW ithMiddleN ameService { | |
| 31 | ||
| 32 | pr ivate stat ic final L og LOG = L ogFactory. getLog(Loo kupPatient AdapterWit hMiddleNam e.class); | |
| 33 | ||
| 34 | pr ivate stat ic final S tring CRLF = "\r\n"; | |
| 35 | ||
| 36 | pr ivate stat ic final S tring CR = "\r"; | |
| 37 | ||
| 38 | pr ivate stat ic final S tring DATA _TERMINATO R = "\u001 B\u001B\u0 01B"; | |
| 39 | ||
| 40 | pr ivate stat ic final S tring DATA _BEGIN_MAR KER = "220 OK\r\nDAT A PARAM=MP I\r\n"; | |
| 41 | ||
| 42 | pr ivate stat ic final S tring HELL O = "HELO" ; | |
| 43 | ||
| 44 | pr ivate stat ic final S tring READ Y = "Ready for"; | |
| 45 | ||
| 46 | pr ivate stat ic final S tring SUCC ESS = "200 OK"; | |
| 47 | ||
| 48 | pr ivate stat ic final S tring DATA _PARAM = " DATA PARAM =MPI"; | |
| 49 | ||
| 50 | pr ivate stat ic final S tring QUIT = "QUIT"; | |
| 51 | ||
| 52 | pr ivate stat ic final S tring TURN = "TURN"; | |
| 53 | ||
| 54 | pr ivate stat ic final S tring ZERO = "0"; | |
| 55 | ||
| 56 | pr ivate stat ic final i nt PREFIX_ LENGTH = 3 ; | |
| 57 | ||
| 58 | pr ivate stat ic final c har CR_CHA R = '\r'; | |
| 59 | ||
| 60 | pr ivate Stri ng host; | |
| 61 | ||
| 62 | pr ivate int port; | |
| 63 | ||
| 64 | pr ivate int timeout; | |
| 65 | ||
| 66 | pr ivate Stri ng request ; | |
| 67 | ||
| 68 | pr ivate Stri ng respons e; | |
| 69 | ||
| 70 | pr ivate Sock et socket = null; | |
| 71 | ||
| 72 | pr ivate Stri ng firstNa me; | |
| 73 | ||
| 74 | pr ivate Stri ng lastNam e; | |
| 75 | ||
| 76 | pr ivate Stri ng middleN ame; | |
| 77 | ||
| 78 | pr ivate Stri ng gender; | |
| 79 | ||
| 80 | pr ivate Date birthDate ; | |
| 81 | ||
| 82 | pr ivate Stri ng ssn; | |
| 83 | ||
| 84 | pr ivate Long userId; | |
| 85 | ||
| 86 | @A utowired | |
| 87 | pr ivate MpiP roperties mpiPropert ies; | |
| 88 | ||
| 89 | pu blic Looku pPatientAd apterWithM iddleName( ) { | |
| 90 | ||
| 91 | } | |
| 92 | ||
| 93 | pu blic Looku pPatientAd apterWithM iddleName( String fir stName, St ring lastN ame, Strin g middleNa me, String gender, D ate birthD ate, Strin g ssn, Lon g userId) { | |
| 94 | if ( LOG.isDebu gEnabled() ) { | |
| 95 | LOG.de bug("Const ructor(fir stName:" + firstName + "; last Name:" + l astName + " middle n ame: " + m iddleName + "; birth Date=" + b irthDate + | |
| 96 | " gender : " + gend er + ")"); | |
| 97 | } | |
| 98 | this .firstName = firstNa me; | |
| 99 | this .lastName = lastName ; | |
| 100 | this .middleNam e = middle Name; | |
| 101 | this .gender = gender; | |
| 102 | this .birthDate = birthDa te; | |
| 103 | this .ssn = ssn ; | |
| 104 | this .userId = userId; | |
| 105 | } | |
| 106 | ||
| 107 | pu blic Patie nt lookupP atient() | |
| 108 | thro ws Adapter Exception, Duplicate PatientExc eption { | |
| 109 | ||
| 110 | Pati ent patien t = null; | |
| 111 | ||
| 112 | try { | |
| 113 | connec t(); | |
| 114 | ||
| 115 | reques t = HELLO + CRLF; | |
| 116 | Output Stream req uestStream = socket. getOutputS tream(); | |
| 117 | send(r equest, re questStrea m); | |
| 118 | ||
| 119 | InputS tream resp onseStream = socket. getInputSt ream(); | |
| 120 | respon se = recei ve(respons eStream, C RLF); | |
| 121 | ||
| 122 | if (re sponse.ind exOf(READY ) != -1) { | |
| 123 | request = DATA_PAR AM + CRLF; | |
| 124 | send(req uest, requ estStream) ; | |
| 125 | ||
| 126 | request = new Look upPatientE ncoderWith MiddleName ().encode( firstName, lastName, middleNam e, gender, birthDate , ssn, use rId); | |
| 127 | ||
| 128 | request = formatOu tboundMess age(reques t); | |
| 129 | send(req uest, requ estStream) ; | |
| 130 | response = receive (responseS tream, CRL F); | |
| 131 | ||
| 132 | // MPI s tarts runn ing query right afte r receivin g DATAPARA M | |
| 133 | // block . | |
| 134 | // It re ads TURN c ommand aft er perform ing query when all r esults | |
| 135 | // are g athered. | |
| 136 | request = TURN + C RLF; | |
| 137 | send(req uest, requ estStream) ; | |
| 138 | response = receive (responseS tream, DAT A_TERMINAT OR); | |
| 139 | response = formatI nboundMess age(respon se); | |
| 140 | ||
| 141 | request = SUCCESS + CRLF; | |
| 142 | send(req uest, requ estStream) ; | |
| 143 | ||
| 144 | request = QUIT + C RLF; | |
| 145 | send(req uest, requ estStream) ; | |
| 146 | ||
| 147 | patient = new Look upPatientD ecoderWith MiddleName (firstName , lastName , middleNa me, gender , birthDat e, ssn).de code(respo nse); | |
| 148 | } else { | |
| 149 | request = QUIT + C RLF; | |
| 150 | send(req uest, requ estStream) ; | |
| 151 | } | |
| 152 | } ca tch (Unkno wnHostExce ption uhe) { | |
| 153 | throw new Adapte rException (host, por t, timeout ); | |
| 154 | } ca tch (IOExc eption ioe ) { | |
| 155 | throw new Adapte rException (host, por t, timeout , request, response) ; | |
| 156 | } ca tch (LLPEx ception ll pe) { | |
| 157 | throw new Adapte rException (host, por t, timeout , request, response) ; | |
| 158 | } ca tch (HL7Ex ception hl 7e) { | |
| 159 | throw new Adapte rException (host, por t, timeout , request, response, hl7e.getM essage()); | |
| 160 | } fi nally { | |
| 161 | try { | |
| 162 | disconne ct(); | |
| 163 | } catc h (IOExcep tion e) { | |
| 164 | } | |
| 165 | } | |
| 166 | ||
| 167 | retu rn patient ; | |
| 168 | } | |
| 169 | ||
| 170 | pr ivate void send(Stri ng msg, Ou tputStream requestSt ream) | |
| 171 | thro ws IOExcep tion { | |
| 172 | if ( LOG.isDebu gEnabled() ) { | |
| 173 | LOG.de bug("Sendi ng [" + ms g + "]"); | |
| 174 | } | |
| 175 | requ estStream. write(msg. getBytes() ); | |
| 176 | requ estStream. flush(); | |
| 177 | } | |
| 178 | ||
| 179 | pr ivate Stri ng receive (InputStre am respons eStream, S tring term inator) | |
| 180 | thro ws IOExcep tion { | |
| 181 | Stri ngBuffer b uffer = ne w StringBu ffer(); | |
| 182 | Inpu tStreamRea der reader = new Inp utStreamRe ader(respo nseStream) ; | |
| 183 | int i = 0; | |
| 184 | char [] arr = n ew char[51 2]; | |
| 185 | whil e (i != -1 && buffer .indexOf(t erminator) < 0) { | |
| 186 | i = re ader.read( arr, 0, ar r.length); | |
| 187 | if (i > 0) { | |
| 188 | buffer.a ppend(arr, 0, i); | |
| 189 | } | |
| 190 | } | |
| 191 | ||
| 192 | Stri ng respons e = buffer .toString( ); | |
| 193 | if ( LOG.isDebu gEnabled() ) { | |
| 194 | LOG.de bug("Recei ved [" + r esponse + "]"); | |
| 195 | } | |
| 196 | retu rn respons e; | |
| 197 | } | |
| 198 | ||
| 199 | pr ivate Stri ng formatO utboundMes sage(Strin g msg) | |
| 200 | thro ws LLPExce ption { | |
| 201 | Stri ng[] resul ts = new S tring[4]; | |
| 202 | Stri ng[] parts = msg.spl it(CR); | |
| 203 | if ( parts.leng th != 3) { | |
| 204 | throw new LLPExc eption("Qu ery has to have exac tly 3 segm ents."); | |
| 205 | } | |
| 206 | for (int i = 0 ; i < part s.length; i++) { | |
| 207 | result s[i] = par ts[i]; | |
| 208 | } | |
| 209 | resu lts[3] = D ATA_TERMIN ATOR; | |
| 210 | Stri ngBuffer m essage = n ew StringB uffer(); | |
| 211 | for (int i = 0 ; i < resu lts.length ; i++) { | |
| 212 | String prefix = String.val ueOf(resul ts[i].leng th()); | |
| 213 | while (prefix.le ngth() < P REFIX_LENG TH) { | |
| 214 | prefix = ZERO + pr efix; | |
| 215 | } | |
| 216 | ||
| 217 | messag e.append(p refix).app end(result s[i]); | |
| 218 | } | |
| 219 | retu rn message .toString( ); | |
| 220 | } | |
| 221 | ||
| 222 | pr ivate Stri ng formatI nboundMess age(String msg) | |
| 223 | thro ws LLPExce ption { | |
| 224 | int count = 0; | |
| 225 | int marker = 0 ; | |
| 226 | Stri ngBuffer r esult = ne w StringBu ffer(); | |
| 227 | if ( !msg.start sWith(DATA _BEGIN_MAR KER)) { | |
| 228 | throw new LLPExc eption("MP I Data Beg in marker is not fou nd"); | |
| 229 | } | |
| 230 | msg = msg.subs tring(DATA _BEGIN_MAR KER.length ()); | |
| 231 | whil e (marker < msg.leng th()) { | |
| 232 | count = Integer. parseInt(m sg.substri ng(marker, marker + PREFIX_LEN GTH)); | |
| 233 | if (co unt > 0) { | |
| 234 | String s ubString = msg.subst ring(marke r + PREFIX _LENGTH, m arker + PR EFIX_LENGT H + count) ; | |
| 235 | if (!sub String.equ als(DATA_T ERMINATOR) ) { | |
| 236 | result.app end(subStr ing); | |
| 237 | } | |
| 238 | } else { | |
| 239 | if (resu lt.charAt( result.len gth() - 1) != CR_CHA R) { | |
| 240 | result.app end(CR); | |
| 241 | } | |
| 242 | } | |
| 243 | ||
| 244 | marker = marker + PREFIX_L ENGTH + co unt; | |
| 245 | } | |
| 246 | ||
| 247 | retu rn result. toString() ; | |
| 248 | } | |
| 249 | ||
| 250 | pr ivate void connect() | |
| 251 | thro ws Unknown HostExcept ion, IOExc eption { | |
| 252 | host = mpiProp erties.get Host(); | |
| 253 | port = mpiProp erties.get Port(); | |
| 254 | time out = mpiP roperties. getTimeout (); | |
| 255 | ||
| 256 | sock et = new S ocket(host , port); | |
| 257 | sock et.setSoTi meout(time out); | |
| 258 | } | |
| 259 | ||
| 260 | pr ivate void disconnec t() | |
| 261 | thro ws IOExcep tion { | |
| 262 | if ( socket != null && so cket.isCon nected()) { | |
| 263 | socket .close(); | |
| 264 | } | |
| 265 | } | |
| 266 | ||
| 267 | pu blic Strin g getFirst Name() { | |
| 268 | retu rn firstNa me; | |
| 269 | } | |
| 270 | ||
| 271 | pu blic void setFirstNa me(String firstName) { | |
| 272 | this .firstName = firstNa me; | |
| 273 | } | |
| 274 | ||
| 275 | pu blic Strin g getLastN ame() { | |
| 276 | retu rn lastNam e; | |
| 277 | } | |
| 278 | ||
| 279 | pu blic void setLastNam e(String l astName) { | |
| 280 | this .lastName = lastName ; | |
| 281 | } | |
| 282 | ||
| 283 | pu blic Strin g getMiddl eName() { | |
| 284 | retu rn middleN ame; | |
| 285 | } | |
| 286 | ||
| 287 | pu blic void setMiddleN ame(String middleNam e) { | |
| 288 | this .middleNam e = middle Name; | |
| 289 | } | |
| 290 | ||
| 291 | pu blic Strin g getGende r() { | |
| 292 | retu rn gender; | |
| 293 | } | |
| 294 | ||
| 295 | pu blic void setGender( String gen der) { | |
| 296 | this .gender = gender; | |
| 297 | } | |
| 298 | ||
| 299 | pu blic Date getBirthDa te() { | |
| 300 | retu rn birthDa te; | |
| 301 | } | |
| 302 | ||
| 303 | pu blic void setBirthDa te(Date bi rthDate) { | |
| 304 | this .birthDate = birthDa te; | |
| 305 | } | |
| 306 | ||
| 307 | pu blic Strin g getSsn() { | |
| 308 | retu rn ssn; | |
| 309 | } | |
| 310 | ||
| 311 | pu blic void setSsn(Str ing ssn) { | |
| 312 | this .ssn = ssn ; | |
| 313 | } | |
| 314 | ||
| 315 | pu blic Long getUserId( ) { | |
| 316 | retu rn userId; | |
| 317 | } | |
| 318 | ||
| 319 | pu blic void setUserId( Long userI d) { | |
| 320 | this .userId = userId; | |
| 321 | } | |
| 322 | ||
| 323 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.