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\main\java\com\cognitive\cds\invocation\engineplugins | OpenCDS.java | Wed Jul 12 18:43:52 2017 UTC |
| 2 | cds.zip\cds\product\production\cdsinvocation\cds-invocation\src\main\java\com\cognitive\cds\invocation\engineplugins | OpenCDS.java | Wed Sep 27 16:01:02 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 1274 |
| 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 | /* | |
| 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.eng ineplugins ; | |
| 26 | ||
| 27 | import jav a.io.IOExc eption; | |
| 28 | import jav a.io.Strin gReader; | |
| 29 | import jav a.net.Http URLConnect ion; | |
| 30 | import jav a.net.URL; | |
| 31 | import jav a.util.Arr ayList; | |
| 32 | import jav a.util.Ite rator; | |
| 33 | import jav a.util.Lis t; | |
| 34 | import jav a.util.Pro perties; | |
| 35 | ||
| 36 | import jav ax.xml.bin d.JAXBCont ext; | |
| 37 | import jav ax.xml.bin d.JAXBElem ent; | |
| 38 | import jav ax.xml.bin d.JAXBExce ption; | |
| 39 | import jav ax.xml.bin d.Marshall er; | |
| 40 | import jav ax.xml.bin d.Unmarsha ller; | |
| 41 | import jav ax.xml.nam espace.QNa me; | |
| 42 | import jav ax.xml.str eam.XMLInp utFactory; | |
| 43 | import jav ax.xml.str eam.XMLStr eamExcepti on; | |
| 44 | import jav ax.xml.str eam.XMLStr eamReader; | |
| 45 | ||
| 46 | //import o rg.codehau s.jackson. JsonNode; | |
| 47 | //import o rg.codehau s.jackson. map.Object Mapper; | |
| 48 | import org .omg.dss.D SSRuntimeE xceptionFa ult; | |
| 49 | import org .omg.dss.D ecisionSup portServic e; | |
| 50 | import org .omg.dss.E valuation; | |
| 51 | import org .omg.dss.E valuationE xceptionFa ult; | |
| 52 | import org .omg.dss.I nvalidDriD ataFormatE xceptionFa ult; | |
| 53 | import org .omg.dss.I nvalidTime ZoneOffset ExceptionF ault; | |
| 54 | import org .omg.dss.R equiredDat aNotProvid edExceptio nFault; | |
| 55 | import org .omg.dss.U nrecognize dLanguageE xceptionFa ult; | |
| 56 | import org .omg.dss.U nrecognize dScopedEnt ityExcepti onFault; | |
| 57 | import org .omg.dss.U nsupported LanguageEx ceptionFau lt; | |
| 58 | import org .omg.dss.c ommon.Enti tyIdentifi er; | |
| 59 | import org .omg.dss.c ommon.Inte ractionIde ntifier; | |
| 60 | import org .omg.dss.c ommon.Item Identifier ; | |
| 61 | import org .omg.dss.c ommon.Sema nticPayloa d; | |
| 62 | import org .omg.dss.e valuation. Evaluate; | |
| 63 | import org .omg.dss.e valuation. EvaluateRe sponse; | |
| 64 | import org .omg.dss.e valuation. requestres ponse.Data Requiremen tItemData; | |
| 65 | import org .omg.dss.e valuation. requestres ponse.Eval uationRequ est; | |
| 66 | import org .omg.dss.e valuation. requestres ponse.KMEv aluationRe quest; | |
| 67 | import org .opencds.v mr.v1_0.sc hema.CD; | |
| 68 | import org .opencds.v mr.v1_0.sc hema.CDSIn put; | |
| 69 | import org .opencds.v mr.v1_0.sc hema.CDSOu tput; | |
| 70 | import org .opencds.v mr.v1_0.sc hema.Encou nterEvent; | |
| 71 | import org .opencds.v mr.v1_0.sc hema.Evalu atedPerson ; | |
| 72 | import org .opencds.v mr.v1_0.sc hema.Evalu atedPerson .ClinicalS tatements. EncounterE vents; | |
| 73 | import org .opencds.v mr.v1_0.sc hema.Evalu atedPerson .Demograph ics; | |
| 74 | import org .opencds.v mr.v1_0.sc hema.II; | |
| 75 | import org .opencds.v mr.v1_0.sc hema.IVLTS ; | |
| 76 | import org .opencds.v mr.v1_0.sc hema.TS; | |
| 77 | import org .opencds.v mr.v1_0.sc hema.VMR; | |
| 78 | import org .slf4j.Log ger; | |
| 79 | import org .slf4j.Log gerFactory ; | |
| 80 | ||
| 81 | import com .cognitive .cds.invoc ation.CDSE nginePlugI nIFace; | |
| 82 | import com .cognitive .cds.invoc ation.Engi neInstance StateManag ementIFace ; | |
| 83 | import com .cognitive .cds.invoc ation.Proj ectPropert ies; | |
| 84 | import com .cognitive .cds.invoc ation.mode l.EngineIn stanceStat e; | |
| 85 | import com .cognitive .cds.invoc ation.mode l.FaultInf o; | |
| 86 | import com .cognitive .cds.invoc ation.mode l.Invocati onConstant s; | |
| 87 | import com .cognitive .cds.invoc ation.mode l.Result; | |
| 88 | import com .cognitive .cds.invoc ation.mode l.ResultBu ndle; | |
| 89 | import com .cognitive .cds.invoc ation.mode l.Rule; | |
| 90 | import com .cognitive .cds.invoc ation.mode l.StatusCo de; | |
| 91 | import com .fasterxml .jackson.d atabind.Js onNode; | |
| 92 | import com .fasterxml .jackson.d atabind.Ob jectMapper ; | |
| 93 | ||
| 94 | /** | |
| 95 | * Main Op enCDS Call Plug in | |
| 96 | * | |
| 97 | * @author Tadessa S efer, Jerr y Goodnoug h | |
| 98 | * @versio n 1.0 | |
| 99 | * @create d 11-Dec-2 014 9:10:4 2 AM | |
| 100 | * | |
| 101 | * Todos: | |
| 102 | * | |
| 103 | * 1) Chec k Error Ha ndling 2) Update for instance pooling - Allow the configurat ion includ e multiple endpoints | |
| 104 | * | |
| 105 | */ | |
| 106 | public cla ss OpenCDS implement s CDSEngin ePlugInIFa ce { | |
| 107 | ||
| 108 | pr ivate stat ic final L ogger logg er = Logge rFactory.g etLogger(O penCDS.cla ss); | |
| 109 | ||
| 110 | pr ivate stat ic final Q Name SERVI CE_NAME = new QName( | |
| 111 | "htt p://www.om g.org/spec /CDSS/2011 05/dssWsdl ", | |
| 112 | "Dec isionSuppo rtService" ); | |
| 113 | pu blic stati c final St ring OPEN_ CDS = "ope nCDS"; | |
| 114 | ||
| 115 | // Common Pr operty Key s used by Rules conf iguration for OpenCD S | |
| 116 | pu blic stati c final St ring KEY_R ULE_SCOPIN G_ENTITY_I D = "scopi ngEntityId "; | |
| 117 | pu blic stati c final St ring KEY_R ULE_BUSINE SS_ID = "b usinessId" ; | |
| 118 | pu blic stati c final St ring KEY_R ULE_VERSIO N = "versi on"; | |
| 119 | ||
| 120 | pu blic stati c final St ring KEY_I NFO_MODEL_ VERSION = "INFO_MODE L_VERSION" ; | |
| 121 | pu blic stati c final St ring KEY_I NFO_MODEL_ BUSINESS_I D = "INFO_ MODEL_BUSI NESS_ID"; | |
| 122 | pu blic stati c final St ring KEY_I NFO_MODEL_ ENTITY_ID = "INFO_MO DEL_ENTITY _ID"; | |
| 123 | ||
| 124 | // Def ault the M odel to FH IR unless otherwise configured by the Ru le or Engi ne | |
| 125 | pr ivate Stri ng default ModelScopi ngEntityId = "org.op encds.fhir "; | |
| 126 | pr ivate Stri ng default ModelBusin essId = "F HIR"; | |
| 127 | pr ivate Stri ng default ModelVersi on = "1.0" ; | |
| 128 | pr ivate fina l String t ype = "Ope nCDS"; | |
| 129 | ||
| 130 | pr ivate Stri ng endPoin t; | |
| 131 | ||
| 132 | /* * | |
| 133 | * Connectio n Timeout in millise conds | |
| 134 | * / | |
| 135 | pr ivate int connection Timeout = 2000; | |
| 136 | ||
| 137 | /* * | |
| 138 | * Variables only used in test c ode below. .. | |
| 139 | * / | |
| 140 | pr ivate stat ic final S tring INPU T_ID_ROOT = "2.16.84 0.1.113883 .3.1829.11 .1.1.1"; | |
| 141 | pr ivate stat ic final S tring TEMP LATE_ID_RO OT = "2.16 .840.1.113 883.3.1829 .11.1.2.1" ; | |
| 142 | pr ivate stat ic final S tring ROOT _ID = "2.1 6.840.1.11 3883.3.348 .61.7"; | |
| 143 | pr ivate stat ic final S tring ROOT _EXTENSION = "100104 "; | |
| 144 | pr ivate stat ic final S tring GEND ER_CODE_SY STEM = "2. 16.840.1.1 13883.1.11 .1"; | |
| 145 | pr ivate stat ic final S tring EVEN T_TIME = " 2010060210 1010"; | |
| 146 | pr ivate stat ic final S tring CONC EPT_CODE = "2.16.840 .1.113883. 1.11.1"; | |
| 147 | ||
| 148 | pu blic OpenC DS() { | |
| 149 | } | |
| 150 | ||
| 151 | @O verride | |
| 152 | pu blic void finalize() throws Th rowable { | |
| 153 | } | |
| 154 | ||
| 155 | @O verride | |
| 156 | pu blic void introduceD ata() { | |
| 157 | } | |
| 158 | ||
| 159 | @O verride | |
| 160 | pu blic Resul tBundle in vokeRaw(Li st<Rule> r ules, Obje ct data, S tring call Id, | |
| 161 | Engi neInstance StateManag ementIFace eism) { | |
| 162 | Resu ltBundle r esultBundl e; | |
| 163 | if ( data insta nceof Stri ng) { | |
| 164 | result Bundle = t his.invoke (rules, (S tring) dat a, callId, eism); | |
| 165 | } el se { | |
| 166 | result Bundle = n ew ResultB undle(); | |
| 167 | result Bundle.set FaultInfo( new ArrayL ist<FaultI nfo>()); | |
| 168 | result Bundle.set Status(Sta tusCode.US E_NOT_RECO GNIZED); | |
| 169 | ||
| 170 | // FUT URE: Imple ment raw m ode OpenCD S serializ ation | |
| 171 | } | |
| 172 | retu rn resultB undle; | |
| 173 | } | |
| 174 | ||
| 175 | /* * | |
| 176 | * | |
| 177 | * @param en gineInstan ceState | |
| 178 | * @return S tring url representi ng the pro vided engi neInstance State, or null in th e event th at the | |
| 179 | * engineIns tanceState is null. | |
| 180 | * / | |
| 181 | pu blic Strin g buildOpe nCDSEndpoi ntUrl(Engi neInstance State engi neInstance State) { | |
| 182 | ||
| 183 | if ( engineInst anceState == null) { | |
| 184 | return null; | |
| 185 | } | |
| 186 | ||
| 187 | //example: http:// IP /opencds-d ecision-su pport-serv ice | |
| 188 | Stri ngBuilder sb = new S tringBuild er("http:/ /"); | |
| 189 | sb.a ppend(engi neInstance State.getH ost() + ": "); | |
| 190 | sb.a ppend(engi neInstance State.getP ort() + "/ opencds-de cision-sup port-servi ce"); | |
| 191 | ||
| 192 | logg er.debug(" endpoint l ooked up f rom (test) registry: " + sb.to String()); | |
| 193 | ||
| 194 | retu rn sb.toSt ring(); | |
| 195 | } | |
| 196 | ||
| 197 | /* * | |
| 198 | * | |
| 199 | * @return a n EngineIn stanceStat e from the list of a ctive engi ne instanc e states o f this typ e, or null if there are | |
| 200 | * none. | |
| 201 | * / | |
| 202 | pu blic Engin eInstanceS tate getEn gineInstan ce(EngineI nstanceSta teManageme ntIFace ei sm) { | |
| 203 | logg er.debug(" in getEngi neInstance ()..."); | |
| 204 | //ge t our list and pick one at ran dom | |
| 205 | List <EngineIns tanceState > engineIn stanceStat es = eism. getActiveE ngineInsta ncesByType (type); | |
| 206 | ||
| 207 | // FUTURE: u se a more legitmate load balan cing schem e | |
| 208 | //FU TURE: do we want to add more elements o f data to the state or make ot her config options? protocol, url, etc. | |
| 209 | int index = (i nt) (Math. random() * engineIns tanceState s.size()); | |
| 210 | logg er.debug(" selected i ndex of en gine type " + type + ": " + in dex); | |
| 211 | ||
| 212 | if ( engineInst anceStates .size() > 0) { | |
| 213 | return engineIns tanceState s.get(inde x); | |
| 214 | } el se { | |
| 215 | //if w e have no engines th at match t he require d type - r eturn null . | |
| 216 | return null; | |
| 217 | } | |
| 218 | } | |
| 219 | ||
| 220 | pu blic boole an updateE ngineInsta nceState( | |
| 221 | Engi neInstance StateManag ementIFace eism, Eng ineInstanc eState eng ineInstanc eState) { | |
| 222 | logg er.debug(" in updateE ngineInsta nceState.. ."); | |
| 223 | retu rn eism.up dateEngine InstanceSt ate(engine InstanceSt ate); | |
| 224 | ||
| 225 | } | |
| 226 | ||
| 227 | /* * | |
| 228 | * Invoke a OpenCDS ru les engine | |
| 229 | * | |
| 230 | * @param ru les | |
| 231 | * @param da ta Based64 Encoded B lob | |
| 232 | * @param ca llId | |
| 233 | * @return A Result Bu ndle of de code resul ts | |
| 234 | * / | |
| 235 | @O verride | |
| 236 | pu blic Resul tBundle in voke(List< Rule> rule s, String data, Stri ng callId, EngineIns tanceState Management IFace eism ) { | |
| 237 | logg er.debug(" in invoke( ...)"); | |
| 238 | ||
| 239 | Resu ltBundle r esultBundl e = new Re sultBundle (); | |
| 240 | List <FaultInfo > faultLis t = new Ar rayList<>( ); | |
| 241 | Stat usCode sta tus = Stat usCode.SUC CESS; | |
| 242 | ||
| 243 | Stri ng theEndP oint = nul l; | |
| 244 | ||
| 245 | URL wsdl = nul l; | |
| 246 | Deci sionSuppor tService o pencdsServ ice = null ; | |
| 247 | Eval uation eva luationPor t = null; | |
| 248 | Engi neInstance State eis = null; | |
| 249 | ||
| 250 | //if an engine endpoint was provid ed via con fig, use i t. Otherw ise, use r egistry. | |
| 251 | if ( endPoint ! = null) { | |
| 252 | theEnd Point = en dPoint; | |
| 253 | logger .debug("en dpoint pro vided by c onfig file : " + endP oint); | |
| 254 | } el se { | |
| 255 | if (ei sm != null ) { //if w e don't ha ve this ei ther, let theEndPoin t stay nul l. | |
| 256 | eis = ge tEngineIns tance(eism ); | |
| 257 | theEndPo int = buil dOpenCDSEn dpointUrl( eis); | |
| 258 | logger.d ebug("endp oint provi ded by eng ine regist ry: " + en dPoint); | |
| 259 | } | |
| 260 | } | |
| 261 | ||
| 262 | if ( opencdsSer vice == nu ll && theE ndPoint != null) { | |
| 263 | boolea n success = false; | |
| 264 | //FUTURE : in the event of a n extremel y unlikely edge case it might | |
| 265 | //be g ood to put a max ret ry count o n loops li ke the one below. | |
| 266 | ||
| 267 | //do/w hile - try to get a working co nnection a s long as we have co nnections left to tr y. | |
| 268 | do { | |
| 269 | try { | |
| 270 | URL url = new URL(th eEndPoint) ; | |
| 271 | logger.deb ug("attemp ting to co ntact endp oint: " + theEndPoin t); | |
| 272 | HttpURLCon nection co nn = (Http URLConnect ion) url.o penConnect ion(); | |
| 273 | conn.setCo nnectTimeo ut(connect ionTimeout ); | |
| 274 | conn.conne ct(); | |
| 275 | if (conn.g etResponse Code() == 200) { | |
| 276 | ws dl = new U RL(theEndP oint + "/e valuate?ws dl"); | |
| 277 | op encdsServi ce = new D ecisionSup portServic e(wsdl, SE RVICE_NAME ); | |
| 278 | ev aluationPo rt = openc dsService. getEvaluat e(); | |
| 279 | } | |
| 280 | success = true; | |
| 281 | ||
| 282 | } catch (Exception e) { | |
| 283 | logger.err or("Error openning c onnection" , e); | |
| 284 | theEndPoin t = null; // using t his to bre ak the loo p unless w e have mor e. | |
| 285 | if (eis != null) { / /if we're using the dynamic re gistry... | |
| 286 | ei s.setStatu s(false); | |
| 287 | up dateEngine InstanceSt ate(eism, eis); | |
| 288 | ei s = getEng ineInstanc e(eism); | |
| 289 | th eEndPoint = buildOpe nCDSEndpoi ntUrl(eis) ; | |
| 290 | } | |
| 291 | } | |
| 292 | //if we don't succ eed, try t o get anot her one an d go again if possib le. | |
| 293 | } whil e (theEndP oint != nu ll && !suc cess); | |
| 294 | logger .debug("Re try loop c ompleted. Success:" + success ); | |
| 295 | } | |
| 296 | ||
| 297 | if ( wsdl == nu ll || open cdsService == null) { | |
| 298 | FaultI nfo fault = new Faul tInfo(); | |
| 299 | status = StatusC ode.RULES_ ENGINE_NOT _AVAILABLE ; | |
| 300 | fault. setFault(I nvocationC onstants.S tatusCodes .RULES_ENG INE_NOT_AV AILABLE.ge tMessage() + " " + t heEndPoint ); | |
| 301 | faultL ist.add(fa ult); | |
| 302 | result Bundle.set FaultInfo( faultList) ; | |
| 303 | result Bundle.set Status(sta tus); | |
| 304 | return resultBun dle; | |
| 305 | } | |
| 306 | ||
| 307 | if ( rules == n ull || rul es.isEmpty ()) { | |
| 308 | FaultI nfo fault = new Faul tInfo(); | |
| 309 | status = StatusC ode.GENERA L_RULES_FA ILURE; | |
| 310 | fault. setFault(I nvocationC onstants.S tatusCodes .GENERAL_R ULES_FAILU RE | |
| 311 | .getMess age() | |
| 312 | + ", " | |
| 313 | + Invoca tionConsta nts.NO_RUL E_CONFIGUR ED); | |
| 314 | faultL ist.add(fa ult); | |
| 315 | result Bundle.set FaultInfo( faultList) ; | |
| 316 | result Bundle.set Status(sta tus); | |
| 317 | return resultBun dle; | |
| 318 | } | |
| 319 | for (Iterator< Rule> iter ator = rul es.iterato r(); itera tor.hasNex t();) { | |
| 320 | Rule r ule = iter ator.next( ); | |
| 321 | Intera ctionIdent ifier inte ractionId = new Inte ractionIde ntifier(); | |
| 322 | Evalua tionReques t evaluati onRequest = new Eval uationRequ est(); | |
| 323 | ||
| 324 | intera ctionId.se tInteracti onId(callI d); | |
| 325 | intera ctionId.se tScopingEn tityId(cal lId); | |
| 326 | ||
| 327 | evalua tionReques t.setClien tLanguage( ""); | |
| 328 | evalua tionReques t.setClien tTimeZoneO ffset(""); | |
| 329 | ||
| 330 | KMEval uationRequ est kmEval Requst = n ew KMEvalu ationReque st(); | |
| 331 | ||
| 332 | kmEval Requst.set KmId(new E ntityIdent ifier()); | |
| 333 | Proper ties ruleP rops = rul e.getPrope rties(); | |
| 334 | ||
| 335 | // FUT URE Implem ent Rule D efaults | |
| 336 | kmEval Requst.get KmId().set ScopingEnt ityId(rule Props.getP roperty(KE Y_RULE_SCO PING_ENTIT Y_ID)); | |
| 337 | kmEval Requst.get KmId().set BusinessId (ruleProps .getProper ty(KEY_RUL E_BUSINESS _ID)); | |
| 338 | kmEval Requst.get KmId().set Version(ru leProps.ge tProperty( KEY_RULE_V ERSION)); | |
| 339 | evalua tionReques t.getKmEva luationReq uest().add (kmEvalReq ust); | |
| 340 | ||
| 341 | DataRe quirementI temData it emData = n ew DataReq uirementIt emData(); | |
| 342 | itemDa ta.setDriI d(new Item Identifier ()); | |
| 343 | itemDa ta.getDriI d().setIte mId(rule.g etId()); | |
| 344 | ||
| 345 | itemDa ta.getDriI d().setCon tainingEnt ityId(new EntityIden tifier()); | |
| 346 | itemDa ta.getDriI d().getCon tainingEnt ityId().se tScopingEn tityId( | |
| 347 | ruleProp s.getPrope rty(KEY_RU LE_SCOPING _ENTITY_ID )); | |
| 348 | itemDa ta.getDriI d().getCon tainingEnt ityId().se tBusinessI d(ruleProp s.getPrope rty(KEY_RU LE_BUSINES S_ID)); | |
| 349 | itemDa ta.getDriI d().getCon tainingEnt ityId().se tVersion(r uleProps.g etProperty (KEY_RULE_ VERSION)); | |
| 350 | Semant icPayload payload = new Semant icPayload( ); | |
| 351 | ||
| 352 | Entity Identifier ei = new EntityIden tifier(); | |
| 353 | ei.set ScopingEnt ityId(rule .getProper ties().get Property(K EY_INFO_MO DEL_ENTITY _ID, defau ltModelSco pingEntity Id)); | |
| 354 | ei.set BusinessId (rule.getP roperties( ).getPrope rty(KEY_IN FO_MODEL_B USINESS_ID , defaultM odelBusine ssId)); | |
| 355 | ei.set Version(ru le.getProp erties().g etProperty (KEY_INFO_ MODEL_VERS ION, defau ltModelVer sion)); | |
| 356 | payloa d.setInfor mationMode lSSId(ei); | |
| 357 | ||
| 358 | itemDa ta.setData (payload); | |
| 359 | ||
| 360 | // Next three line s disabled and repla ced by the simple | |
| 361 | // dat a.getBytes - I think it is equ ivalent | |
| 362 | // byt e[] encode d = null; | |
| 363 | // enc oded = Bas e64.encode (data.getB ytes()); | |
| 364 | // byt e[] decode d = Base64 .decode(en coded); | |
| 365 | // Sys tem.out.pr intln("Ope nCDS Paylo ad = "+dat a); | |
| 366 | // Pay load is as sumed to b e Base64 E ncoded alr eady, we m ight chang e | |
| 367 | // thi s. | |
| 368 | byte[] decoded = data.getB ytes(); | |
| 369 | itemDa ta.getData ().getBase 64EncodedP ayload().a dd(decoded ); | |
| 370 | ||
| 371 | evalua tionReques t.getDataR equirement ItemData() .add(itemD ata); | |
| 372 | ||
| 373 | Evalua te evaluat e = new Ev aluate(); | |
| 374 | evalua te.setEval uationRequ est(evalua tionReques t); | |
| 375 | evalua te.setInte ractionId( interactio nId); | |
| 376 | String returnDat aDecoded = null; | |
| 377 | try { | |
| 378 | Evaluate Response r esponse = evaluation Port.evalu ate(evalua te); | |
| 379 | // F UTURE - Ca n OpenCDS return mul tiple resp onse and i f so we | |
| 380 | // shoul d handle t hem | |
| 381 | byte[] r eturnData = response .getEvalua tionRespon se() | |
| 382 | .getFinalK MEvaluatio nResponse( ).get(0) | |
| 383 | .getKmEval uationResu ltData().g et(0).getD ata() | |
| 384 | .getBase64 EncodedPay load().get (0); | |
| 385 | returnDa taDecoded = new Stri ng(returnD ata); | |
| 386 | ||
| 387 | } catc h (Invalid TimeZoneOf fsetExcept ionFault e ) { | |
| 388 | logger.e rror("Expe cted excep tion: Inva lidTimeZon eOffsetExc eptionFaul t has occu rred."); | |
| 389 | FaultInf o fault = new FaultI nfo(); | |
| 390 | fault.se tFault("In validTimeZ oneOffsetE xceptionFa ult has oc curred"); | |
| 391 | faultLis t.add(faul t); | |
| 392 | } catc h (Evaluat ionExcepti onFault e) { | |
| 393 | logger.e rror("Expe cted excep tion: Eval uationExce ptionFault has occur red. " + e .getMessag e()); | |
| 394 | status = StatusCod e.GENERAL_ RULES_FAIL URE; | |
| 395 | FaultInf o fault = new FaultI nfo(); | |
| 396 | fault.se tFault(Inv ocationCon stants.Sta tusCodes.G ENERAL_RUL ES_FAILURE .getMessag e()); | |
| 397 | faultLis t.add(faul t); | |
| 398 | resultBu ndle.setSt atus(statu s); | |
| 399 | } catc h (Invalid DriDataFor matExcepti onFault e) { | |
| 400 | logger.e rror("Expe cted excep tion: Inva lidDriData FormatExce ptionFault has occur red."); | |
| 401 | FaultInf o fault = new FaultI nfo(); | |
| 402 | fault.se tFault("In validDriDa taFormatEx ceptionFau lt has occ urred."); | |
| 403 | faultLis t.add(faul t); | |
| 404 | resultBu ndle.setSt atus(Statu sCode.GENE RAL_RULES_ FAILURE); | |
| 405 | } catc h (Unrecog nizedLangu ageExcepti onFault e) { | |
| 406 | logger.e rror("Expe cted excep tion: Unre cognizedLa nguageExce ptionFault has occur red."); | |
| 407 | FaultInf o fault = new FaultI nfo(); | |
| 408 | fault.se tFault("Un recognized LanguageEx ceptionFau lt has occ urred."); | |
| 409 | faultLis t.add(faul t); | |
| 410 | resultBu ndle.setSt atus(Statu sCode.GENE RAL_RULES_ FAILURE); | |
| 411 | } catc h (Unrecog nizedScope dEntityExc eptionFaul t e) { | |
| 412 | logger.e rror("Expe cted excep tion: Unre cognizedSc opedEntity ExceptionF ault has o ccurred.") ; | |
| 413 | FaultInf o fault = new FaultI nfo(); | |
| 414 | fault.se tFault("Un recognized ScopedEnti tyExceptio nFault has occurred. "); | |
| 415 | faultLis t.add(faul t); | |
| 416 | resultBu ndle.setSt atus(Statu sCode.GENE RAL_RULES_ FAILURE); | |
| 417 | } catc h (DSSRunt imeExcepti onFault e) { | |
| 418 | logger.e rror("Expe cted excep tion: DSSR untimeExce ptionFault has occur red."); | |
| 419 | FaultInf o fault = new FaultI nfo(); | |
| 420 | fault.se tFault("In validTimeZ oneOffsetE xceptionFa ult has oc curred"); | |
| 421 | faultLis t.add(faul t); | |
| 422 | resultBu ndle.setSt atus(Statu sCode.GENE RAL_RULES_ FAILURE); | |
| 423 | } catc h (Unsuppo rtedLangua geExceptio nFault e) { | |
| 424 | logger.e rror("Expe cted excep tion: Unsu pportedLan guageExcep tionFault has occurr ed."); | |
| 425 | FaultInf o fault = new FaultI nfo(); | |
| 426 | fault.se tFault("Un supportedL anguageExc eptionFaul t has occu rred."); | |
| 427 | faultLis t.add(faul t); | |
| 428 | resultBu ndle.setSt atus(Statu sCode.GENE RAL_RULES_ FAILURE); | |
| 429 | } catc h (Require dDataNotPr ovidedExce ptionFault e) { | |
| 430 | logger.e rror("Expe cted excep tion: Requ iredDataNo tProvidedE xceptionFa ult has oc curred."); | |
| 431 | FaultInf o fault = new FaultI nfo(); | |
| 432 | fault.se tFault("Re quiredData NotProvide dException Fault has occurred." ); | |
| 433 | faultLis t.add(faul t); | |
| 434 | resultBu ndle.setSt atus(Statu sCode.GENE RAL_RULES_ FAILURE); | |
| 435 | } | |
| 436 | if (fa ultList != null && ! faultList. isEmpty()) { | |
| 437 | resultBu ndle.setFa ultInfo(fa ultList); | |
| 438 | return r esultBundl e; | |
| 439 | } | |
| 440 | ||
| 441 | Result result = new Result (); | |
| 442 | result .setBody(r eturnDataD ecoded); | |
| 443 | result .setCallId (callId); | |
| 444 | result .setGenera tedBy("Ope nCDS"); | |
| 445 | List<R esult> res ults = new ArrayList <>(); | |
| 446 | result s.add(resu lt); | |
| 447 | result Bundle.set Results(re sults); | |
| 448 | } | |
| 449 | retu rn resultB undle; | |
| 450 | } | |
| 451 | ||
| 452 | pu blic Strin g getEndPo int() { | |
| 453 | retu rn endPoin t; | |
| 454 | } | |
| 455 | ||
| 456 | pu blic void setEndPoin t(String e ndPoint) { | |
| 457 | if ( endPoint.s tartsWith( "@")) { | |
| 458 | this.e ndPoint = ProjectPro perties.ge tInstance( ).getPrope rty( | |
| 459 | endPoint .substring (1)); | |
| 460 | } el se { | |
| 461 | this.e ndPoint = endPoint; | |
| 462 | } | |
| 463 | } | |
| 464 | ||
| 465 | pu blic Strin g getDefau ltModelSco pingEntity Id() { | |
| 466 | retu rn default ModelScopi ngEntityId ; | |
| 467 | } | |
| 468 | ||
| 469 | pu blic void setDefault ModelScopi ngEntityId ( | |
| 470 | Stri ng default ModelScopi ngEntityId ) { | |
| 471 | this .defaultMo delScoping EntityId = defaultMo delScoping EntityId; | |
| 472 | } | |
| 473 | ||
| 474 | pu blic Strin g getDefau ltModelBus inessId() { | |
| 475 | retu rn default ModelBusin essId; | |
| 476 | } | |
| 477 | ||
| 478 | pu blic void setDefault ModelBusin essId(Stri ng default ModelBusin essId) { | |
| 479 | this .defaultMo delBusines sId = defa ultModelBu sinessId; | |
| 480 | } | |
| 481 | ||
| 482 | pu blic Strin g getDefau ltModelVer sion() { | |
| 483 | retu rn default ModelVersi on; | |
| 484 | } | |
| 485 | ||
| 486 | pu blic void setDefault ModelVersi on(String defaultMod elVersion) { | |
| 487 | this .defaultMo delVersion = default ModelVersi on; | |
| 488 | } | |
| 489 | ||
| 490 | pu blic int g etConnecti onTimeout( ) { | |
| 491 | retu rn connect ionTimeout ; | |
| 492 | } | |
| 493 | ||
| 494 | pu blic void setConnect ionTimeout (int conne ctionTimeo ut) { | |
| 495 | this .connectio nTimeout = connectio nTimeout; | |
| 496 | } | |
| 497 | ||
| 498 | pu blic Strin g jaxbMars hal(CDSInp ut jaxbObj ) | |
| 499 | thro ws javax.x ml.bind.JA XBExceptio n, java.io .IOExcepti on { | |
| 500 | java .io.String Writer sw = new java .io.String Writer(); | |
| 501 | java x.xml.bind .JAXBConte xt jaxbCtx = javax.x ml.bind.JA XBContext | |
| 502 | .newIn stance(jax bObj.getCl ass().getP ackage().g etName()); | |
| 503 | java x.xml.bind .Marshalle r marshall er = jaxbC tx.createM arshaller( ); | |
| 504 | mars haller.set Property(j avax.xml.b ind.Marsha ller.JAXB_ ENCODING, "UTF-8"); | |
| 505 | ||
| 506 | mars haller.set Property(j avax.xml.b ind.Marsha ller.JAXB_ FORMATTED_ OUTPUT, Bo olean.TRUE ); | |
| 507 | mars haller.set Property(M arshaller. JAXB_FRAGM ENT, Boole an.TRUE); // to | |
| 508 | // r emove | |
| 509 | // s tandalone= "yes" | |
| 510 | // f rom | |
| 511 | // t he | |
| 512 | // x ml | |
| 513 | mars haller.mar shal(new J AXBElement <CDSInput> (new QName ("", "cdsI nput"), CD SInput.cla ss, jaxbOb j), sw); | |
| 514 | sw.c lose(); | |
| 515 | retu rn sw.toSt ring(); | |
| 516 | } | |
| 517 | ||
| 518 | /* * | |
| 519 | * This meth od deseria lize the v mr xml str ing to CDS Output dat a model | |
| 520 | * | |
| 521 | * @param vm rXml - The VMR xml o utput comi ng from Op enCDS | |
| 522 | * @return C DSoutput d ata model | |
| 523 | * / | |
| 524 | pu blic CDSOu tput unmar shal(Strin g xmlStrin g) { | |
| 525 | CDSO utput outp ut = null; | |
| 526 | try { | |
| 527 | JAXBCo ntext jaxb Context = JAXBContex t.newInsta nce(CDSOut put.class) ; | |
| 528 | Unmars haller jax bUnmarshal ler = jaxb Context.cr eateUnmars haller(); | |
| 529 | XMLInp utFactory factory = XMLInputFa ctory.newF actory(); | |
| 530 | ||
| 531 | XMLStr eamReader streamRead er = facto ry.createX MLStreamRe ader(new S tringReade r(xmlStrin g)); | |
| 532 | JAXBEl ement<CDSO utput> roo t = jaxbUn marshaller .unmarshal (streamRea der, CDSOu tput.class ); | |
| 533 | output = root.ge tValue(); | |
| 534 | } ca tch (XMLSt reamExcept ion e) { | |
| 535 | logger .error("Co uldn't rea d the cdso utput xml. "); | |
| 536 | } ca tch (JAXBE xception e ) { | |
| 537 | logger .error("Co uldn't unm arshal the cdsoutput xml to CD SOutput ob ject."); | |
| 538 | } | |
| 539 | retu rn output; | |
| 540 | } | |
| 541 | ||
| 542 | pu blic Strin g parseVpr JsonToVmrX ml(String json) { | |
| 543 | Stri ng vmrXML = null; | |
| 544 | Obje ctMapper m apper = ne w ObjectMa pper(); | |
| 545 | ||
| 546 | Json Node rootN ode = null ; | |
| 547 | try { | |
| 548 | rootNo de = mappe r.readTree (json); | |
| 549 | } ca tch (IOExc eption e) { | |
| 550 | logger .error("Co uldn't rea d the json vpr data. "); | |
| 551 | } | |
| 552 | ||
| 553 | Json Node dataN ode = root Node.path( "data"); | |
| 554 | Json Node items Node = dat aNode.path ("items"); | |
| 555 | if ( itemsNode != null && itemsNode .has(0)) { | |
| 556 | JsonNo de item = itemsNode. get(0); | |
| 557 | String birthDate = item.pa th("birthD ate").asTe xt(); | |
| 558 | String gender = item.path( "genderCod e").asText (); | |
| 559 | JsonNo de exposur eNode = it em.path("e xposure"); | |
| 560 | if (ex posureNode .isMissing Node()) { | |
| 561 | vmrXML = marshalTo VmrXml("Un known", bi rthDate, " " + gender .charAt(ge nder.lengt h() - 1)); | |
| 562 | return v mrXML; | |
| 563 | } | |
| 564 | for (I terator<Js onNode> it erator = e xposureNod e.iterator (); iterat or.hasNext ();) { | |
| 565 | JsonNode exposure = iterator .next(); | |
| 566 | String u id = expos ure.path(" uid").asTe xt(); | |
| 567 | // uid: "urn:va:ag ent-orange :N" | |
| 568 | if (uid. contains(" agent-oran ge")) { | |
| 569 | String nam e = exposu re.path("n ame").asTe xt(); | |
| 570 | if (name ! = null) { | |
| 571 | vm rXML = mar shalToVmrX ml(name, b irthDate, "" + gende r.charAt(g ender.leng th() - 1)) ; | |
| 572 | re turn vmrXM L; | |
| 573 | } | |
| 574 | } | |
| 575 | } | |
| 576 | } | |
| 577 | retu rn vmrXML; | |
| 578 | } | |
| 579 | ||
| 580 | pr ivate Stri ng marshal ToVmrXml(S tring expo sure, Stri ng birthTi me, String sex) { | |
| 581 | CDSI nput input = new CDS Input(); | |
| 582 | II i nputId = n ew II(); | |
| 583 | inpu tId.setRoo t(INPUT_ID _ROOT); | |
| 584 | inpu t.getTempl ateId().ad d(inputId) ; | |
| 585 | ||
| 586 | VMR vmr = new VMR(); | |
| 587 | II t emplateId = new II() ; | |
| 588 | temp lateId.set Root(TEMPL ATE_ID_ROO T); | |
| 589 | vmr. getTemplat eId().add( templateId ); | |
| 590 | Eval uatedPerso n patient = new Eval uatedPerso n(); | |
| 591 | II r ootId = ne w II(); | |
| 592 | root Id.setRoot (ROOT_ID); | |
| 593 | root Id.setExte nsion(ROOT _EXTENSION ); | |
| 594 | pati ent.setId( rootId); | |
| 595 | Demo graphics d em = new D emographic s(); | |
| 596 | TS t s = new TS (); | |
| 597 | ts.s etValue(bi rthTime); | |
| 598 | dem. setBirthTi me(ts); | |
| 599 | CD g ender = ne w CD(); | |
| 600 | gend er.setCode (sex); | |
| 601 | gend er.setCode System(GEN DER_CODE_S YSTEM); | |
| 602 | gend er.setOrig inalText(s ex); | |
| 603 | dem. setGender( gender); | |
| 604 | pati ent.setDem ographics( dem); | |
| 605 | Eval uatedPerso n.Clinical Statements statement s = new Ev aluatedPer son.Clinic alStatemen ts(); | |
| 606 | ||
| 607 | Enco unterEvent s ees = ne w Evaluate dPerson.Cl inicalStat ements.Enc ounterEven ts(); | |
| 608 | Enco unterEvent ee = new EncounterE vent(); | |
| 609 | ee.s etId(rootI d); | |
| 610 | IVLT S eventTim e = new IV LTS(); | |
| 611 | even tTime.setL ow(EVENT_T IME); | |
| 612 | even tTime.setH igh(EVENT_ TIME); | |
| 613 | ee.s etEncounte rEventTime (eventTime ); | |
| 614 | ||
| 615 | CD c oncept = n ew CD(); | |
| 616 | conc ept.setCod e(CONCEPT_ CODE); | |
| 617 | conc ept.setCod eSystem("s nomed"); | |
| 618 | conc ept.setCod eSystemNam e("snomed" ); | |
| 619 | conc ept.setDis playName(e xposure); | |
| 620 | conc ept.setOri ginalText( "agent-ora nge"); | |
| 621 | ee.s etEncounte rType(conc ept); | |
| 622 | ees. getEncount erEvent(). add(ee); | |
| 623 | stat ements.set EncounterE vents(ees) ; | |
| 624 | ||
| 625 | pati ent.setCli nicalState ments(stat ements); | |
| 626 | vmr. setPatient (patient); | |
| 627 | inpu t.setVmrIn put(vmr); | |
| 628 | Stri ng result = null; | |
| 629 | try { | |
| 630 | result = jaxbMar shal(input ); | |
| 631 | } ca tch (JAXBE xception | IOExcepti on e) { | |
| 632 | logger .error("CD SInput cou ldn't be m arshalled to xml."); | |
| 633 | } | |
| 634 | ||
| 635 | retu rn result; | |
| 636 | } | |
| 637 | ||
| 638 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.