Produced by Araxis Merge on 10/2/2017 7:00:08 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.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | cds.zip\cds\product\production\cdsinvocation\cds-invocation\src\test\java\com\cognitive\cds\invocation\fhir | FhirDataRetrieverTest.java | Wed Jul 12 18:43:52 2017 UTC |
| 2 | cds.zip\cds\product\production\cdsinvocation\cds-invocation\src\test\java\com\cognitive\cds\invocation\fhir | FhirDataRetrieverTest.java | Thu Sep 28 16:13:39 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 1214 |
| Changed | 2 | 4 |
| 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 | /* | |
| 2 | * COPYRIG HT STATUS: © 2015, 2 016. This work, aut hored by C ognitive M edical Sys tems | |
| 3 | * employe es, was fu nded in wh ole or in part by Th e Departme nt of Vete rans | |
| 4 | * Affairs under U.S . Governme nt contrac t VA118-11 -D-1011 / VA118-1011 -0013. | |
| 5 | * The cop yright hol der agrees to post o r allow th e Governme nt to post all or | |
| 6 | * part of this work in open-s ource repo sitories s ubject to the Apache License, | |
| 7 | * Version 2.0, date d January 2004. All other righ ts are res erved by t he | |
| 8 | * copyrig ht owner. | |
| 9 | * | |
| 10 | * For use outside t he Governm ent, the f ollowing n otice appl ies: | |
| 11 | * | |
| 12 | * Cop yright 201 5 © Cognit ive Medica l Systems | |
| 13 | * | |
| 14 | * Lic ensed unde r the Apac he License , Version 2.0 (the " License"); you may | |
| 15 | * not use this file excep t in compl iance with the Licen se. You ma y obtain | |
| 16 | * a c opy of the License a t http://w ww.apache. org/licens es/LICENSE -2.0 | |
| 17 | * | |
| 18 | * Unl ess requir ed by appl icable law or agreed to in wri ting, soft ware | |
| 19 | * dis tributed u nder the L icense is distribute d on an "A S IS" BASI S, | |
| 20 | * WIT HOUT WARRA NTIES OR C ONDITIONS OF ANY KIN D, either express or implied. | |
| 21 | * See the Licen se for the specific language g overning p ermissions and | |
| 22 | * lim itations u nder the L icense. | |
| 23 | * | |
| 24 | */ | |
| 25 | package co m.cognitiv e.cds.invo cation.fhi r; | |
| 26 | ||
| 27 | import sta tic org.ju nit.Assert .assertEqu als; | |
| 28 | import sta tic org.ju nit.Assert .assertTru e; | |
| 29 | import sta tic org.ju nit.Assert .fail; | |
| 30 | ||
| 31 | import jav a.io.Buffe redReader; | |
| 32 | import jav a.io.IOExc eption; | |
| 33 | import jav a.io.Input Stream; | |
| 34 | import jav a.io.Input StreamRead er; | |
| 35 | import jav a.io.Unsup portedEnco dingExcept ion; | |
| 36 | import jav a.net.Malf ormedURLEx ception; | |
| 37 | import jav a.nio.char set.Charse t; | |
| 38 | import jav a.util.Arr ayList; | |
| 39 | import jav a.util.Lis t; | |
| 40 | ||
| 41 | import jav ax.ws.rs.c ore.MediaT ype; | |
| 42 | import jav ax.ws.rs.c ore.Respon se; | |
| 43 | ||
| 44 | import org .apache.cx f.helpers. IOUtils; | |
| 45 | import org .apache.cx f.jaxrs.cl ient.WebCl ient; | |
| 46 | import org .junit.Aft er; | |
| 47 | import org .junit.Aft erClass; | |
| 48 | import org .junit.Bef ore; | |
| 49 | import org .junit.Bef oreClass; | |
| 50 | import org .junit.Ign ore; | |
| 51 | import org .junit.Tes t; | |
| 52 | import org .junit.run ner.RunWit h; | |
| 53 | import org .springfra mework.bea ns.factory .annotatio n.Autowire d; | |
| 54 | import org .springfra mework.bea ns.factory .annotatio n.Qualifie r; | |
| 55 | import org .springfra mework.tes t.context. ContextCon figuration ; | |
| 56 | import org .springfra mework.tes t.context. junit4.Spr ingJUnit4C lassRunner ; | |
| 57 | ||
| 58 | import com .cognitive .cds.invoc ation.util .FhirUtils ; | |
| 59 | ||
| 60 | import ca. uhn.fhir.c ontext.Fhi rContext; | |
| 61 | import ca. uhn.fhir.m odel.api.I Resource; | |
| 62 | import ca. uhn.fhir.m odel.base. resource.B aseOperati onOutcome. BaseIssue; | |
| 63 | import ca. uhn.fhir.m odel.dstu2 .resource. Bundle; | |
| 64 | import ca. uhn.fhir.m odel.dstu2 .resource. Bundle.Ent ry; | |
| 65 | import ca. uhn.fhir.m odel.dstu2 .resource. Observatio n; | |
| 66 | import ca. uhn.fhir.m odel.dstu2 .resource. Patient; | |
| 67 | import ca. uhn.fhir.m odel.dstu2 .valueset. BundleType Enum; | |
| 68 | import ca. uhn.fhir.m odel.primi tive.IdDt; | |
| 69 | import ca. uhn.fhir.p arser.IPar ser; | |
| 70 | import ca. uhn.fhir.p arser.XmlP arser; | |
| 71 | import ca. uhn.fhir.v alidation. FhirValida tor; | |
| 72 | import ca. uhn.fhir.v alidation. Validation Result; | |
| 73 | ||
| 74 | /** | |
| 75 | * | |
| 76 | * @author tnguyen | |
| 77 | */ | |
| 78 | @RunWith(S pringJUnit 4ClassRunn er.class) | |
| 79 | @ContextCo nfiguratio n(location s = { "cla sspath:fhi rcontext-t est.xml" } ) | |
| 80 | public cla ss FhirDat aRetriever Test { | |
| 81 | ||
| 82 | privat e static f inal org.s lf4j.Logge r log = or g.slf4j.Lo ggerFactor y.getLogge r(FhirData RetrieverT est.class) ; | |
| 83 | ||
| 84 | @Autow ired | |
| 85 | @Quali fier("retr ieveFhirDa ta") | |
| 86 | FhirDa taRetrieve r instance ; | |
| 87 | ||
| 88 | public FhirDataR etrieverTe st() { | |
| 89 | } | |
| 90 | ||
| 91 | @Befor eClass | |
| 92 | public static vo id setUpCl ass() { | |
| 93 | } | |
| 94 | ||
| 95 | @After Class | |
| 96 | public static vo id tearDow nClass() { | |
| 97 | } | |
| 98 | ||
| 99 | @Befor e | |
| 100 | public void setU p() { | |
| 101 | ||
| 102 | } | |
| 103 | ||
| 104 | @After | |
| 105 | public void tear Down() { | |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * Tes t parsing and valida ting a DST U2 bundle and DSTU2 simple dat a response | |
| 110 | * (pr ocessing a captured data from RDK run) | |
| 111 | * | |
| 112 | * USI NG TEST DA TA FILE: s ampleRDKFh ir-Patient _dstu2.jso n | |
| 113 | * sam pleRDKFhir -HealthFac tors.json now social -history | |
| 114 | * | |
| 115 | * @th rows IOExc eption | |
| 116 | */ | |
| 117 | @Ignor e("Develop ment Test only") | |
| 118 | @Test | |
| 119 | public void test HAPIParser _DSTU2() t hrows IOEx ception { | |
| 120 | ||
| 121 | lo g.trace("\ n\n======= ========== ====> TEST ING: testH APIParser_ DSTU2 <=== ========== ======== " ); | |
| 122 | ||
| 123 | St ring msg; | |
| 124 | Va lidationRe sult valid ationResul t; | |
| 125 | ||
| 126 | // --------- ---------- ------- | |
| 127 | // PARSE ent ry fom rep sonse | |
| 128 | // --------- ---------- ------- | |
| 129 | ||
| 130 | IP arser p = FhirUtils. newJsonPar ser(); | |
| 131 | ||
| 132 | // --------- ---------- ------- | |
| 133 | // Setup the schema fo r validati ng | |
| 134 | // --------- ---------- ------- | |
| 135 | Fh irValidato r val = Fh irUtils.ge tContext() .newValida tor(); | |
| 136 | va l.setValid ateAgainst StandardSc hema(true) ; | |
| 137 | va l.setValid ateAgainst StandardSc hematron(t rue); | |
| 138 | ||
| 139 | // --------- ---------- ---------- ------ | |
| 140 | // Parsing & Validatin g a Simple json: PAT IENT as si mple resou rce | |
| 141 | // --------- ---------- ---------- ------ | |
| 142 | ms g = IOUtil s.toString (XmlParser .class.get ResourceAs Stream("/s ampleRDKFh ir-Patient _dstu2.jso n")); | |
| 143 | Pa tient res = p.parseR esource(Pa tient.clas s, msg); | |
| 144 | ||
| 145 | lo g.trace("\ n......... .... PARSI NG SIMPLE. .......... .."); | |
| 146 | lo g.trace("N AME: " + res.getRes ourceName( )); | |
| 147 | lo g.trace("G ENDER: " + res.getG enderEleme nt().getVa lueAsStrin g()); | |
| 148 | ||
| 149 | va lidationRe sult = val .validateW ithResult( res); | |
| 150 | as sertTrue(" Validating sampleRDK Fhir-Patie nt_dstu2.j son", vali dationResu lt.isSucce ssful()); | |
| 151 | ||
| 152 | // now part of observa tion | |
| 153 | // --------- ---------- ---------- ------ | |
| 154 | // Parsing & Validatin g a Bundle json | |
| 155 | // --------- ---------- ---------- ------ | |
| 156 | ms g = IOUtil s.toString (XmlParser .class.get ResourceAs Stream("/s ampleRDKFh ir-HealthF actors.jso n")); | |
| 157 | Bu ndle bundl e = (Bundl e) p.parse Resource(m sg); | |
| 158 | va lidationRe sult = val .validateW ithResult( bundle); | |
| 159 | ||
| 160 | if (!validat ionResult. isSuccessf ul()) { | |
| 161 | log.erro r("\n----- ---------- ---------- ---------- --------\n "); | |
| 162 | for (Bas eIssue iss ue : valid ationResul t.getOpera tionOutcom e().getIss ue()) { | |
| 163 | log. error(issu e.getDetai lsElement( ).getValue AsString() ); | |
| 164 | } | |
| 165 | log.erro r("\n----- ---------- ---------- ---------- --------\n "); | |
| 166 | assertTr ue("sample RDKFhir-He althFactor s.json", v alidationR esult.isSu ccessful() ); | |
| 167 | } | |
| 168 | ||
| 169 | // GETTING f irst resou rce | |
| 170 | En try e = bu ndle.getEn try().get( 0); | |
| 171 | IR esource re source = e .getResour ce(); | |
| 172 | ||
| 173 | lo g.trace("\ n......... .... PARSI NG BUNDLE. .......... .."); | |
| 174 | lo g.trace("F IRST RESOU RCE NAME: " + resour ce.getReso urceName() ); | |
| 175 | lo g.trace(re source.get ResourceMe tadata().t oString()) ; | |
| 176 | ||
| 177 | as sertEquals (Observati on.class, resource.g etClass()) ; | |
| 178 | ||
| 179 | // DETERMINI NG WHICH R ESOURCETYP E the reso urce is | |
| 180 | if (resource .getClass( ).equals(P atient.cla ss)) { | |
| 181 | Patient pt = (Pati ent) resou rce; | |
| 182 | log.trac e("GENDER " + pt.get Gender()); | |
| 183 | log.trac e("MARITAL ms.text: " + pt.get MaritalSta tus().getT ext()); | |
| 184 | log.trac e("MARITAL ms.coding : " + pt.g etMaritalS tatus().ge tCoding()) ; | |
| 185 | log.trac e("MARITAL ms.coding .display: " + pt.get MaritalSta tus().getC odingFirst Rep().getD isplay()); | |
| 186 | } | |
| 187 | ||
| 188 | IR esource aC ontained = e.getReso urce().get Contained( ).getConta inedResour ces().get( 0); | |
| 189 | lo g.trace("C ONTAINED S IZE: " + e .getResour ce().getCo ntained(). getContain edResource s().size() ); | |
| 190 | lo g.trace("C ONTAINED R ESOURCENAM E: " + aCo ntained.ge tResourceN ame()); | |
| 191 | ||
| 192 | tr y { | |
| 193 | msg = IO Utils.toSt ring(XmlPa rser.class .getResour ceAsStream ("/sampleR DKFhir-Pat ient_dstu2 .json")); | |
| 194 | Patient b = p.pars eResource( Patient.cl ass, msg); | |
| 195 | } catch (ca. uhn.fhir.p arser.Data FormatExce ption ex) { | |
| 196 | fail("Ex ception pa rsing a pa tient: " + ex.getMes sage()); | |
| 197 | ||
| 198 | } | |
| 199 | ||
| 200 | tr y { | |
| 201 | msg = IO Utils.toSt ring(XmlPa rser.class .getResour ceAsStream ("/sampleR DKFhir-Pat ient_dstu2 _bundle.js on")); | |
| 202 | IResourc e i = p.pa rseResourc e(msg); | |
| 203 | if (!(i instanceof Bundle)) { | |
| 204 | fail ("Parsed r esource is not a bun dle, but r ather a " + i.getRes ourceName( )); | |
| 205 | } | |
| 206 | } catch (ca. uhn.fhir.p arser.Data FormatExce ption ex) { | |
| 207 | fail("Ex ception pa rsing a bu ndle: " + ex.getMess age()); | |
| 208 | } | |
| 209 | } | |
| 210 | ||
| 211 | /** | |
| 212 | * | |
| 213 | * Tes t parsing and valida ting a DST U2 bundle of multipl e resource s data | |
| 214 | * res ponse (pro cessing a captured d ata from R DK run) | |
| 215 | * | |
| 216 | * @th rows IOExc eption | |
| 217 | */ | |
| 218 | @Ignor e("Develop ment Test only") | |
| 219 | @Test | |
| 220 | public void test HAPIBundli ngOfMultip leResource s() throws IOExcepti on { | |
| 221 | ||
| 222 | lo g.trace("\ n\n======= ========== ====> TEST ING: testH APIBundlin gOfMultipl eResources <======== ====== "); | |
| 223 | ||
| 224 | St ring msg; | |
| 225 | Bu ndle bundl eout = new Bundle(); | |
| 226 | ||
| 227 | // --------- ---------- ------- | |
| 228 | // PREP HAPI CONTEXT A ND PARSER | |
| 229 | // --------- ---------- ------- | |
| 230 | Fh irContext hapiFhirCt x = new Fh irContext( ); | |
| 231 | ha piFhirCtx = FhirCont ext.forDst u2(); | |
| 232 | IP arser p = hapiFhirCt x.newJsonP arser(); | |
| 233 | ||
| 234 | // --------- ---------- ---------- ---- | |
| 235 | // READ IN S TATIC SIMP LE DATA fr om a sourc e and add to new bun dle | |
| 236 | // (bundleou t) | |
| 237 | // --------- ---------- ---------- ---- | |
| 238 | ms g = IOUtil s.toString (XmlParser .class.get ResourceAs Stream("/s ampleRDKFh ir-Patient _dstu2.jso n")); | |
| 239 | Pa tient res = p.parseR esource(Pa tient.clas s, msg); | |
| 240 | bu ndleout.ad dEntry().s etResource (res); | |
| 241 | ||
| 242 | // PRINT OUT NEW BUNDL E bundleou t | |
| 243 | St ring outst r = hapiFh irCtx.newJ sonParser( ).encodeRe sourceToSt ring(bundl eout); | |
| 244 | lo g.trace("N EW BUNDLE AFTER SIMP LE:\n" + o utstr); | |
| 245 | ||
| 246 | // --------- ---------- ---------- ---- | |
| 247 | // READ IN S TATIC BUND LE DATA fr om a sourc e | |
| 248 | // Tester: s ampleRDKFh ir-Patient AndPatient _dstu2_bun dle.json | |
| 249 | // (a bundle containin g two pati ents entri es) | |
| 250 | // --------- ---------- ---------- ---- | |
| 251 | ms g = IOUtil s.toString (XmlParser .class.get ResourceAs Stream("/s ampleRDKFh ir-Patient AndPatient _dstu2_bun dle.json") ); | |
| 252 | Bu ndle bundl e = (Bundl e) p.parse Resource(m sg); | |
| 253 | ||
| 254 | // --------- ---------- ---------- ---- | |
| 255 | // LOOP THRO UGH ALL EN TRIES | |
| 256 | // extract e ach RESOUR CE and add to new bu ndle. | |
| 257 | // --------- ---------- ---------- ---- | |
| 258 | Li st<Entry> entries = bundle.get Entry(); | |
| 259 | ||
| 260 | fo r (Entry e : entries ) { | |
| 261 | IResourc e resource = e.getRe source(); | |
| 262 | ||
| 263 | log.trac e("\n..... ........ P ARSING BUN DLE....... ......"); | |
| 264 | log.trac e("FIRST R ESOURCE NA ME: " + re source.get ResourceNa me()); | |
| 265 | log.trac e(resource .getResour ceMetadata ().toStrin g()); | |
| 266 | bundleou t.addEntry ().setReso urce(resou rce); | |
| 267 | ||
| 268 | log.trac e("ADDING: " + resou rce.getTex t().getDiv ().toStrin g()); | |
| 269 | } | |
| 270 | ||
| 271 | // PRINT OUT NEW BUNDL E bundleou t | |
| 272 | ou tstr = Fhi rUtils.new JsonParser ().encodeR esourceToS tring(bund leout); | |
| 273 | lo g.trace("N EW BUNDLE AFTER BUND LE(2):\n" + outstr); | |
| 274 | ||
| 275 | } | |
| 276 | ||
| 277 | /** | |
| 278 | * NOT E: DEVELOP MENT TESTI NG ONLY. | |
| 279 | */ | |
| 280 | @Ignor e("Develop ment Test only") | |
| 281 | @Test | |
| 282 | public void test MultiCalls OneSession () { | |
| 283 | ||
| 284 | lo g.trace("\ n\n======= ========== ====> TEST ING: testM ultiCallsO neSession <========= ========== == "); | |
| 285 | ||
| 286 | Re sponse res ponse; | |
| 287 | St ring endpo int; | |
| 288 | String bas eEP = "htt p:// IP /resource/ "; | |
| 289 | ||
| 290 | St ringBuilde r sb = new StringBui lder(); | |
| 291 | ||
| 292 | tr y { | |
| 293 | ||
| 294 | endpoint = baseEP; | |
| 295 | ||
| 296 | List<Obj ect> provi ders = new ArrayList <Object>() ; | |
| 297 | // provi ders.add(n ew | |
| 298 | // org.c odehaus.ja ckson.jaxr s.JacksonJ sonProvide r()); | |
| 299 | provider s.add(new com.faster xml.jackso n.jaxrs.js on.Jackson JsonProvid er()); | |
| 300 | ||
| 301 | // ===== ========== ========== ========== ========== ======= | |
| 302 | // AUTHE NTICATION EP | |
| 303 | // ===== ========== ========== ========== ========== ======= | |
| 304 | WebClien t client = WebClient .create(en dpoint, pr oviders).p ath("{type }/{domain} ", "auth", "authenti cation"); | |
| 305 | ||
| 306 | // MAINT AIN SESSIO N for mult i request using same session(c ookie) | |
| 307 | WebClien t.getConfi g(client). getRequest Context(). put(org.ap ache.cxf.m essage.Mes sage.MAINT AIN_SESSIO N, Boolean .TRUE); | |
| 308 | ||
| 309 | String bod y = "{" + "\"accessC ode\": \" REDACTED \"," + "\" verifyCode \":\" REDACTED \"," + "\" site\":\"9 E7A\"," + "\"divisio n\":\"500\ "" + "}"; | |
| 310 | ||
| 311 | response = client. accept(Med iaType.APP LICATION_J SON).type( MediaType. APPLICATIO N_JSON).po st(body); | |
| 312 | ||
| 313 | InputStr eam in = ( InputStrea m) respons e.getEntit y(); | |
| 314 | InputStr eamReader is = new I nputStream Reader(in) ; | |
| 315 | ||
| 316 | Buffered Reader br = new Buff eredReader (is); | |
| 317 | String r ead = br.r eadLine(); | |
| 318 | ||
| 319 | while (r ead != nul l) { | |
| 320 | sb.a ppend(read ); | |
| 321 | read = br.read Line(); | |
| 322 | } | |
| 323 | br.close (); | |
| 324 | ||
| 325 | log.trac e("\n===> sb size=" + sb.lengt h() + "\n" + sb.toSt ring()); | |
| 326 | ||
| 327 | // ===== ========== ========== ========== ========== ======= | |
| 328 | // GETTI NG DEMOG | |
| 329 | // ===== ========== ========== ========== ========== ======= | |
| 330 | client.r eset(); | |
| 331 | client.p ath("{type }/{domain} /{pid}", " fhir", "pa tient", "1 0107V39591 2"); | |
| 332 | response = client. accept("ap plication/ json").typ e("applica tion/json" ).get(); | |
| 333 | ||
| 334 | in = (In putStream) response. getEntity( ); | |
| 335 | is = new InputStre amReader(i n); | |
| 336 | ||
| 337 | sb = new StringBui lder(); | |
| 338 | br = new BufferedR eader(is); | |
| 339 | read = b r.readLine (); | |
| 340 | while (r ead != nul l) { | |
| 341 | sb.a ppend(read ); | |
| 342 | read = br.read Line(); | |
| 343 | } | |
| 344 | log.trac e("\n===> sb size=" + sb.lengt h() + "\n" + sb.toSt ring()); | |
| 345 | ||
| 346 | // ===== ========== ========== ========== ========== ======= | |
| 347 | // GETTI NG ALLERGY | |
| 348 | // ===== ========== ========== ========== ========== ======= | |
| 349 | client.r eset(); | |
| 350 | client.p ath("{type }/{domain} ", "fhir", "adverseR eaction"). query("sub ject.ident ifier", "1 0107V39591 2"); | |
| 351 | response = client. accept("ap plication/ json").typ e("applica tion/json" ).get(); | |
| 352 | ||
| 353 | in = (In putStream) response. getEntity( ); | |
| 354 | is = new InputStre amReader(i n); | |
| 355 | ||
| 356 | br = new BufferedR eader(is); | |
| 357 | read = b r.readLine (); | |
| 358 | ||
| 359 | // INSER T JSON STA RTING NODE | |
| 360 | String a tomhdr = " {\"atom\": ["; | |
| 361 | sb.inser t(0, atomh dr, 0, ato mhdr.lengt h()); | |
| 362 | ||
| 363 | sb.appen d(","); // ADDING co mma after last domai n .. in pr ep for | |
| 364 | // next doma in data se t | |
| 365 | ||
| 366 | // ADDIN G domain d ata to buf fer | |
| 367 | while (r ead != nul l) { | |
| 368 | sb.a ppend(read ); | |
| 369 | read = br.read Line(); | |
| 370 | } | |
| 371 | ||
| 372 | // ===== ========== ========== ========== ========== ======= | |
| 373 | // GETTI NG OBSERVA TION | |
| 374 | // ===== ========== ========== ========== ========== ======= | |
| 375 | client.r eset(); | |
| 376 | // clien t.back(tru e); | |
| 377 | client.p ath("{type }/{domain} ", "fhir", "observat ion").quer y("subject .identifie r", "10107 V395912"). query("pro file", "CD S"); | |
| 378 | response = client. accept("ap plication/ json").typ e("applica tion/json" ).get(); | |
| 379 | ||
| 380 | in = (In putStream) response. getEntity( ); | |
| 381 | is = new InputStre amReader(i n); | |
| 382 | ||
| 383 | br = new BufferedR eader(is); | |
| 384 | read = b r.readLine (); | |
| 385 | ||
| 386 | sb.appen d(","); // ADDING co mma after last domai n .. in pr ep for | |
| 387 | // next doma in data se t | |
| 388 | ||
| 389 | // ADDIN G domain d ata to buf fer | |
| 390 | while (r ead != nul l) { | |
| 391 | sb.a ppend(read ); | |
| 392 | read = br.read Line(); | |
| 393 | } | |
| 394 | ||
| 395 | } catch (Mal formedURLE xception e ) { | |
| 396 | log.erro r(e.toStri ng()); | |
| 397 | fail(e.g etMessage( )); | |
| 398 | } catch (IOE xception e ) { | |
| 399 | log.erro r(e.toStri ng()); | |
| 400 | fail(e.g etMessage( )); | |
| 401 | } | |
| 402 | ||
| 403 | sb .append("] }"); | |
| 404 | ||
| 405 | lo g.trace("\ n===> sb s ize=" + sb .length() + "\n" + s b.toString ()); | |
| 406 | } | |
| 407 | ||
| 408 | @Ignor e("fails") | |
| 409 | @Test | |
| 410 | public void test ParseConta ined() { | |
| 411 | ||
| 412 | lo g.trace("\ n\n======= ========== ====> TEST ING: testP arseContai ned <===== ========== ====== "); | |
| 413 | ||
| 414 | Fh irContext c = FhirCo ntext.forD stu2(); | |
| 415 | IP arser pars er = c.new JsonParser ().setPret tyPrint(tr ue); | |
| 416 | ||
| 417 | Ob servation o = new Ob servation( ); | |
| 418 | o. getCode(). setText("o bs text"); | |
| 419 | ||
| 420 | Pa tient p = new Patien t(); | |
| 421 | p. addName(). addFamily( "patient f amily"); | |
| 422 | o. getSubject ().setReso urce(p); | |
| 423 | ||
| 424 | St ring enc = parser.en codeResour ceToString (o); | |
| 425 | lo g.trace(en c); | |
| 426 | ||
| 427 | o = parser.p arseResour ce(Observa tion.class , enc); | |
| 428 | as sertEquals ("obs text ", o.getCo de().getTe xt()); | |
| 429 | ||
| 430 | p = (Patient ) o.getSub ject().get Resource() ; | |
| 431 | lo g.trace("p atient fam ily", p.ge tNameFirst Rep().getF amilyAsSin gleString( )); | |
| 432 | } | |
| 433 | ||
| 434 | /** | |
| 435 | * Tes t parsing and valida ting a DST U2 bundle of multipl e resource s data | |
| 436 | * res ponse (pro cessing a captured d ata from R DK run) | |
| 437 | * | |
| 438 | * @th rows IOExc eption | |
| 439 | */ | |
| 440 | @Ignor e("fails") | |
| 441 | @Test | |
| 442 | public void test ExtractRes ourcesAndB uildBundle () throws Interrupte dException , IOExcept ion { | |
| 443 | ||
| 444 | lo g.trace("\ n\n======= ========== ====> TEST ING: testE xtractReso urcesAndBu ildBundle <========= ========== == "); | |
| 445 | ||
| 446 | St ring msg; | |
| 447 | Bu ndle bundl eIn; | |
| 448 | Bu ndle bundl eOut = new Bundle(); | |
| 449 | // --------- ---------- ---------- ---------- ---------- -- | |
| 450 | Fh irValidato r val = Fh irUtils.ge tContext() .newValida tor(); | |
| 451 | va l.setValid ateAgainst StandardSc hema(true) ; | |
| 452 | va l.setValid ateAgainst StandardSc hematron(f alse); | |
| 453 | ||
| 454 | ja va.util.UU ID uuid = java.util. UUID.rando mUUID(); | |
| 455 | bu ndleOut.se tId(new Id Dt(uuid.to String())) ; | |
| 456 | ||
| 457 | bu ndleOut.se tType(Bund leTypeEnum .COLLECTIO N); | |
| 458 | Va lidationRe sult valid ationResul ta = val.v alidateWit hResult(bu ndleOut); | |
| 459 | as sertTrue(" Validating Initial B undle", va lidationRe sulta.isSu ccessful() ); | |
| 460 | ||
| 461 | // --------- ---------- ------- | |
| 462 | // PREP HAPI CONTEXT A ND PARSER | |
| 463 | // --------- ---------- ------- | |
| 464 | ||
| 465 | IP arser p = FhirUtils. newJsonPar ser().setP rettyPrint (true); | |
| 466 | ||
| 467 | // --------- ---------- ---------- -------- | |
| 468 | // Read in D STU2 bundl e of 1 res ources | |
| 469 | // --------- ---------- ---------- -------- | |
| 470 | ms g = IOUtil s.toString (XmlParser .class.get ResourceAs Stream("/s ampleRDKFh ir-Patient _dstu2.jso n")); | |
| 471 | IR esource re sourceIn = p.parseRe source(msg ); | |
| 472 | ||
| 473 | in stance.add SingleReso urce(FhirU tils.getCo ntext(), r esourceIn, bundleOut ); | |
| 474 | ||
| 475 | St ring outst r = p.enco deResource ToString(b undleOut); | |
| 476 | lo g.trace("\ n\nNEW BUN DLE AFTER BUNDLE(1): \n" + outs tr); | |
| 477 | ||
| 478 | as sertTrue(" A Bundle w ith 1 reso urce added successsf ully!", bu ndleOut.ge tEntry().s ize() == 1 ); | |
| 479 | ||
| 480 | // now part of observa tion | |
| 481 | // --------- ---------- ---------- -------- | |
| 482 | // Read in D STU2 bundl e of 2 res ources | |
| 483 | // --------- ---------- ---------- -------- | |
| 484 | ms g = IOUtil s.toString (XmlParser .class.get ResourceAs Stream("/s ampleRDKFh ir-HealthF actors.jso n")); | |
| 485 | bu ndleIn = ( Bundle) p. setPrettyP rint(true) .parseReso urce(msg); | |
| 486 | ||
| 487 | in stance.add Resources( FhirUtils. getContext (), bundle In, bundle Out); | |
| 488 | ||
| 489 | // --------- ---------- ---------- -------- | |
| 490 | // PRINT OUT NEW BUNDL E bundleou t | |
| 491 | // --------- ---------- ---------- -------- | |
| 492 | ou tstr = p.e ncodeResou rceToStrin g(bundleOu t); | |
| 493 | lo g.trace("N EW BUNDLE AFTER BUND LE(2):\n" + outstr); | |
| 494 | ||
| 495 | as sertTrue(" Another Bu ndle with 2 resource s added su ccesssfull y!", bundl eOut.getEn try().size () == 3); | |
| 496 | ||
| 497 | // --------- ---------- ---------- ---------- ---------- -- | |
| 498 | // Setup the schema fo r validati ng | |
| 499 | // and VALID ATE the ne wly create d bundle: bundleOut | |
| 500 | ||
| 501 | Va lidationRe sult valid ationResul t = val.va lidateWith Result(bun dleOut); | |
| 502 | as sertTrue(" Validating created f inal Json" , validati onResult.i sSuccessfu l()); | |
| 503 | ||
| 504 | } | |
| 505 | ||
| 506 | /** | |
| 507 | * | |
| 508 | * @th rows IOExc eption | |
| 509 | */ | |
| 510 | @Ignor e | |
| 511 | @Test | |
| 512 | public void test HAPIParser AndValidat e_DSTU2() throws IOE xception { | |
| 513 | ||
| 514 | lo g.trace("\ n\n======= ========== ====> TEST ING: testH APIParserA ndValidate _DSTU2 <== ========== ========= "); | |
| 515 | ||
| 516 | St ring msg; | |
| 517 | Va lidationRe sult valid ationResul t; | |
| 518 | ||
| 519 | // --------- ---------- ------- | |
| 520 | // PARSE ent ry fom rep sonse | |
| 521 | // --------- ---------- ------- | |
| 522 | Fh irContext fhirCtx = FhirUtils. getContext (); | |
| 523 | IP arser p = FhirUtils. newJsonPar ser().setP rettyPrint (true); | |
| 524 | ||
| 525 | // --------- ---------- ------- | |
| 526 | // Setup the schema fo r validati ng | |
| 527 | // --------- ---------- ------- | |
| 528 | Fh irValidato r val = fh irCtx.newV alidator() ; | |
| 529 | va l.setValid ateAgainst StandardSc hema(true) ; | |
| 530 | va l.setValid ateAgainst StandardSc hematron(t rue); | |
| 531 | ||
| 532 | // --------- ---------- ---------- ------ | |
| 533 | // Parsing & Validatin g a Bundle json | |
| 534 | // --------- ---------- ---------- ------ | |
| 535 | ms g = IOUtil s.toString (XmlParser .class.get ResourceAs Stream("/s ampleRDKFh ir-Conditi on.json")) ; | |
| 536 | Bu ndle bundl e = (Bundl e) p.parse Resource(m sg); | |
| 537 | ||
| 538 | va lidationRe sult = val .validateW ithResult( bundle); | |
| 539 | ||
| 540 | // IResource res = p.p arseResour ce(msg); | |
| 541 | // validatio nResult = val.valida teWithResu lt(res); | |
| 542 | if (!validat ionResult. isSuccessf ul()) { | |
| 543 | log.erro r("Validat ion Failed !"); | |
| 544 | log.erro r("....... VALIDATIN G Conditio n: Total I ssues = " + validati onResult.g etOperatio nOutcome() .getIssue( ).size() + "........ .........\ n"); | |
| 545 | for (Bas eIssue iss ue : valid ationResul t.getOpera tionOutcom e().getIss ue()) { | |
| 546 | log. error(issu e.getDetai lsElement( ).getValue AsString() ); | |
| 547 | } | |
| 548 | log.erro r("....... .......... .......... .......... .......... ......\n") ; | |
| 549 | } | |
| 550 | as sertTrue(" Validation failed: " , validati onResult.i sSuccessfu l()); | |
| 551 | ||
| 552 | } | |
| 553 | ||
| 554 | /** | |
| 555 | * Tes t used for quick PAR SING and V ALIDATING of a Bundl e JSON str ing. | |
| 556 | */ | |
| 557 | @Ignor e("Develop ment Test only") | |
| 558 | @Test | |
| 559 | public void test Validate() throws Un supportedE ncodingExc eption { | |
| 560 | ||
| 561 | // --------- ---------- ---------- ---------- - | |
| 562 | // can read data in fr om a file if it's LA RGE | |
| 563 | // --------- ---------- ---------- ---------- - | |
| 564 | // byte[] b = Files.re adAllBytes (Paths.get ("src/test /resources ", | |
| 565 | // "DataToVa lidate.jso n")); | |
| 566 | ||
| 567 | // --------- ---------- ---------- ---------- - | |
| 568 | // else repl ace inline for a qui ckie check | |
| 569 | // --------- ---------- ---------- ---------- - | |
| 570 | St ring s = " {\n" + " \"resour ceType\": \"Bundle\" ,\n" + " \"id\": \"a4a17e7a -874d-3279 -b663-4f47 b700f8cf\" ,\n" + " \"type\" : \"collec tion\",\n" | |
| 571 | + " \"base\ ": \"http: //127.0.0. 1:8888/res ource/fhir /\",\n" + " \"ent ry\": [{\n " + " \"r esource\": {\n" + " \"res ourceType\ ": \"Obser vation\",\ n" | |
| 572 | + " \"mod ifierExten sion\": [{ \n" + " \"url\": \"http://o rg.cogniti ve.cds.inv ocation.fh ir.datanat ure\",\n" | |
| 573 | + " \"value Code\": \" Input\"\n" + " }, {\n " + " \ "url\": \" http://org .cognitive .cds.invoc ation.fhir .parameter name\",\n" | |
| 574 | + " \"value String\": \"Weight\" \n" + " }], \n" + " \"code\ ": {\n" + " \"coding\ ": [{\n" | |
| 575 | + " \"s ystem\": \ "http://lo inc.org\", \n" + " \"cod e\": \"294 63-7\"\n" + " }]\ n" + " },\n" | |
| 576 | + " \"val ueQuantity \": {\n" + " \"value\ ": 180.5,\ n" + " \"co de\": \"Po unds\"\n" + " } ,\n" | |
| 577 | + " \"com ments\": \ "Comment\" ,\n" + " \"issu ed\": \"20 15-06-02T1 8:55:48.33 8-07:00\", \n" + " \"statu s\": \"pre liminary\" \n" | |
| 578 | + " }\n" + " }]\ n" + "}"; | |
| 579 | by te[] b = s .getBytes( Charset.fo rName("UTF -8")); | |
| 580 | ||
| 581 | // --------- ---------- ---------- ---------- - | |
| 582 | // PARSE Str ing into a BUNDLE ob ject | |
| 583 | // --------- ---------- ---------- ---------- - | |
| 584 | Fh irContext fhirCtx = FhirUtils. getContext (); | |
| 585 | IP arser pars er = FhirU tils.newJs onParser() .setPretty Print(true ); | |
| 586 | ||
| 587 | Bu ndle bundl e = (Bundl e) parser. parseResou rce(new St ring(b, "U TF-8")); | |
| 588 | ||
| 589 | // --------- ---------- ---------- ------ | |
| 590 | // Parsing & Validatin g a Bundle json | |
| 591 | // --------- ---------- ---------- ------ | |
| 592 | Fh irValidato r val = fh irCtx.newV alidator() ; | |
| 593 | va l.setValid ateAgainst StandardSc hema(true) ; | |
| 594 | va l.setValid ateAgainst StandardSc hematron(t rue); | |
| 595 | ||
| 596 | Va lidationRe sult valid ationResul t = val.va lidateWith Result(bun dle); | |
| 597 | ||
| 598 | // --------- ---------- ---------- ------ | |
| 599 | // PRINT OUT VALIDATIO N RESULTs | |
| 600 | // --------- ---------- ---------- ------ | |
| 601 | if (validati onResult.g etOperatio nOutcome() .getIssue( ).size() > 0) { | |
| 602 | log.erro r("....... VALIDATIN G: Total I ssues = " + validati onResult.g etOperatio nOutcome() .getIssue( ).size() + "........ .........\ n"); | |
| 603 | for (Bas eIssue iss ue : valid ationResul t.getOpera tionOutcom e().getIss ue()) { | |
| 604 | log. error(issu e.getDetai lsElement( ).getValue AsString() ); | |
| 605 | } | |
| 606 | log.erro r("....... .......... .......... .......... .......... ......\n") ; | |
| 607 | } | |
| 608 | } | |
| 609 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.