Produced by Araxis Merge on 11/29/2018 1:28:44 PM Eastern Standard 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 | PPMS Build 9.zip\CIF B10S1\VA.PPMS.IWS\VA.PPMS.IWS\VA.PPMS.IWS.CreateResponseService | CreateResponseService.cs | Tue Nov 20 19:11:38 2018 UTC |
| 2 | PPMS Build 9.zip\CIF B10S1\VA.PPMS.IWS\VA.PPMS.IWS\VA.PPMS.IWS.CreateResponseService | CreateResponseService.cs | Tue Nov 27 21:28:06 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 1124 |
| 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 | using Hl7. Fhir.Model ; | |
| 2 | using Hl7. Fhir.Seria lization; | |
| 3 | using log4 net; | |
| 4 | using Micr osoft.Azur e.KeyVault ; | |
| 5 | using Micr osoft.Iden tityModel. Clients.Ac tiveDirect ory; | |
| 6 | using Micr osoft.Xrm. Sdk; | |
| 7 | using Syst em; | |
| 8 | using Syst em.Collect ions.Gener ic; | |
| 9 | using Syst em.IO; | |
| 10 | using Syst em.Linq; | |
| 11 | using Syst em.Net; | |
| 12 | using Syst em.Net.Htt p; | |
| 13 | using Syst em.Net.Htt p.Headers; | |
| 14 | using Syst em.Securit y.Cryptogr aphy.X509C ertificate s; | |
| 15 | using Syst em.Service Model; | |
| 16 | using Syst em.Text; | |
| 17 | using Syst em.Threadi ng.Tasks; | |
| 18 | using VA.P PMS.Contex t; | |
| 19 | using VA.P PMS.Contex t.Interfac e; | |
| 20 | using VA.P PMS.IWS.Co mmon; | |
| 21 | using VA.P PMS.IWS.Cr eateRespon seService. Interface; | |
| 22 | using VA.P PMS.IWS.Fu nctions.Co nfiguratio n.Interfac e; | |
| 23 | using VA.P PMS.IWS.Qu eueService .Interface ; | |
| 24 | using VA.P PMS.Provid erData; | |
| 25 | ||
| 26 | namespace VA.PPMS.IW S.CreateRe sponseServ ice | |
| 27 | { | |
| 28 | public class Cre ateRespons eService : ICreateRe sponseServ ice | |
| 29 | { | |
| 30 | pr ivate read only ILog _logger; | |
| 31 | pr ivate read only IIwsC onfigurati on _config uration; | |
| 32 | pr ivate read only IQueu eService _ queueServi ce; | |
| 33 | pr ivate read only IPpms Helper _pp msHelper; | |
| 34 | pr ivate read only IPpms ContextHel per _conte xtHelper; | |
| 35 | ||
| 36 | pu blic Creat eResponseS ervice(ILo g logger, IIwsConfig uration co nfiguratio n, IQueueS ervice que ueService, IPpmsHelp er ppmsHel per, IPpms ContextHel per contex tHelper) | |
| 37 | { | |
| 38 | _logger = logger; | |
| 39 | _configu ration = c onfigurati on; | |
| 40 | _queueSe rvice = qu eueService ; | |
| 41 | _ppmsHel per = ppms Helper; | |
| 42 | _context Helper = c ontextHelp er; | |
| 43 | } | |
| 44 | ||
| 45 | pu blic async Task<stri ng> Create Response(D asMessage message) | |
| 46 | { | |
| 47 | _logger. Info($"@@@ @ INFO - S tart Creat eResponseS ervice.Cre ateRespons e @@@@"); | |
| 48 | ||
| 49 | try | |
| 50 | { | |
| 51 | var batchId = Utilities. ValidateGu id(message .Content); | |
| 52 | if ( string.IsN ullOrEmpty (batchId)) | |
| 53 | { | |
| 54 | _logger.In fo($"@@@@ INFO - Bat ch ID not provided f or BatchId : {batchId } @@@@"); | |
| 55 | throw new PpmsServic eException ($"CreateR esponseSer vice.Creat eResponse - Batch ID not provi ded for Ba tch {messa ge.Transac tionId}.") ; | |
| 56 | } | |
| 57 | ||
| 58 | // C reate XML response f ile | |
| 59 | var response = await Cre ateRespons eDocument( message); | |
| 60 | ||
| 61 | _log ger.Info($ "@@@@ INFO - End Mai n Create R esponse Se rvice for BatchId: { batchId} @ @@@"); | |
| 62 | ||
| 63 | retu rn respons e; | |
| 64 | } | |
| 65 | catch (E xception e x) | |
| 66 | { | |
| 67 | _log ger.Error( $"@@@@ ERR OR - There was a pro blem with the Create ResponseSe rvice. @@@ @", ex); | |
| 68 | thro w new Ppms ServiceExc eption($"T here was a problem w ith the Cr eateRespon seService. ", ex); | |
| 69 | } | |
| 70 | } | |
| 71 | ||
| 72 | pu blic async Task<stri ng> Create ProviderPa yload(DasM essage mes sage) | |
| 73 | { | |
| 74 | _logger. Info($"@@@ @ INFO - S tart Creat eResponseS ervice.Cre ateProvide rPayload @ @@@"); | |
| 75 | ||
| 76 | try | |
| 77 | { | |
| 78 | // C reate XML response f ile | |
| 79 | var response = await Cre ateProvide rXmlDoc(me ssage); | |
| 80 | ||
| 81 | _log ger.Info($ "@@@@ INFO - End Mai n Create R esponse Se rvice for BatchId: { Utilities. ValidateGu id(message .Content)} @@@@"); | |
| 82 | ||
| 83 | retu rn respons e; | |
| 84 | } | |
| 85 | catch (E xception e x) | |
| 86 | { | |
| 87 | _log ger.Error( $"@@@@ ERR OR - There was a pro blem with the Create ResponseSe rvice @@@@ ", ex); | |
| 88 | thro w new Ppms ServiceExc eption($"T here was a problem w ith the Cr eateRespon seService. ", ex); | |
| 89 | } | |
| 90 | } | |
| 91 | ||
| 92 | pu blic async Task Noti fyOfRespon se(DasMess age messag e) | |
| 93 | { | |
| 94 | try | |
| 95 | { | |
| 96 | // P arse base6 4 string t o extract guid | |
| 97 | var shortGuid = ShortGui d.Parse(me ssage.Cont ent); | |
| 98 | var batchId = shortGuid. ToGuid().T oString(); | |
| 99 | ||
| 100 | var batch = aw ait GetBat chById(bat chId); | |
| 101 | if ( batch == n ull) throw new PpmsS erviceExce ption("Una ble to fin d batch re cord."); | |
| 102 | ||
| 103 | // R etrieve Re ceiverId f rom associ ated netwo rk | |
| 104 | if ( batch.ppms _vaprovide rnetwork_b atch_netwo rk == null ) throw ne w PpmsServ iceExcepti on("Unable to determ ine associ ated netwo rk."); | |
| 105 | ||
| 106 | // S et header values | |
| 107 | mess age.Conver sationId = batch.ppm s_conversa tionid; | |
| 108 | mess age.Receiv erId = bat ch.ppms_va providerne twork_batc h_network. ppms_short hand; | |
| 109 | ||
| 110 | // G et URL pat hs from co nfiguratio n | |
| 111 | var baseUrl = await _con figuration .GetPpmsRe sponseNoti ficationUr iAsync(mes sage.IsVaR eceiver); | |
| 112 | var requestUri = await _ configurat ion.GetPpm sResponseP ostUriAsyn c(message. IsVaReceiv er); | |
| 113 | ||
| 114 | stri ng result; | |
| 115 | if ( message.Is VaReceiver ) | |
| 116 | { | |
| 117 | var payloa d = await CreateResp onseDocume nt(message ); | |
| 118 | result = a wait PostX mlToDas(me ssage, pay load, base Url, reque stUri); | |
| 119 | } | |
| 120 | else | |
| 121 | { | |
| 122 | var docume ntRef = aw ait Create DocumentRe ference(ba tch.ppms_c onversatio nid); | |
| 123 | result = a wait PostT oDas(messa ge, docume ntRef, bas eUrl, requ estUri); | |
| 124 | } | |
| 125 | ||
| 126 | var logId = Ut ilities.Va lidateGuid (message.C ontent); | |
| 127 | _log ger.Info($ "Updating batch: {lo gId}"); | |
| 128 | ||
| 129 | if ( !string.Is NullOrEmpt y(result)) | |
| 130 | { | |
| 131 | await _ppm sHelper.Up dateBatch( message, $ "Response notificati on sent: { logId}", ( int)ppms_b atch_Statu sCode.Rece iverNotifi ed); | |
| 132 | } | |
| 133 | } | |
| 134 | catch (E xception e x) | |
| 135 | { | |
| 136 | _log ger.Error( "CreateRes ponseServi ce.NotifyO fResponse: Unable to process r esponse.") ; | |
| 137 | thro w new Ppms ServiceExc eption("Cr eateRespon seService. NotifyOfRe sponse: Un able to pr ocess resp onse.", ex ); | |
| 138 | } | |
| 139 | } | |
| 140 | ||
| 141 | pr ivate asyn c Task<str ing> PostX mlToDas(Da sMessage m essage, st ring xmlCo ntent, str ing baseUr i, string requestUri ) | |
| 142 | { | |
| 143 | var clie nt = (Http WebRequest )WebReques t.Create($ "{baseUri} {requestUr i}"); | |
| 144 | client.C ontentType = "applic ation/xml" ; | |
| 145 | client.M ethod = "P OST"; | |
| 146 | client.A ccept = "a pplication /xml"; | |
| 147 | // Set D AS headers | |
| 148 | client.H eaders.Add ("X-Conver sationID", message.C onversatio nId); | |
| 149 | client.H eaders.Add ("X-Routin gSenderID" , message. SenderId); | |
| 150 | client.H eaders.Add ("X-Routin gReceiverI Ds", messa ge.Receive rId); | |
| 151 | client.H eaders.Add ("X-Transa ctionID", message.Tr ansactionI d); | |
| 152 | ||
| 153 | _logger. Info($"XML Output: { xmlContent }"); | |
| 154 | using (v ar streamW riter = ne w StreamWr iter(clien t.GetReque stStream() )) | |
| 155 | { | |
| 156 | stre amWriter.W rite(xmlCo ntent); | |
| 157 | stre amWriter.F lush(); | |
| 158 | stre amWriter.C lose(); | |
| 159 | } | |
| 160 | ||
| 161 | var http Response = (HttpWebR esponse)(a wait clien t.GetRespo nseAsync() ); | |
| 162 | return " Success"; | |
| 163 | ||
| 164 | throw ne w PpmsServ iceExcepti on($"Error Posting R esponse No tification ."); | |
| 165 | } | |
| 166 | ||
| 167 | pr ivate asyn c Task<str ing> PostT oDas(DasMe ssage mess age, Docum entReferen ce content , string b aseUri, st ring reque stUri) | |
| 168 | { | |
| 169 | using (v ar client = await Ge tHttpClien t()) | |
| 170 | { | |
| 171 | clie nt.BaseAdd ress = new Uri(baseU ri); | |
| 172 | // S et DAS hea ders | |
| 173 | clie nt.Default RequestHea ders.Accep t.Clear(); | |
| 174 | clie nt.Default RequestHea ders.Accep t.Add(new MediaTypeW ithQuality HeaderValu e("applica tion/json+ fhir")); | |
| 175 | clie nt.Default RequestHea ders.Add(" X-Conversa tionID", m essage.Con versationI d); | |
| 176 | clie nt.Default RequestHea ders.Add(" X-RoutingS enderID", message.Se nderId); | |
| 177 | clie nt.Default RequestHea ders.Add(" X-RoutingR eceiverIDs ", message .ReceiverI d); | |
| 178 | clie nt.Default RequestHea ders.Add(" X-Transact ionID", me ssage.Tran sactionId) ; | |
| 179 | ||
| 180 | var sout = new FhirJsonS erializer( ); | |
| 181 | var strDocRef = sout.Ser ializeToSt ring(conte nt); | |
| 182 | var docRef = n ew StringC ontent(str DocRef, En coding.Def ault, "app lication/j son+fhir") ; | |
| 183 | ||
| 184 | docR ef.Headers .ContentTy pe.CharSet = string. Empty; | |
| 185 | ||
| 186 | //va r response = await c lient.Post Async(requ estUri, ne w ObjectCo ntent(type of(Documen tReference ), content , new NoCh arSetJsonM ediaTypeFo rmatter(), "applicat ion/json+f hir")); | |
| 187 | var response = await cli ent.PostAs ync(reques tUri, docR ef); | |
| 188 | ||
| 189 | if ( response.I sSuccessSt atusCode) return "Su ccess"; | |
| 190 | ||
| 191 | thro w new Ppms ServiceExc eption($"E rror Posti ng Respons e Notifica tion to DA S. The err or is {res ponse.Stat usCode.ToS tring()}") ; | |
| 192 | } | |
| 193 | } | |
| 194 | ||
| 195 | pr ivate asyn c Task<Doc umentRefer ence> Crea teDocument Reference( string con versationI d) | |
| 196 | { | |
| 197 | // Const ruct call back URL | |
| 198 | //var re ferencePat h = await _configura tion.GetRe sponseDocu mentRefere nceUrlAsyn c(); | |
| 199 | var docu mentPath = await Get DocumentPa th(convers ationId); | |
| 200 | var cont ent = new List<Docum entReferen ce.Content Component> | |
| 201 | { | |
| 202 | new DocumentRe ference.Co ntentCompo nent { Att achment = new Attach ment { Con tentType = "applicat ion/xml", Url = $"{d ocumentPat h}" } } | |
| 203 | }; | |
| 204 | ||
| 205 | // Set D ocumentRef erence pro perties | |
| 206 | var docR ef = new D ocumentRef erence | |
| 207 | { | |
| 208 | Cust odian = ne w Resource Reference( "PPMS"), | |
| 209 | Crea ted = Date Time.Now.T oString("s ", System. Globalizat ion.Cultur eInfo.Inva riantCultu re), | |
| 210 | Inde xed = new DateTimeOf fset(DateT ime.Now), | |
| 211 | Stat us = Docum entReferen ceStatus.C urrent, | |
| 212 | Cont ent = cont ent | |
| 213 | }; | |
| 214 | ||
| 215 | return d ocRef; | |
| 216 | } | |
| 217 | ||
| 218 | pr ivate asyn c Task<str ing> GetDo cumentPath (string co nversation Id) | |
| 219 | { | |
| 220 | if (stri ng.IsNullO rEmpty(con versationI d)) | |
| 221 | { | |
| 222 | _log ger.Info($ "@@@@ INFO - Paramet er invalid for Conve rsationId = {convers ationId} @ @@@"); | |
| 223 | thro w new Ppms ServiceExc eption("Un able to cr eate docum ent path, parameter invalid"); | |
| 224 | } | |
| 225 | ||
| 226 | //{ rela tive - pat h}/ Binary /[documen tURN] ? tr ansactionI D ={ uniqu e ID} | |
| 227 | var rela tivePathPa ttern = aw ait _confi guration.G etResponse DocumentPa thPatternA sync(); | |
| 228 | return s tring.Form at(relativ ePathPatte rn, conver sationId); | |
| 229 | } | |
| 230 | ||
| 231 | pr ivate asyn c Task<ppm s_batch> G etBatchByI d(string b atchId) | |
| 232 | { | |
| 233 | var cont ext = awai t _context Helper.Get ContextAsy nc(); | |
| 234 | var batc h = contex t.ppms_bat chSet.Firs tOrDefault (b => b.pp ms_batchId == new Gu id(batchId )); | |
| 235 | ||
| 236 | LoadBatc hPropertie s(context, batch); | |
| 237 | ||
| 238 | return b atch; | |
| 239 | } | |
| 240 | ||
| 241 | pr ivate asyn c Task<ppm s_batch> G etBatchByC onversatio nId(string conversat ionId) | |
| 242 | { | |
| 243 | var cont ext = awai t _context Helper.Get ContextAsy nc(); | |
| 244 | var batc h = contex t.ppms_bat chSet.Firs tOrDefault (b => b.pp ms_convers ationid == conversat ionId); | |
| 245 | ||
| 246 | LoadBatc hPropertie s(context, batch); | |
| 247 | ||
| 248 | return b atch; | |
| 249 | } | |
| 250 | ||
| 251 | pr ivate void LoadBatch Properties (PpmsConte xt context , ppms_bat ch batch) | |
| 252 | { | |
| 253 | if (batc h == null) throw new PpmsServi ceExceptio n("Batch r ecord does not exist "); | |
| 254 | ||
| 255 | context. LoadProper ty(batch, new Relati onship("pp ms_batch_b atchdetail _batch")); | |
| 256 | context. LoadProper ty(batch, new Relati onship("pp ms_vaprovi dernetwork _batch_net work")); | |
| 257 | ||
| 258 | if (batc h.ppms_bat ch_batchde tail_batch != null) | |
| 259 | { | |
| 260 | fore ach (var i tem in bat ch.ppms_ba tch_batchd etail_batc h) | |
| 261 | { | |
| 262 | context.Lo adProperty (item, new Relations hip("ppms_ batchdetai l_batchdet ailresult" )); | |
| 263 | } | |
| 264 | } | |
| 265 | } | |
| 266 | ||
| 267 | pu blic async Task<stri ng> Create ResponseDo cument(Das Message qu eueMessage ) | |
| 268 | { | |
| 269 | try | |
| 270 | { | |
| 271 | if ( string.IsN ullOrEmpty (queueMess age.Conver sationId)) | |
| 272 | { | |
| 273 | _logger.In fo($"@@@@ INFO - Par ameter inv alid for i tem @@@@") ; | |
| 274 | return str ing.Empty; | |
| 275 | } | |
| 276 | ||
| 277 | var conversati onId = que ueMessage. Conversati onId; | |
| 278 | var batch = aw ait GetBat chByConver sationId(c onversatio nId); | |
| 279 | ||
| 280 | var details = batch.ppms _batch_bat chdetail_b atch; | |
| 281 | IEnu merable<pp ms_batchde tail> ppms Batchdetai ls = detai ls as ppms _batchdeta il[] ?? de tails.ToAr ray(); | |
| 282 | if ( !ppmsBatch details.An y()) | |
| 283 | { | |
| 284 | _logger.In fo($"@@@@ INFO - Det ails not f ound @@@@" ); | |
| 285 | return str ing.Empty; | |
| 286 | } | |
| 287 | ||
| 288 | _log ger.Info($ "@@@@ INFO - Details found @@@ @"); | |
| 289 | ||
| 290 | // C reate XML doc | |
| 291 | var doc = new ProviderRe sponses | |
| 292 | { | |
| 293 | ProviderRe sponse = n ew List<Pr oviderResp onse>() | |
| 294 | }; | |
| 295 | ||
| 296 | // C apture bat ch details | |
| 297 | fore ach (var d etail in p pmsBatchde tails) | |
| 298 | { | |
| 299 | // Provide r node | |
| 300 | var provid er = new P roviderRes ponse | |
| 301 | { | |
| 302 | Provid erId = det ail.ppms_p roviderid, | |
| 303 | Succes s = detail .GetAttrib uteValue<b ool>("ppms _isvalid") | |
| 304 | }; | |
| 305 | ||
| 306 | // Set cor relation i d, if appr opriate | |
| 307 | if (detail .ppms_prov ider != nu ll) | |
| 308 | { | |
| 309 | provid er.Correla tionId = d etail.ppms _provider. Id.ToStrin g(); | |
| 310 | } | |
| 311 | ||
| 312 | // Retriev e batch de tail resul ts | |
| 313 | var batchD etailResul ts = detai l.ppms_bat chdetail_b atchdetail result; | |
| 314 | ||
| 315 | // Capture batch det ail result s | |
| 316 | IEnumerabl e<ppms_bat chdetailre sult> ppms Batchdetai lresults = batchDeta ilResults as ppms_ba tchdetailr esult[] ?? batchDeta ilResults. ToArray(); | |
| 317 | if (ppmsBa tchdetailr esults.Any ()) | |
| 318 | { | |
| 319 | // Ini tialize re sults list | |
| 320 | provid er.Results = new Res ults { Ite m = new Li st<Result> () }; | |
| 321 | ||
| 322 | foreac h (var det ailResult in ppmsBat chdetailre sults) | |
| 323 | { | |
| 324 | va r result = new Resul t | |
| 325 | { | |
| 326 | Type = d etailResul t.ppms_ent itytype, | |
| 327 | Id = det ailResult. ppms_name, | |
| 328 | Success = detailRe sult.ppms_ isvalid.Ha sValue && detailResu lt.ppms_is valid.Valu e | |
| 329 | }; | |
| 330 | ||
| 331 | if (result.T ype == "Pr oviderServ ice") | |
| 332 | { | |
| 333 | result.C orrelation Id = detai lResult.Id .ToString( ); | |
| 334 | } | |
| 335 | ||
| 336 | if (!result. Success) | |
| 337 | { | |
| 338 | result.H eader = de tailResult .ppms_resu lt; | |
| 339 | result.M essage = d etailResul t.ppms_mes sage; | |
| 340 | } | |
| 341 | ||
| 342 | pr ovider.Res ults.Item. Add(result ); | |
| 343 | } | |
| 344 | } | |
| 345 | else | |
| 346 | { | |
| 347 | _logge r.Info($"@ @@@ INFO - Results n ot found f or provide r: {detail .ppms_name } @@@@"); | |
| 348 | } | |
| 349 | ||
| 350 | // Add to list of pr oviders | |
| 351 | doc.Provid erResponse .Add(provi der); | |
| 352 | } | |
| 353 | ||
| 354 | // C reate resp onse packe t | |
| 355 | var responseTo Send = awa it Convert ResponseTo Xml(doc); | |
| 356 | ||
| 357 | // C lose batch | |
| 358 | awai t _ppmsHel per.Update Batch(queu eMessage, "CCN Respo nse sent." , (int)ppm s_batch_St atusCode.C omplete); | |
| 359 | ||
| 360 | _log ger.Info($ "@@@@ INFO - Save co mplete @@@ @"); | |
| 361 | ||
| 362 | retu rn respons eToSend; | |
| 363 | } | |
| 364 | catch (F aultExcept ion<Organi zationServ iceFault> ex) | |
| 365 | { | |
| 366 | _log ger.Error( $"@@@@ Cre ateRespons eService E RROR - Fau lt: {ex} @ @@@", ex); | |
| 367 | thro w; | |
| 368 | } | |
| 369 | catch (E xception e x) | |
| 370 | { | |
| 371 | _log ger.Error( $"@@@@ Cre ateRespons eService E RROR - Exc eption: {e x} @@@@", ex); | |
| 372 | thro w; | |
| 373 | } | |
| 374 | } | |
| 375 | ||
| 376 | pu blic async Task<stri ng> Create ProviderXm lDoc(DasMe ssage queu eMessage) | |
| 377 | { | |
| 378 | try | |
| 379 | { | |
| 380 | if ( string.IsN ullOrEmpty (queueMess age.Conten t)) | |
| 381 | { | |
| 382 | _logger.In fo($"@@@@ INFO - Bat ch ID not provided. @@@@"); | |
| 383 | return str ing.Empty; | |
| 384 | } | |
| 385 | ||
| 386 | var batchId = queueMessa ge.Content ; | |
| 387 | var batch = aw ait GetBat chById(bat chId); | |
| 388 | ||
| 389 | retu rn await E xportBatch ToXml(batc h); | |
| 390 | } | |
| 391 | catch (E xception e x) | |
| 392 | { | |
| 393 | _log ger.Info($ "!!!! ERRO R - Error occured cr eated prov ider XML d ocument. ! !!!", ex); | |
| 394 | } | |
| 395 | ||
| 396 | return s tring.Empt y; | |
| 397 | } | |
| 398 | ||
| 399 | pr ivate asyn c Task<str ing> Conve rtResponse ToXml(Prov iderRespon ses respon se) | |
| 400 | { | |
| 401 | var pack et = await _configur ation.GetS chemaProfi leAsync(Sc hemaOption s.SchemaPr ofiles.Res ponse); | |
| 402 | ||
| 403 | var pref ix = packe t.Prefix; | |
| 404 | var name Space = pa cket.Names pace; | |
| 405 | ||
| 406 | return U tilities.S erializeIn stance(res ponse, pre fix, nameS pace); | |
| 407 | } | |
| 408 | ||
| 409 | pr ivate asyn c Task<str ing> Expor tBatchToXm l(ppms_bat ch batch) | |
| 410 | { | |
| 411 | Context. Account ac count = nu ll; | |
| 412 | ||
| 413 | if (batc h.ppms_bat ch_batchde tail_batch == null) return str ing.Empty; | |
| 414 | ||
| 415 | var prov iders = ne w List<Pro vider>(); | |
| 416 | ||
| 417 | foreach (var item in batch.p pms_batch_ batchdetai l_batch) | |
| 418 | { | |
| 419 | acco unt = awai t GetProvi der(item.p pms_provid er.Id); | |
| 420 | if ( account != null) | |
| 421 | { | |
| 422 | // convert provider to XML | |
| 423 | providers. Add(ToProv ider(accou nt)); | |
| 424 | } | |
| 425 | } | |
| 426 | ||
| 427 | var xml = Utilities. SerializeI nstance(pr oviders, " p", "https :// DNS . URL /exchange/ ccn/1.0"); | |
| 428 | xml = xm l.Replace( "ArrayOfPr ovider", " Providers" ); | |
| 429 | ||
| 430 | return x ml; | |
| 431 | } | |
| 432 | ||
| 433 | pr ivate asyn c Task<Con text.Accou nt> GetPro vider(Guid providerI d) | |
| 434 | { | |
| 435 | var cont ext = awai t _context Helper.Get ContextAsy nc(); | |
| 436 | var enti ty = conte xt.Account Set.FirstO rDefault(b => b.Id = = provider Id); | |
| 437 | if (enti ty == null ) throw ne w PpmsServ iceExcepti on("Batch record doe s not exis t"); | |
| 438 | ||
| 439 | LoadProv iderProper ties(entit y, context ); | |
| 440 | ||
| 441 | return e ntity; | |
| 442 | } | |
| 443 | ||
| 444 | pr otected vo id LoadPro viderPrope rties(Enti ty entity, PpmsConte xt context ) | |
| 445 | { | |
| 446 | if (enti ty == null || contex t == null) return; | |
| 447 | ||
| 448 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ providerid entifier_P rovider"); | |
| 449 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ providerse rvice"); | |
| 450 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ boardcerti fication") ; | |
| 451 | context. LoadProper ty(entity, "ppms_acc ount_organ izationaut horizedoff icial"); | |
| 452 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ otherprovi deridentif ier"); | |
| 453 | context. LoadProper ty(entity, "contact_ customer_a ccounts"); | |
| 454 | context. LoadProper ty(entity, "ppms_acc ount_provi derlicensu re"); | |
| 455 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ othername" ); | |
| 456 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ providerta xonomy"); | |
| 457 | context. LoadProper ty(entity, "ppms_acc ount_deasc hedulepriv ilege"); | |
| 458 | context. LoadProper ty(entity, "ppms_acc ount_provi dernetwork id"); | |
| 459 | } | |
| 460 | ||
| 461 | pr ivate Prov ider ToPro vider(Cont ext.Accoun t account) | |
| 462 | { | |
| 463 | if (acco unt == nul l) return null; | |
| 464 | ||
| 465 | var prov ider = new Provider( ); | |
| 466 | ||
| 467 | // Map p roperties | |
| 468 | provider .Email = a ccount.EMa ilAddress1 ; | |
| 469 | provider .Phone = a ccount.Tel ephone1; | |
| 470 | provider .Fax = acc ount.Fax; | |
| 471 | ||
| 472 | // Addre ss | |
| 473 | var addr ess = new ProviderDa ta.Address (); | |
| 474 | address. Address1 = account.A ddress1_Li ne1; | |
| 475 | address. Address2 = account.A ddress1_Li ne2; | |
| 476 | address. Address3 = account.A ddress1_Li ne3; | |
| 477 | address. City = acc ount.Addre ss1_City; | |
| 478 | address. State = ac count.Addr ess1_State OrProvince ; | |
| 479 | address. PostalCode = account .Address1_ PostalCode ; | |
| 480 | address. County = a ccount.Add ress1_Coun ty; | |
| 481 | ||
| 482 | provider .Address = address; | |
| 483 | ||
| 484 | // NPIs | |
| 485 | var npis = new Lis t<Npi>(); | |
| 486 | var npi = new Npi( ); | |
| 487 | npi.Numb er = accou nt.ppms_Pr oviderIden tifier; | |
| 488 | provider .Npis = ne w Npis() { Item = np is }; | |
| 489 | ||
| 490 | // Speci alties | |
| 491 | if (acco unt.ppms_a ccount_ppm s_provider taxonomy ! = null) | |
| 492 | { | |
| 493 | var specialtie s = new Li st<Taxonom y>(); | |
| 494 | fore ach (var i tem in acc ount.ppms_ account_pp ms_provide rtaxonomy) | |
| 495 | { | |
| 496 | specialtie s.Add(new Taxonomy() { CodedSp ecialty = item.ppms_ codedspeci alty }); | |
| 497 | } | |
| 498 | prov ider.Speci alties = n ew Special ties() { I tem = spec ialties }; | |
| 499 | } | |
| 500 | ||
| 501 | // Name | |
| 502 | var indi vidual = n ew Individ ual(); | |
| 503 | var name s = accoun t.Name.Spl it(','); | |
| 504 | individu al.FirstNa me = names [0].Trim() ; | |
| 505 | individu al.LastNam e = names[ 1].Trim(); | |
| 506 | individu al.MiddleN ame = ""; | |
| 507 | ||
| 508 | // DEA N umbers | |
| 509 | if (acco unt.ppms_a ccount_dea schedulepr ivilege != null) | |
| 510 | { | |
| 511 | var deaNumbers = new Lis t<DeaSched ulePrivile ge>(); | |
| 512 | fore ach (var i tem in acc ount.ppms_ account_de aschedulep rivilege) | |
| 513 | { | |
| 514 | deaNumbers .Add(new D eaSchedule Privilege( ) { DeaNum ber = item .ppms_dean umber }); | |
| 515 | } | |
| 516 | indi vidual.Dea Numbers = new DeaSch edulePrivi leges() { Item = dea Numbers }; | |
| 517 | } | |
| 518 | ||
| 519 | // Set p rovider ty pe | |
| 520 | var prov iderType = new Provi derType(); | |
| 521 | provider Type.Item = individu al; | |
| 522 | ||
| 523 | provider .Type = pr oviderType ; | |
| 524 | ||
| 525 | return p rovider; | |
| 526 | } | |
| 527 | ||
| 528 | #r egion Cert s | |
| 529 | ||
| 530 | pu blic async Task<Http Client> Ge tHttpClien t() | |
| 531 | { | |
| 532 | await Ta sk.Run(() => { }); | |
| 533 | var clie ntHandler = new Http ClientHand ler(); | |
| 534 | clientHa ndler.Clie ntCertific ates.Add(a wait GetCe rtKeyVault ()); | |
| 535 | ||
| 536 | return n ew HttpCli ent(client Handler); | |
| 537 | } | |
| 538 | ||
| 539 | pr ivate asyn c Task<X50 9Certifica te2> GetCe rtKeyVault () | |
| 540 | { | |
| 541 | var keyV aultClient = new Key VaultClien t(GetToken ); | |
| 542 | var resu lt = await keyVaultC lient.GetS ecretAsync (await _co nfiguratio n.GetDasCe rtUrl()); | |
| 543 | ||
| 544 | if (resu lt == null ) throw ne w InvalidO perationEx ception("F ailed to o btain the certificat e from Key Vault"); | |
| 545 | ||
| 546 | var secr et = Conve rt.FromBas e64String( result.Val ue); | |
| 547 | return n ew X509Cer tificate2( secret, (s tring)null ); | |
| 548 | } | |
| 549 | ||
| 550 | pr ivate asyn c Task<str ing> GetTo ken(string authority , string r esource, s tring scop e) | |
| 551 | { | |
| 552 | var auth Context = new Authen ticationCo ntext(auth ority); | |
| 553 | var clie ntCred = n ew ClientC redential( await _con figuration .GetDasApp Id(), awai t _configu ration.Get DasSecret( )); | |
| 554 | var resu lt = await authConte xt.Acquire TokenAsync (resource, clientCre d); | |
| 555 | ||
| 556 | if (resu lt == null ) throw ne w InvalidO perationEx ception("F ailed to o btain the token to r etrieve ce rtificate" ); | |
| 557 | ||
| 558 | return r esult.Acce ssToken; | |
| 559 | } | |
| 560 | ||
| 561 | #e ndregion | |
| 562 | } | |
| 563 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.