Produced by Araxis Merge on 8/27/2018 1:12:12 PM 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 | PPMS Build 8 Sprint 1.zip\PPMS Build 8 Sprint 1\CIF B8S1\VA.PPMS.IWS\VA.PPMS.IWS\VA.PPMS.IWS.CreateResponseService | CreateResponseService.cs | Tue Aug 14 18:51:14 2018 UTC |
| 2 | PPMS Build 8 Sprint 1.zip\PPMS Build 8 Sprint 1\CIF B8S1\VA.PPMS.IWS\VA.PPMS.IWS\VA.PPMS.IWS.CreateResponseService | CreateResponseService.cs | Wed Aug 15 18:49:43 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 964 |
| 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.Xrm. Sdk; | |
| 5 | using Syst em; | |
| 6 | using Syst em.Collect ions.Gener ic; | |
| 7 | using Syst em.Linq; | |
| 8 | using Syst em.Net.Htt p; | |
| 9 | using Syst em.Net.Htt p.Formatti ng; | |
| 10 | using Syst em.Net.Htt p.Headers; | |
| 11 | using Syst em.Threadi ng.Tasks; | |
| 12 | using VA.P PMS.Contex t; | |
| 13 | using VA.P PMS.Contex t.Interfac e; | |
| 14 | using VA.P PMS.IWS.Co mmon; | |
| 15 | using VA.P PMS.IWS.Cr eateRespon seService. Interface; | |
| 16 | using VA.P PMS.IWS.Fu nctions.Co nfiguratio n.Interfac e; | |
| 17 | using VA.P PMS.IWS.Qu eueService .Interface ; | |
| 18 | using VA.P PMS.Provid erData; | |
| 19 | using Syst em.Service Model; | |
| 20 | ||
| 21 | namespace VA.PPMS.IW S.CreateRe sponseServ ice | |
| 22 | { | |
| 23 | public class Cre ateRespons eService : ICreateRe sponseServ ice | |
| 24 | { | |
| 25 | pr ivate read only ILog _logger; | |
| 26 | pr ivate read only IIwsC onfigurati on _config uration; | |
| 27 | pr ivate read only IQueu eService _ queueServi ce; | |
| 28 | pr ivate read only IPpms Helper _pp msHelper; | |
| 29 | pr ivate read only IPpms ContextHel per _conte xtHelper; | |
| 30 | ||
| 31 | 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) | |
| 32 | { | |
| 33 | _logger = logger; | |
| 34 | _configu ration = c onfigurati on; | |
| 35 | _queueSe rvice = qu eueService ; | |
| 36 | _ppmsHel per = ppms Helper; | |
| 37 | _context Helper = c ontextHelp er; | |
| 38 | } | |
| 39 | ||
| 40 | pu blic async Task<stri ng> Create Response(D asMessage message) | |
| 41 | { | |
| 42 | _logger. Info($"@@@ @ INFO - S tart Creat eResponseS ervice for Transacti onId: { me ssage.Tran sactionId} @@@@"); | |
| 43 | ||
| 44 | try | |
| 45 | { | |
| 46 | var batchId = message.Co ntent; | |
| 47 | if ( string.IsN ullOrEmpty (batchId)) | |
| 48 | { | |
| 49 | _logger.In fo($"@@@@ INFO - Bat ch ID not provided f or Transac tionId: {m essage.Tra nsactionId } @@@@"); | |
| 50 | throw new PpmsServic eException ($"CreateR esponseSer vice - Bat ch ID not provided f or Transac tionId {me ssage.Tran sactionId} ."); | |
| 51 | } | |
| 52 | ||
| 53 | // C reate XML response f ile | |
| 54 | var response = await Cre ateRespons eDocument( message); | |
| 55 | ||
| 56 | _log ger.Info($ "@@@@ INFO - End Mai n Create R esponse Se rvice for Transactio nId: {mess age.Transa ctionId} B atchId: {b atchId} @@ @@"); | |
| 57 | ||
| 58 | retu rn respons e; | |
| 59 | } | |
| 60 | catch (E xception e x) | |
| 61 | { | |
| 62 | _log ger.Error( $"@@@@ ERR OR - There was a pro blem with theCreateR esponseSer vice for T ransaction Id {messag e.Transact ionId} @@@ @", ex); | |
| 63 | thro w new Ppms ServiceExc eption($"T here was a problem w ith the Ma in Orchest ration Ser vice for T ransaction Id {messag e.Transact ionId}.", ex); | |
| 64 | } | |
| 65 | } | |
| 66 | ||
| 67 | pu blic async Task<stri ng> Create ProviderPa yload(DasM essage mes sage) | |
| 68 | { | |
| 69 | _logger. Info($"@@@ @ INFO - S tart Creat eResponseS ervice for Transacti onId: { me ssage.Tran sactionId} @@@@"); | |
| 70 | ||
| 71 | try | |
| 72 | { | |
| 73 | // C reate XML response f ile | |
| 74 | var response = await Cre ateProvide rXmlDoc(me ssage); | |
| 75 | ||
| 76 | _log ger.Info($ "@@@@ INFO - End Mai n Create R esponse Se rvice for Transactio nId: {mess age.Transa ctionId} B atchId: {m essage.Con tent} @@@@ "); | |
| 77 | ||
| 78 | retu rn respons e; | |
| 79 | } | |
| 80 | catch (E xception e x) | |
| 81 | { | |
| 82 | _log ger.Error( $"@@@@ ERR OR - There was a pro blem with theCreateR esponseSer vice for T ransaction Id {messag e.Transact ionId} @@@ @", ex); | |
| 83 | thro w new Ppms ServiceExc eption($"T here was a problem w ith the Ma in Orchest ration Ser vice for T ransaction Id {messag e.Transact ionId}.", ex); | |
| 84 | } | |
| 85 | } | |
| 86 | ||
| 87 | pu blic async Task Noti fyOfRespon se(DasMess age messag e) | |
| 88 | { | |
| 89 | var batc hId = mess age.Conten t; | |
| 90 | ||
| 91 | try | |
| 92 | { | |
| 93 | var batch = aw ait GetBat ch(batchId ); | |
| 94 | if ( batch == n ull) throw new PpmsS erviceExce ption("Una ble to fin d batch re cord."); | |
| 95 | ||
| 96 | // R etrieve Re ceiverId f rom associ ated netwo rk | |
| 97 | if ( batch.ppms _vaprovide rnetwork_b atch_netwo rk == null ) throw ne w PpmsServ iceExcepti on("Unable to determ ine associ ated netwo rk."); | |
| 98 | ||
| 99 | // S et header values | |
| 100 | mess age.Conver sationId = batch.ppm s_conversa tionid; | |
| 101 | mess age.Receiv erId = bat ch.ppms_va providerne twork_batc h_network. ppms_short hand; | |
| 102 | ||
| 103 | var documentRe f = await CreateDocu mentRefere nce(batchI d, batch.p pms_conver sationid); | |
| 104 | ||
| 105 | // G et URL pat hs from co nfiguratio n | |
| 106 | var baseUrl = await _con figuration .GetPpmsRe sponseNoti ficationUr iAsync(); | |
| 107 | var requestUri = await _ configurat ion.GetPpm sResponseP ostUriAsyn c(); | |
| 108 | ||
| 109 | _log ger.Info($ "Posting t o DAS at U RL {baseUr l}{request Uri}"); | |
| 110 | _log ger.Info($ "---Messag e: 1:{mess age.Conver sationId}, 2:{messag e.SenderId }, 3:{mess age.Receiv erId}, 4:{ message.Se nderId}, 5 :{message. Content}") ; | |
| 111 | ||
| 112 | var result = a wait PostT oDas(messa ge, docume ntRef, bas eUrl, requ estUri); | |
| 113 | ||
| 114 | _log ger.Info($ "Updating batch: {ba tchId}"); | |
| 115 | ||
| 116 | if ( !string.Is NullOrEmpt y(result)) | |
| 117 | { | |
| 118 | await _ppm sHelper.Up dateBatch( message, $ "Response notificati on sent: { batchId}", (int)ppms _batch_Sta tusCode.Re ceiverNoti fied); | |
| 119 | } | |
| 120 | } | |
| 121 | catch (E xception e x) | |
| 122 | { | |
| 123 | _log ger.Error( "CreateRes ponseServi ce.NotifyO fResponse: Unable to process r esponse.") ; | |
| 124 | thro w new Ppms ServiceExc eption("Cr eateRespon seService. NotifyOfRe sponse: Un able to pr ocess resp onse.", ex ); | |
| 125 | } | |
| 126 | } | |
| 127 | ||
| 128 | pr ivate asyn c Task<str ing> PostT oDas(DasMe ssage mess age, Docum entReferen ce content , string b aseUri, st ring reque stUri) | |
| 129 | { | |
| 130 | using (v ar client = new Http Client()) | |
| 131 | { | |
| 132 | clie nt.BaseAdd ress = new Uri(baseU ri); | |
| 133 | // S et DAS hea ders | |
| 134 | clie nt.Default RequestHea ders.Accep t.Clear(); | |
| 135 | clie nt.Default RequestHea ders.Accep t.Add(new MediaTypeW ithQuality HeaderValu e("applica tion/json+ fhir")); | |
| 136 | clie nt.Default RequestHea ders.Add(" X-Conversa tionID", m essage.Con versationI d); | |
| 137 | clie nt.Default RequestHea ders.Add(" X-RoutingS enderID", message.Se nderId); | |
| 138 | clie nt.Default RequestHea ders.Add(" X-RoutingR eceiverIDs ", message .ReceiverI d); | |
| 139 | clie nt.Default RequestHea ders.Add(" X-Transact ionID", me ssage.Tran sactionId) ; | |
| 140 | ||
| 141 | var response = await cli ent.PostAs ync(reques tUri, new ObjectCont ent(typeof (DocumentR eference), content, new NoChar SetJsonMed iaTypeForm atter(), " applicatio n/json+fhi r")); | |
| 142 | ||
| 143 | if ( response.I sSuccessSt atusCode) return "Su ccess"; | |
| 144 | ||
| 145 | thro w new Ppms ServiceExc eption($"E rror Posti ng Respons e Notifica tion to DA S for tran saction {m essage.Tra nsactionId }. The err or is {res ponse.Stat usCode.ToS tring()}") ; | |
| 146 | } | |
| 147 | } | |
| 148 | ||
| 149 | pr ivate asyn c Task<Doc umentRefer ence> Crea teDocument Reference( string bat chId, stri ng convers ationId) | |
| 150 | { | |
| 151 | // Const ruct call back URL | |
| 152 | //var re ferencePat h = await _configura tion.GetRe sponseDocu mentRefere nceUrlAsyn c(); | |
| 153 | var docu mentPath = await Get DocumentPa th(batchId , conversa tionId); | |
| 154 | var cont ent = new List<Docum entReferen ce.Content Component> | |
| 155 | { | |
| 156 | new DocumentRe ference.Co ntentCompo nent { Att achment = new Attach ment { Con tentType = "applicat ion/xml", Url = $"{d ocumentPat h}" } } | |
| 157 | }; | |
| 158 | ||
| 159 | // Set D ocumentRef erence pro perties | |
| 160 | var docR ef = new D ocumentRef erence | |
| 161 | { | |
| 162 | Cust odian = ne w Resource Reference( "PPMS"), | |
| 163 | Crea ted = Date Time.Now.T oString("s ", System. Globalizat ion.Cultur eInfo.Inva riantCultu re), | |
| 164 | Inde xed = new DateTimeOf fset(DateT ime.Now), | |
| 165 | Stat us = Docum entReferen ceStatus.C urrent, | |
| 166 | Cont ent = cont ent | |
| 167 | }; | |
| 168 | ||
| 169 | return d ocRef; | |
| 170 | } | |
| 171 | ||
| 172 | pr ivate asyn c Task<str ing> GetDo cumentPath (string ba tchId, str ing conver sationId) | |
| 173 | { | |
| 174 | if (stri ng.IsNullO rEmpty(bat chId) || s tring.IsNu llOrEmpty( conversati onId)) | |
| 175 | { | |
| 176 | _log ger.Info($ "@@@@ INFO - Paramet er invalid for Batch Id: {batch Id}, Conve rsationId {conversat ionId} @@@ @"); | |
| 177 | thro w new Ppms ServiceExc eption("Un able to cr eate docum ent path, parameter invalid"); | |
| 178 | } | |
| 179 | ||
| 180 | //{ rela tive - pat h}/ Binary /[documen tURN] ? tr ansactionI D ={ uniqu e ID} | |
| 181 | //&reque stor ={ ES | PPMS | CUI etc.} | |
| 182 | //&purpo seOfUse = Treatment & dataSour ce ={ ES | PPMS | CU I etc.} | |
| 183 | var rela tivePathPa ttern = aw ait _confi guration.G etResponse DocumentPa thPatternA sync(); | |
| 184 | return s tring.Form at(relativ ePathPatte rn, batchI d, convers ationId); | |
| 185 | } | |
| 186 | ||
| 187 | pr ivate asyn c Task<ppm s_batch> G etBatch(st ring batch Id) | |
| 188 | { | |
| 189 | var cont ext = awai t _context Helper.Get ContextAsy nc(); | |
| 190 | var batc h = contex t.ppms_bat chSet.Firs tOrDefault (b => b.pp ms_batchId == new Gu id(batchId )); | |
| 191 | if (batc h == null) throw new PpmsServi ceExceptio n("Batch r ecord does not exist "); | |
| 192 | ||
| 193 | context. LoadProper ty(batch, new Relati onship("pp ms_batch_b atchdetail _batch")); | |
| 194 | context. LoadProper ty(batch, new Relati onship("pp ms_vaprovi dernetwork _batch_net work")); | |
| 195 | ||
| 196 | if (batc h.ppms_bat ch_batchde tail_batch != null) | |
| 197 | { | |
| 198 | fore ach (var i tem in bat ch.ppms_ba tch_batchd etail_batc h) | |
| 199 | { | |
| 200 | context.Lo adProperty (item, new Relations hip("ppms_ batchdetai l_batchdet ailresult" )); | |
| 201 | } | |
| 202 | } | |
| 203 | ||
| 204 | return b atch; | |
| 205 | } | |
| 206 | ||
| 207 | pr ivate asyn c Task<ILi st<ppms_pr ovidernetw orkid>> Ge tProviderN etworks(st ring provi derId) | |
| 208 | { | |
| 209 | var cont ext = awai t _context Helper.Get ContextAsy nc(); | |
| 210 | var prov ider = con text.ppms_ providerne tworkidSet .FirstOrDe fault(b => b.ppms_pr oviderid = = provider Id); | |
| 211 | if (prov ider == nu ll) throw new PpmsSe rviceExcep tion("Prov ider recor d does not exist"); | |
| 212 | ||
| 213 | //contex t.LoadProp erty(provi der, new R elationshi p("ppms_ba tch_batchd etail_batc h")); | |
| 214 | ||
| 215 | //if (pr ovider.ppm s_batch_ba tchdetail_ batch != n ull) | |
| 216 | //{ | |
| 217 | // fo reach (var item in p rovider.pp ms_batch_b atchdetail _batch) | |
| 218 | // { | |
| 219 | // context. LoadProper ty(item, n ew Relatio nship("ppm s_batchdet ail_batchd etailresul t")); | |
| 220 | // } | |
| 221 | //} | |
| 222 | ||
| 223 | return n ew List<pp ms_provide rnetworkid >() { prov ider }; | |
| 224 | } | |
| 225 | ||
| 226 | pu blic async Task<stri ng> Create ResponseDo cument(Das Message qu eueMessage ) | |
| 227 | { | |
| 228 | try | |
| 229 | { | |
| 230 | if ( string.IsN ullOrEmpty (queueMess age.Conten t)) | |
| 231 | { | |
| 232 | _logger.In fo($"@@@@ INFO - Par ameter inv alid for i tem: {queu eMessage.T oString()} @@@@"); | |
| 233 | return str ing.Empty; | |
| 234 | } | |
| 235 | ||
| 236 | var batchId = queueMessa ge.Content ; | |
| 237 | var batch = aw ait GetBat ch(batchId ); | |
| 238 | ||
| 239 | _log ger.Info($ "@@@@ INFO - Verify details fo r Conversa tionId: {b atchId} @@ @@"); | |
| 240 | var details = batch.ppms _batch_bat chdetail_b atch; | |
| 241 | IEnu merable<pp ms_batchde tail> ppms Batchdetai ls = detai ls as ppms _batchdeta il[] ?? de tails.ToAr ray(); | |
| 242 | if ( !ppmsBatch details.An y()) | |
| 243 | { | |
| 244 | _logger.In fo($"@@@@ INFO - Det ails not f ound for B atchId: {b atchId} @@ @@"); | |
| 245 | return str ing.Empty; | |
| 246 | } | |
| 247 | ||
| 248 | _log ger.Info($ "@@@@ INFO - Details found for BatchId: {batchId} @@@@"); | |
| 249 | ||
| 250 | // C reate XML doc | |
| 251 | var doc = new ProviderRe sponses | |
| 252 | { | |
| 253 | ProviderRe sponse = n ew List<Pr oviderResp onse>(), | |
| 254 | Transactio nId = batc h.ppms_tra nsactionid | |
| 255 | }; | |
| 256 | ||
| 257 | // C apture bat ch details | |
| 258 | fore ach (var d etail in p pmsBatchde tails) | |
| 259 | { | |
| 260 | // Provide r node | |
| 261 | var provid er = new P roviderRes ponse | |
| 262 | { | |
| 263 | Provid erId = det ail.ppms_p roviderid, | |
| 264 | Succes s = detail .GetAttrib uteValue<b ool>("ppms _isvalid") | |
| 265 | }; | |
| 266 | ||
| 267 | // Set cor relation i d, if appr opriate | |
| 268 | if (detail .ppms_prov ider != nu ll) | |
| 269 | { | |
| 270 | provid er.Correla tionId = d etail.ppms _provider. Id.ToStrin g(); | |
| 271 | } | |
| 272 | ||
| 273 | // Retriev e batch de tail resul ts | |
| 274 | var batchD etailResul ts = detai l.ppms_bat chdetail_b atchdetail result; | |
| 275 | ||
| 276 | // Capture batch det ail result s | |
| 277 | IEnumerabl e<ppms_bat chdetailre sult> ppms Batchdetai lresults = batchDeta ilResults as ppms_ba tchdetailr esult[] ?? batchDeta ilResults. ToArray(); | |
| 278 | if (ppmsBa tchdetailr esults.Any ()) | |
| 279 | { | |
| 280 | // Ini tialize re sults list | |
| 281 | provid er.Results = new Res ults { Ite m = new Li st<Result> () }; | |
| 282 | ||
| 283 | foreac h (var det ailResult in ppmsBat chdetailre sults) | |
| 284 | { | |
| 285 | va r result = new Resul t | |
| 286 | { | |
| 287 | Type = d etailResul t.ppms_ent itytype, | |
| 288 | Id = det ailResult. ppms_name, | |
| 289 | Success = detailRe sult.ppms_ isvalid.Ha sValue && detailResu lt.ppms_is valid.Valu e | |
| 290 | }; | |
| 291 | ||
| 292 | if (!result. Success) | |
| 293 | { | |
| 294 | result.H eader = de tailResult .ppms_resu lt; | |
| 295 | result.M essage = d etailResul t.ppms_mes sage; | |
| 296 | } | |
| 297 | ||
| 298 | pr ovider.Res ults.Item. Add(result ); | |
| 299 | } | |
| 300 | } | |
| 301 | else | |
| 302 | { | |
| 303 | _logge r.Info($"@ @@@ INFO - Results n ot found f or provide r: {detail .ppms_name } @@@@"); | |
| 304 | } | |
| 305 | ||
| 306 | // Add to list of pr oviders | |
| 307 | doc.Provid erResponse .Add(provi der); | |
| 308 | } | |
| 309 | ||
| 310 | // C reate resp onse packe t | |
| 311 | var responseTo Send = awa it Convert ResponseTo Xml(doc); | |
| 312 | ||
| 313 | // C lose batch | |
| 314 | awai t _ppmsHel per.Update Batch(queu eMessage, "CCN Respo nse sent." , (int)ppm s_batch_St atusCode.C omplete); | |
| 315 | ||
| 316 | _log ger.Info($ "@@@@ INFO - Save co mplete for BatchId: {batchId} @@@@"); | |
| 317 | ||
| 318 | retu rn respons eToSend; | |
| 319 | } | |
| 320 | catch (F aultExcept ion<Organi zationServ iceFault> ex) | |
| 321 | { | |
| 322 | _log ger.Error( $"@@@@ Cre ateRespons eService E RROR - Fau lt: {ex} @ @@@", ex); | |
| 323 | thro w; | |
| 324 | } | |
| 325 | catch (E xception e x) | |
| 326 | { | |
| 327 | _log ger.Error( $"@@@@ Cre ateRespons eService E RROR - Exc eption: {e x} @@@@", ex); | |
| 328 | thro w; | |
| 329 | } | |
| 330 | } | |
| 331 | ||
| 332 | pu blic async Task<stri ng> Create ProviderXm lDoc(DasMe ssage queu eMessage) | |
| 333 | { | |
| 334 | try | |
| 335 | { | |
| 336 | if ( string.IsN ullOrEmpty (queueMess age.Conten t)) | |
| 337 | { | |
| 338 | _logger.In fo($"@@@@ INFO - Bat ch ID not provided f or item: { queueMessa ge.ToStrin g()} @@@@" ); | |
| 339 | return str ing.Empty; | |
| 340 | } | |
| 341 | ||
| 342 | var batchId = queueMessa ge.Content ; | |
| 343 | var batch = aw ait GetBat ch(batchId ); | |
| 344 | ||
| 345 | retu rn await E xportBatch ToXml(batc h); | |
| 346 | } | |
| 347 | catch (E xception e x) | |
| 348 | { | |
| 349 | _log ger.Info($ "!!!! ERRO R - Error occured cr eated prov ider XML d ocument: \ n{queueMes sage.ToStr ing()}\n{e x.Message} !!!!"); | |
| 350 | } | |
| 351 | ||
| 352 | return s tring.Empt y; | |
| 353 | } | |
| 354 | ||
| 355 | pr ivate asyn c Task<str ing> Conve rtResponse ToXml(Prov iderRespon ses respon se) | |
| 356 | { | |
| 357 | var pack et = await _configur ation.GetS chemaProfi leAsync(Sc hemaOption s.SchemaPr ofiles.Res ponse); | |
| 358 | ||
| 359 | var pref ix = packe t.Prefix; | |
| 360 | var name Space = pa cket.Names pace; | |
| 361 | ||
| 362 | return U tilities.S erializeIn stance(res ponse, pre fix, nameS pace); | |
| 363 | } | |
| 364 | ||
| 365 | pr ivate asyn c Task<str ing> Expor tBatchToXm l(ppms_bat ch batch) | |
| 366 | { | |
| 367 | Context. Account ac count = nu ll; | |
| 368 | ||
| 369 | if (batc h.ppms_bat ch_batchde tail_batch == null) return str ing.Empty; | |
| 370 | ||
| 371 | var prov iders = ne w List<Pro vider>(); | |
| 372 | ||
| 373 | foreach (var item in batch.p pms_batch_ batchdetai l_batch) | |
| 374 | { | |
| 375 | acco unt = awai t GetProvi der(item.p pms_provid er.Id); | |
| 376 | if ( account != null) | |
| 377 | { | |
| 378 | // convert provider to XML | |
| 379 | providers. Add(ToProv ider(accou nt)); | |
| 380 | } | |
| 381 | } | |
| 382 | ||
| 383 | var xml = Utilities. SerializeI nstance(pr oviders, " p", "https ://ppms. DNS /exchange/ ccn/1.0"); | |
| 384 | ||
| 385 | return x ml; | |
| 386 | } | |
| 387 | ||
| 388 | pr ivate asyn c Task<Con text.Accou nt> GetPro vider(Guid providerI d) | |
| 389 | { | |
| 390 | var cont ext = awai t _context Helper.Get ContextAsy nc(); | |
| 391 | var enti ty = conte xt.Account Set.FirstO rDefault(b => b.Id = = provider Id); | |
| 392 | if (enti ty == null ) throw ne w PpmsServ iceExcepti on("Batch record doe s not exis t"); | |
| 393 | ||
| 394 | LoadProv iderProper ties(entit y, context ); | |
| 395 | ||
| 396 | return e ntity; | |
| 397 | } | |
| 398 | ||
| 399 | pr otected vo id LoadPro viderPrope rties(Enti ty entity, PpmsConte xt context ) | |
| 400 | { | |
| 401 | if (enti ty == null || contex t == null) return; | |
| 402 | ||
| 403 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ providerid entifier_P rovider"); | |
| 404 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ providerse rvice"); | |
| 405 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ boardcerti fication") ; | |
| 406 | context. LoadProper ty(entity, "ppms_acc ount_organ izationaut horizedoff icial"); | |
| 407 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ otherprovi deridentif ier"); | |
| 408 | context. LoadProper ty(entity, "contact_ customer_a ccounts"); | |
| 409 | context. LoadProper ty(entity, "ppms_acc ount_provi derlicensu re"); | |
| 410 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ othername" ); | |
| 411 | context. LoadProper ty(entity, "ppms_acc ount_ppms_ providerta xonomy"); | |
| 412 | context. LoadProper ty(entity, "ppms_acc ount_deasc hedulepriv ilege"); | |
| 413 | context. LoadProper ty(entity, "ppms_acc ount_provi dernetwork id"); | |
| 414 | } | |
| 415 | ||
| 416 | pr ivate Prov ider ToPro vider(Cont ext.Accoun t account) | |
| 417 | { | |
| 418 | if (acco unt == nul l) return null; | |
| 419 | ||
| 420 | var prov ider = new Provider( ); | |
| 421 | ||
| 422 | // Map p roperties | |
| 423 | provider .Email = a ccount.EMa ilAddress1 ; | |
| 424 | provider .Phone = a ccount.Tel ephone1; | |
| 425 | provider .Fax = acc ount.Fax; | |
| 426 | ||
| 427 | // Addre ss | |
| 428 | var addr ess = new ProviderDa ta.Address (); | |
| 429 | address. Address1 = account.A ddress1_Li ne1; | |
| 430 | address. Address2 = account.A ddress1_Li ne2; | |
| 431 | address. Address3 = account.A ddress1_Li ne3; | |
| 432 | address. City = acc ount.Addre ss1_City; | |
| 433 | address. State = ac count.Addr ess1_State OrProvince ; | |
| 434 | address. PostalCode = account .Address1_ PostalCode ; | |
| 435 | address. County = a ccount.Add ress1_Coun ty; | |
| 436 | ||
| 437 | provider .Address = address; | |
| 438 | ||
| 439 | // NPIs | |
| 440 | var npis = new Lis t<Npi>(); | |
| 441 | var npi = new Npi( ); | |
| 442 | npi.Numb er = accou nt.ppms_Pr oviderIden tifier; | |
| 443 | provider .Npis = ne w Npis() { Item = np is }; | |
| 444 | ||
| 445 | // Speci alties | |
| 446 | if (acco unt.ppms_a ccount_ppm s_provider taxonomy ! = null) | |
| 447 | { | |
| 448 | var specialtie s = new Li st<Taxonom y>(); | |
| 449 | fore ach (var i tem in acc ount.ppms_ account_pp ms_provide rtaxonomy) | |
| 450 | { | |
| 451 | specialtie s.Add(new Taxonomy() { CodedSp ecialty = item.ppms_ codedspeci alty }); | |
| 452 | } | |
| 453 | prov ider.Speci alties = n ew Special ties() { I tem = spec ialties }; | |
| 454 | } | |
| 455 | ||
| 456 | // Name | |
| 457 | var indi vidual = n ew Individ ual(); | |
| 458 | var name s = accoun t.Name.Spl it(','); | |
| 459 | individu al.FirstNa me = names [0].Trim() ; | |
| 460 | individu al.LastNam e = names[ 1].Trim(); | |
| 461 | individu al.MiddleN ame = ""; | |
| 462 | ||
| 463 | // DEA N umbers | |
| 464 | if (acco unt.ppms_a ccount_dea schedulepr ivilege != null) | |
| 465 | { | |
| 466 | var deaNumbers = new Lis t<DeaSched ulePrivile ge>(); | |
| 467 | fore ach (var i tem in acc ount.ppms_ account_de aschedulep rivilege) | |
| 468 | { | |
| 469 | deaNumbers .Add(new D eaSchedule Privilege( ) { DeaNum ber = item .ppms_dean umber }); | |
| 470 | } | |
| 471 | indi vidual.Dea Numbers = new DeaSch edulePrivi leges() { Item = dea Numbers }; | |
| 472 | } | |
| 473 | ||
| 474 | // Set p rovider ty pe | |
| 475 | var prov iderType = new Provi derType(); | |
| 476 | provider Type.Item = individu al; | |
| 477 | ||
| 478 | provider .Type = pr oviderType ; | |
| 479 | ||
| 480 | return p rovider; | |
| 481 | } | |
| 482 | } | |
| 483 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.