Produced by Araxis Merge on 8/27/2018 1:12:09 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.DataWebServiceV1\VA.PPMS.DataWebServiceV1\PpmsDataService | GlobalFunctionsController.cs | Tue Aug 14 18:48:56 2018 UTC |
| 2 | PPMS Build 8 Sprint 1.zip\PPMS Build 8 Sprint 1\CIF B8S1\VA.PPMS.DataWebServiceV1\VA.PPMS.DataWebServiceV1\PpmsDataService | GlobalFunctionsController.cs | Wed Aug 15 19:23:03 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 4 | 1190 |
| Changed | 3 | 16 |
| 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 Syst em; | |
| 2 | using Syst em.Collect ions.Gener ic; | |
| 3 | using Syst em.Configu ration; | |
| 4 | using Syst em.Device. Location; | |
| 5 | using Syst em.Linq; | |
| 6 | using Syst em.Net; | |
| 7 | using Syst em.Net.Htt p; | |
| 8 | using Syst em.Threadi ng.Tasks; | |
| 9 | using Syst em.Web.Htt p; | |
| 10 | using Syst em.Web.Htt p.Descript ion; | |
| 11 | using Syst em.Web.ODa ta; | |
| 12 | using Syst em.Web.ODa ta.Routing ; | |
| 13 | using Bing MapsRESTTo olkit; | |
| 14 | using Micr osoft.Web. Http; | |
| 15 | using Ppms DataServic e.Models; | |
| 16 | using Ppms DataServic e.ModelsEn umTypes; | |
| 17 | using Ppms DataServic e.V1.Mappe rs; | |
| 18 | using Ppms DataServic e.VA.PPMS. Context; | |
| 19 | using VA.P PMS.Contex t; | |
| 20 | using Syst em.Net.Htt p.Headers; | |
| 21 | using Syst em.Runtime .Serializa tion.Json; | |
| 22 | using Syst em.Securit y.Cryptogr aphy.X509C ertificate s; | |
| 23 | using Syst em.Text; | |
| 24 | using Syst em.IO; | |
| 25 | ||
| 26 | namespace PpmsDataSe rvice | |
| 27 | { | |
| 28 | /// <s ummary> | |
| 29 | /// Pr ovides unb ound, util ity functi ons. | |
| 30 | /// </ summary> | |
| 31 | [ApiVe rsionNeutr al] | |
| 32 | public class Glo balFunctio nsControll er : OData Controller | |
| 33 | { | |
| 34 | [H ttpGet] | |
| 35 | [M apToApiVer sion("1.0" )] | |
| 36 | [R esponseTyp e(typeof(C oordinates ))] | |
| 37 | [O DataRoute( "Geocode") ] | |
| 38 | pu blic async Task<Http ResponseMe ssage> Geo code([From ODataUri] string add ress) | |
| 39 | { | |
| 40 | using (v ar context = new Ppm sContext(a wait PpmsC ontextHelp er.GetProx y())) | |
| 41 | { | |
| 42 | stri ng key = C onfigurati onManager. AppSetting s["BingMap sKey"]; | |
| 43 | var request = new Geocod eRequest() | |
| 44 | { | |
| 45 | Query = ad dress, | |
| 46 | IncludeIso 2 = true, | |
| 47 | IncludeNei ghborhood = true, | |
| 48 | MaxResults = 25, | |
| 49 | BingMapsKe y = key | |
| 50 | }; | |
| 51 | ||
| 52 | //Pr ocess the request by using the ServiceMa nager. | |
| 53 | var response = await Ser viceManage r.GetRespo nseAsync(r equest); | |
| 54 | ||
| 55 | if ( response ! = null && | |
| 56 | response.R esourceSet s != null && | |
| 57 | response.R esourceSet s.Length > 0 && | |
| 58 | response.R esourceSet s[0].Resou rces != nu ll && | |
| 59 | response.R esourceSet s[0].Resou rces.Lengt h > 0) | |
| 60 | { | |
| 61 | var result = respons e.Resource Sets[0].Re sources[0] as Locati on; | |
| 62 | if (result != null) | |
| 63 | { | |
| 64 | double latitude = result.P oint.Coord inates[0]; | |
| 65 | double longitude = result. Point.Coor dinates[1] ; | |
| 66 | var co ordinate = new GeoCo ordinate(l atitude, l ongitude); | |
| 67 | ||
| 68 | ||
| 69 | //Map the Lat, L ong, and c oordinate to Coordin ates Class . | |
| 70 | var co ordinates = new Coor dinates(); | |
| 71 | coordi nates.Lati tude = lat itude; | |
| 72 | coordi nates.Long itude = lo ngitude; | |
| 73 | coordi nates.Coor dinate = c oordinate; | |
| 74 | ||
| 75 | //Retr un the Coo rdinates | |
| 76 | return Request.C reateRespo nse(coordi nates); | |
| 77 | } | |
| 78 | } | |
| 79 | ||
| 80 | var message = string.For mat("Unabl e to Geoco de the giv en address ."); | |
| 81 | Http Error err = new Http Error(mess age); | |
| 82 | retu rn Request .CreateErr orResponse (HttpStatu sCode.NotF ound, err) ; | |
| 83 | } | |
| 84 | } | |
| 85 | ||
| 86 | [H ttpGet] | |
| 87 | [M apToApiVer sion("1.0" )] | |
| 88 | [R esponseTyp e(typeof(A ddressData ))] | |
| 89 | [O DataRoute( "ValidateA ddress")] | |
| 90 | pu blic async Task<Http ResponseMe ssage> Val idateAddre ss([FromOD ataUri] st ring stree tAddress, [FromOData Uri] strin g city, [F romODataUr i] string state, [Fr omODataUri ] string z ip) | |
| 91 | { | |
| 92 | ServiceP ointManage r.ServerCe rtificateV alidationC allback += (sender, certificat e, chain, sslPolicyE rrors) => true; | |
| 93 | ServiceP ointManage r.Security Protocol = SecurityP rotocolTyp e.Tls12; | |
| 94 | try | |
| 95 | { | |
| 96 | //Th is Control ler Action called th e Address Validation API from Vets360 | |
| 97 | usin g (var cli ent = GetH ttpClient( )) | |
| 98 | { | |
| 99 | client.Bas eAddress = new Uri(" https://in t.vet360. DNS "); | |
| 100 | //client.B aseAddress = new Uri ("https:// dev.vet360 . DNS "); | |
| 101 | ||
| 102 | var payloa d = new Ro otObjectRe quest | |
| 103 | { | |
| 104 | reques tAddress = new Model s.Address | |
| 105 | { | |
| 106 | ad dressLine1 = streetA ddress, | |
| 107 | ci ty = city, | |
| 108 | st ateProvinc e = new St ateProvinc e | |
| 109 | { | |
| 110 | name = s tate | |
| 111 | }, | |
| 112 | zi pCode5 = z ip | |
| 113 | } | |
| 114 | }; | |
| 115 | ||
| 116 | var json = Serialize e(payload) ; | |
| 117 | ||
| 118 | var conten t = new St ringConten t(json, En coding.UTF 8, "applic ation/json "); | |
| 119 | content.He aders.Cont entType = new MediaT ypeHeaderV alue("appl ication/js on"); | |
| 120 | ||
| 121 | var respon se = clien t.PostAsyn c("/addres s-validati on/address /v1/valida te", conte nt).GetAwa iter().Get Result(); | |
| 122 | ||
| 123 | if (respon se.IsSucce ssStatusCo de) | |
| 124 | { | |
| 125 | var re sult = res ponse.Cont ent.ReadAs StringAsyn c().GetAwa iter().Get Result(); | |
| 126 | if (st ring.IsNul lOrEmpty(r esult)) | |
| 127 | { | |
| 128 | ||
| 129 | } | |
| 130 | else | |
| 131 | { | |
| 132 | va r addressV alidationR esult = De serialize< RootObject Response>( result); | |
| 133 | va r addressD ata = awai t AddressD ataMap.Map AddressDat a(addressV alidationR esult); | |
| 134 | re turn Reque st.CreateR esponse(ad dressData) ; | |
| 135 | } | |
| 136 | } | |
| 137 | var addres sValidatio nError = s tring.Form at("Addres s Validati on Unsucce ssful: " + response. StatusCode .ToString( )); | |
| 138 | HttpError addErr = n ew HttpErr or(address Validation Error); | |
| 139 | return Req uest.Creat eErrorResp onse(HttpS tatusCode. NotFound, addErr); | |
| 140 | ||
| 141 | } | |
| 142 | } | |
| 143 | catch (W ebExceptio n we) | |
| 144 | { | |
| 145 | var addressVal idationErr or = we.To String(); | |
| 146 | Http Error addE rr = new H ttpError(a ddressVali dationErro r); | |
| 147 | retu rn Request .CreateErr orResponse (HttpStatu sCode.NotF ound, addE rr); | |
| 148 | ||
| 149 | } | |
| 150 | catch (H ttpRequest Exception he) | |
| 151 | { | |
| 152 | var addressVal idationErr or = he.To String(); | |
| 153 | Http Error addE rr = new H ttpError(a ddressVali dationErro r); | |
| 154 | retu rn Request .CreateErr orResponse (HttpStatu sCode.NotF ound, addE rr); | |
| 155 | } | |
| 156 | catch (E xception e ) | |
| 157 | { | |
| 158 | var addressVal idationErr or = e.ToS tring(); | |
| 159 | Http Error addE rr = new H ttpError(a ddressVali dationErro r); | |
| 160 | retu rn Request .CreateErr orResponse (HttpStatu sCode.NotF ound, addE rr); | |
| 161 | } | |
| 162 | ||
| 163 | ||
| 164 | } | |
| 165 | ||
| 166 | [H ttpGet] | |
| 167 | [M apToApiVer sion("1.0" )] | |
| 168 | [R esponseTyp e(typeof(P roviderLoc atorResult ))] | |
| 169 | [O DataRoute( "ProviderL ocator")] | |
| 170 | ||
| 171 | pu blic async Task<Http ResponseMe ssage> Pro viderLocat or([FromOD ataUri] st ring addre ss, [FromO DataUri] i nt radius, [FromODat aUriAttrib ute] strin g specialt ycode, [Fr omODataUri Attribute] int netwo rk, [FromO DataUriAtt ribute] in t gender, [FromOData UriAttribu te] int pr imarycare, [FromODat aUriAttrib ute] int a cceptingne wpatients ) | |
| 172 | { | |
| 173 | using (v ar context = new Ppm sContext(a wait PpmsC ontextHelp er.GetProx y())) | |
| 174 | { | |
| 175 | stri ng key = C onfigurati onManager. AppSetting s["BingMap sKey"]; | |
| 176 | ||
| 177 | //Ge ocode the Starting A ddress fir st | |
| 178 | var request = new Geocod eRequest() | |
| 179 | { | |
| 180 | Query = ad dress, | |
| 181 | IncludeIso 2 = true, | |
| 182 | IncludeNei ghborhood = true, | |
| 183 | MaxResults = 25, | |
| 184 | BingMapsKe y = key | |
| 185 | }; | |
| 186 | ||
| 187 | //Pr ocess the request by using the ServiceMa nager. | |
| 188 | var response = await Ser viceManage r.GetRespo nseAsync(r equest); | |
| 189 | ||
| 190 | if ( response ! = null && | |
| 191 | response.R esourceSet s != null && | |
| 192 | response.R esourceSet s.Length > 0 && | |
| 193 | response.R esourceSet s[0].Resou rces != nu ll && | |
| 194 | response.R esourceSet s[0].Resou rces.Lengt h > 0) | |
| 195 | { | |
| 196 | var result = respons e.Resource Sets[0].Re sources[0] as Locati on; | |
| 197 | if (result != null) | |
| 198 | { | |
| 199 | double startLati tude = res ult.Point. Coordinate s[0]; | |
| 200 | double startLong itude = re sult.Point .Coordinat es[1]; | |
| 201 | var st artingCoor d = new Co ordinate(s tartLatitu de, startL ongitude); | |
| 202 | var st artingWayP oint = new SimpleWay point(star tingCoord) ; | |
| 203 | var or igin = new List<Simp leWaypoint > { starti ngWayPoint }; | |
| 204 | ||
| 205 | var pr ovServices = from ps in contex t.ppms_pro viderservi ceSet | |
| 206 | where p s.StateCod e.Value == (int)ppm s_provider serviceSta te.Active | |
| 207 | where p s.ppms_net work != nu ll | |
| 208 | where p s.ppms_Pro viderId != null | |
| 209 | where p s.ppms_spe cialty != null | |
| 210 | where p s.ppms_Car eSiteAddre ssLatitude .Contains( ".") | |
| 211 | where p s.ppms_Car eSiteAddre ssLongitud e.Contains (".") | |
| 212 | select ps; | |
| 213 | ||
| 214 | //Add Optional F ilters | |
| 215 | ||
| 216 | //Spec ialty | |
| 217 | if (sp ecialtycod e != "none ") | |
| 218 | pr ovServices = provSer vices.Wher e(ps => ps .ppms_spec ialtycode. Equals(spe cialtycode )); | |
| 219 | //Netw ork Switch | |
| 220 | var pr oviderNetw ork = Netw orkIds.Get Network(ne twork); | |
| 221 | if(pro viderNetwo rk.Number != (int)Ne twork.AnyN etwork) | |
| 222 | pr ovServices = provSer vices.Wher e(ps => ps .ppms_netw ork.Id == providerNe twork.Id); | |
| 223 | ||
| 224 | switch (gender) | |
| 225 | { | |
| 226 | ca se 0: | |
| 227 | //Any ge nder | |
| 228 | break; | |
| 229 | ca se 1: | |
| 230 | //Male | |
| 231 | provServ ices = pro vServices. Where(ps = > ps.ppms_ providerge nder.Equal s(ppms_Gen der.Male)) ; | |
| 232 | break; | |
| 233 | ca se 2: | |
| 234 | //Female | |
| 235 | provServ ices = pro vServices. Where(ps = > ps.ppms_ providerge nder.Equal s(ppms_Gen der.Female )); | |
| 236 | break; | |
| 237 | de fault: | |
| 238 | break; | |
| 239 | } | |
| 240 | ||
| 241 | switch (primaryc are) | |
| 242 | { | |
| 243 | ca se 0: | |
| 244 | //No Pre ference | |
| 245 | break; | |
| 246 | ca se 1: | |
| 247 | provServ ices = pro vServices. Where(ps = > ps.ppms_ provideris primarycar e.Equals(t rue)); | |
| 248 | break; | |
| 249 | ca se 2: | |
| 250 | provServ ices = pro vServices. Where(ps = > ps.ppms_ provideris primarycar e.Equals(f alse)); | |
| 251 | break; | |
| 252 | de fault: | |
| 253 | break; | |
| 254 | } | |
| 255 | ||
| 256 | switch (acceptin gnewpatien ts) | |
| 257 | { | |
| 258 | ca se 0: | |
| 259 | //No Pre ference | |
| 260 | break; | |
| 261 | ca se 1: | |
| 262 | provServ ices = pro vServices. Where(ps = > ps.ppms_ providerac ceptingnew patients.E quals(true ) && ps.pp ms_provide raccepting va.Equals( true)); | |
| 263 | break; | |
| 264 | ca se 2: | |
| 265 | provServ ices = pro vServices. Where(ps = > ps.ppms_ providerac ceptingnew patients.E quals(fals e) && ps.p pms_provid eracceptin gva.Equals (false)); | |
| 266 | break; | |
| 267 | de fault: | |
| 268 | break; | |
| 269 | } | |
| 270 | ||
| 271 | ||
| 272 | ||
| 273 | var pp msProvider ServicesIn Radius = p rovService s | |
| 274 | .Sel ect(psr => new Provi derInRadiu s | |
| 275 | { | |
| 276 | ProviderSe rvice = ps r, | |
| 277 | Distance = Haversine .GetDistan ce(startLa titude, st artLongitu de | |
| 278 | , Convert.T oDouble(ps r.ppms_Car eSiteAddre ssLatitude ), Convert .ToDouble( psr.ppms_C areSiteAdd ressLongit ude)) | |
| 279 | }).A sEnumerabl e(); | |
| 280 | ||
| 281 | //var ppmsProvid erServices List = ppm sProviderS ervicesInR adius.Orde rBy(psr => psr.Dista nce).Take( 100).Selec t(x => x.P roviderSer vice).ToLi st(); | |
| 282 | var pp msProvider ServicesLi st = ppmsP roviderSer vicesInRad ius.Where( psr => psr .Distance <= radius) .OrderBy(p sr => psr. Distance). Take(100). Select(x = > x.Provid erService) .ToList(); | |
| 283 | if (pp msProvider ServicesLi st.Count > 0) | |
| 284 | { | |
| 285 | ||
| 286 | // Split up i nto separa te lists o f max 625 for the Di stance Mat rix Reques t. | |
| 287 | // If adding a Start ti me the max # in a re quest is 1 00 | |
| 288 | // var ppmsPr oviderServ icesParsed = ppmsPro viderServi ces.Select ((x, i) => new { Ind ex = i, Va lue = x }) .GroupBy(x => x.Inde x / 100).S elect(x => x.Select( v => v.Val ue).ToList ()).ToList (); | |
| 289 | ||
| 290 | va r provLoca torList = new List<P roviderLoc atorResult >(); | |
| 291 | // foreach (v ar provSer viceList i n ppmsProv iderServic esParsed) | |
| 292 | // { | |
| 293 | //Create the List of Destina tions | |
| 294 | var dest inationsLi st = new L ist<Simple Waypoint>( ); | |
| 295 | foreach (var ppmsP roviderSer vice in pp msProvider ServicesLi st) | |
| 296 | { | |
| 297 | doub le latitud e = Conver t.ToDouble (ppmsProvi derService .ppms_Care SiteAddres sLatitude) ; | |
| 298 | doub le longitu de = Conve rt.ToDoubl e(ppmsProv iderServic e.ppms_Car eSiteAddre ssLongitud e); | |
| 299 | var coord = ne w Coordina te(latitud e, longitu de); | |
| 300 | var wayPoint = new Simpl eWaypoint( coord); | |
| 301 | dest inationsLi st.Add(way Point); | |
| 302 | } | |
| 303 | //Define the Dista nce Matrix Request | |
| 304 | var dist anceMatrix Req = new DistanceMa trixReques t() | |
| 305 | { | |
| 306 | Orig ins = orig in, | |
| 307 | Bing MapsKey = key, | |
| 308 | Dist anceUnits = Distance UnitType.M iles, | |
| 309 | Time Units = Ti meUnitType .Minute, | |
| 310 | Dest inations = destinati onsList, | |
| 311 | Trav elMode = T ravelModeT ype.Drivin g, | |
| 312 | //St artTime = DateTime.N ow | |
| 313 | }; | |
| 314 | ||
| 315 | //Proces s the requ est by usi ng the Ser viceManage r. | |
| 316 | var dist MatrixResp onse = awa it Service Manager.Ge tResponseA sync(dista nceMatrixR eq); | |
| 317 | ||
| 318 | if (dist MatrixResp onse != nu ll && | |
| 319 | dist MatrixResp onse.Resou rceSets != null && | |
| 320 | dist MatrixResp onse.Resou rceSets.Le ngth > 0 & & | |
| 321 | dist MatrixResp onse.Resou rceSets[0] .Resources != null & & | |
| 322 | dist MatrixResp onse.Resou rceSets[0] .Resources .Length > 0) | |
| 323 | { | |
| 324 | if ( distMatrix Response.R esourceSet s[0].Resou rces[0] is DistanceM atrix dist anceMatrix ) | |
| 325 | { | |
| 326 | var travel TimesDista nces = dis tanceMatri x.Results; | |
| 327 | ||
| 328 | for (var i = 0; i < travelTime sDistances .Length; i ++) | |
| 329 | { | |
| 330 | //Only do mappin g if the P rovider Se rvice/Trav el Distanc e falls wi thin radiu s | |
| 331 | if (tr avelTimesD istances[i ].TravelDi stance <= radius) | |
| 332 | { | |
| 333 | va r provLoca torResult = new Prov iderLocato rResult(); | |
| 334 | pr ovLocatorR esult.Mile s = travel TimesDista nces[i].Tr avelDistan ce; | |
| 335 | pr ovLocatorR esult.Minu tes = trav elTimesDis tances[i]. TravelDura tion; | |
| 336 | pr ovLocatorR esult.Prov iderName = ppmsProvi derService sList[i].p pms_provid ername; | |
| 337 | pr ovLocatorR esult.Prov iderSpecia lty = ppms ProviderSe rvicesList [i].ppms_s pecialtyna metext; | |
| 338 | pr ovLocatorR esult.Spec ialtyCode = ppmsProv iderServic esList[i]. ppms_speci altycode; | |
| 339 | pr ovLocatorR esult.Prov iderIdenti fier = ppm sProviderS ervicesLis t[i].ppms_ providerid entifer; | |
| 340 | pr ovLocatorR esult.Work Hours = pp msProvider ServicesLi st[i].ppms _workhours ; | |
| 341 | ||
| 342 | if (ppmsProv iderServic esList[i]. ppms_quali tyrankingt otalscore != null) | |
| 343 | { | |
| 344 | provLoca torResult. QualityRan king = (in t)ppmsProv iderServic esList[i]. ppms_quali tyrankingt otalscore; | |
| 345 | } | |
| 346 | pr ovLocatorR esult.Lati tude = Con vert.ToDou ble(ppmsPr oviderServ icesList[i ].ppms_Car eSiteAddre ssLatitude ); | |
| 347 | pr ovLocatorR esult.Long itude = Co nvert.ToDo uble(ppmsP roviderSer vicesList[ i].ppms_Ca reSiteAddr essLongitu de); | |
| 348 | if (ppmsProv iderServic esList[i]. ppms_cares ite != nul l) | |
| 349 | provLoca torResult. CareSite = ppmsProvi derService sList[i].p pms_caresi te.Name; | |
| 350 | pr ovLocatorR esult.Care SiteAddres s = ppmsPr oviderServ icesList[i ].ppms_car esiteaddre ss + ' ' + ppmsProvi derService sList[i].p pms_caresi tecity + ' ,'+' '+ | |
| 351 | ppmsProv iderServic esList[i]. ppms_cares itestatepr ovince + ' ' + ppmsP roviderSer vicesList[ i].ppms_ca resitezipc ode; | |
| 352 | // Gender | |
| 353 | if (ppmsProv iderServic esList[i]. ppms_provi dergender != null) | |
| 354 | switch ( ppmsProvid erServices List[i].pp ms_provide rgender.Va lue) | |
| 355 | { | |
| 356 | case (int)ppms _Gender.Ma le: | |
| 357 | provLocato rResult.Pr oviderGend er = Provi derGender. Male; | |
| 358 | break; | |
| 359 | case (int)ppms _Gender.Fe male: | |
| 360 | provLocato rResult.Pr oviderGend er = Provi derGender. Female; | |
| 361 | break; | |
| 362 | case (int)ppms _Gender.No tSpecified : | |
| 363 | provLocato rResult.Pr oviderGend er = Provi derGender. NotSpecifi ed; | |
| 364 | break; | |
| 365 | case (int)ppms _Gender.Ot her: | |
| 366 | provLocato rResult.Pr oviderGend er = Provi derGender. Other; | |
| 367 | break; | |
| 368 | } | |
| 369 | ||
| 370 | if (ppmsProv iderServic esList[i]. ppms_quali tyrankingt otalscore != null) | |
| 371 | provLoca torResult. QualityRan king = (in t)ppmsProv iderServic esList[i]. ppms_quali tyrankingt otalscore; | |
| 372 | if (ppmsProv iderServic esList[i]. ppms_netwo rk != null ) | |
| 373 | { | |
| 374 | provLoca torResult. ProviderNe twork = pp msProvider ServicesLi st[i].ppms _network.N ame; | |
| 375 | var prov Network = NetworkIds .GetNetwor k(ppmsProv iderServic esList[i]. ppms_netwo rk.Id); | |
| 376 | provLoca torResult. NetworkId = provNetw ork.Number ; | |
| 377 | } | |
| 378 | if (ppmsProv iderServic esList[i]. ppms_provi derisprima rycare != null) | |
| 379 | provLoca torResult. ProviderPr imaryCare = ppmsProv iderServic esList[i]. ppms_provi derisprima rycare.Val ue; | |
| 380 | if (ppmsProv iderServic esList[i]. ppms_provi deraccepti ngnewpatie nts != nul l) | |
| 381 | provLoca torResult. ProviderAc ceptingNew Patients = ppmsProvi derService sList[i].p pms_provid eracceptin gnewpatien ts.Value; | |
| 382 | provLo catorList. Add(provLo catorResul t); | |
| 383 | } | |
| 384 | } | |
| 385 | } | |
| 386 | } | |
| 387 | // } | |
| 388 | ||
| 389 | // Sort the R esults on Distance a scending. | |
| 390 | pr ovLocatorL ist.Sort(( x, y) => x .Miles.Com pareTo(y.M iles)); | |
| 391 | // Return the Results | |
| 392 | re turn Reque st.CreateR esponse(pr ovLocatorL ist); | |
| 393 | ||
| 394 | } | |
| 395 | var me ssage = st ring.Forma t("No Prov iders foun d based on Address, Radius and Filter Cr iteria giv en"); | |
| 396 | HttpEr ror err = new HttpEr ror(messag e); | |
| 397 | return Request.C reateError Response(H ttpStatusC ode.NotFou nd, err); | |
| 398 | } | |
| 399 | } | |
| 400 | var geoCodeErr orMessage = string.F ormat("Una ble to Geo code the g iven addre ss"); | |
| 401 | Http Error geoE rr = new H ttpError(g eoCodeErro rMessage); | |
| 402 | retu rn Request .CreateErr orResponse (HttpStatu sCode.NotF ound, geoE rr); | |
| 403 | } | |
| 404 | } | |
| 405 | ||
| 406 | pu blic stati c class Ha versine | |
| 407 | { | |
| 408 | public s tatic bool IsInRadiu s(double l at1, doubl e lon1, do uble lat2, double lo n2, int ra dius) | |
| 409 | { | |
| 410 | var R = 6372.8 ; // In ki lometers | |
| 411 | var dLat = toR adians(lat 2 - lat1); | |
| 412 | var dLon = toR adians(lon 2 - lon1); | |
| 413 | lat1 = toRadia ns(lat1); | |
| 414 | lat2 = toRadia ns(lat2); | |
| 415 | ||
| 416 | var a = Math.S in(dLat / 2) * Math. Sin(dLat / 2) + Math .Sin(dLon / 2) * Mat h.Sin(dLon / 2) * Ma th.Cos(lat 1) * Math. Cos(lat2); | |
| 417 | var c = 2 * Ma th.Asin(Ma th.Sqrt(a) ); | |
| 418 | var distance = R * 2 * M ath.Asin(M ath.Sqrt(a )); | |
| 419 | if ( distance < = radius) | |
| 420 | { | |
| 421 | return tru e; | |
| 422 | } | |
| 423 | retu rn false; | |
| 424 | } | |
| 425 | ||
| 426 | public s tatic doub le GetDist ance(doubl e lat1, do uble lon1, double la t2, double lon2) | |
| 427 | { | |
| 428 | var R = 6372.8 ; // In ki lometers | |
| 429 | var dLat = toR adians(lat 2 - lat1); | |
| 430 | var dLon = toR adians(lon 2 - lon1); | |
| 431 | lat1 = toRadia ns(lat1); | |
| 432 | lat2 = toRadia ns(lat2); | |
| 433 | var a = Math.S in(dLat / 2) * Math. Sin(dLat / 2) + Math .Sin(dLon / 2) * Mat h.Sin(dLon / 2) * Ma th.Cos(lat 1) * Math. Cos(lat2); | |
| 434 | var c = 2 * Ma th.Asin(Ma th.Sqrt(a) ); | |
| 435 | var distance = R * 2 * M ath.Asin(M ath.Sqrt(a )); | |
| 436 | retu rn distanc e; | |
| 437 | } | |
| 438 | ||
| 439 | public s tatic ppms _providers ervice Ret urnInRadiu s(ppms_pro viderservi ce provSer vice, doub le lat1, d ouble lon1 , int radi us) | |
| 440 | { | |
| 441 | doub le lat2 = Convert.To Double(pro vService.p pms_CareSi teAddressL atitude); | |
| 442 | doub le lon2 = Convert.To Double(pro vService.p pms_CareSi teAddressL ongitude); | |
| 443 | var R = 6372.8 ; // In ki lometers | |
| 444 | var dLat = toR adians(lat 2 - lat1); | |
| 445 | var dLon = toR adians(lon 2 - lon1); | |
| 446 | lat1 = toRadia ns(lat1); | |
| 447 | lat2 = toRadia ns(lat2); | |
| 448 | ||
| 449 | var a = Math.S in(dLat / 2) * Math. Sin(dLat / 2) + Math .Sin(dLon / 2) * Mat h.Sin(dLon / 2) * Ma th.Cos(lat 1) * Math. Cos(lat2); | |
| 450 | var c = 2 * Ma th.Asin(Ma th.Sqrt(a) ); | |
| 451 | var distance = R * 2 * M ath.Asin(M ath.Sqrt(a )); | |
| 452 | prov Service.pp ms_distanc e = distan ce; | |
| 453 | if ( distance < = radius) | |
| 454 | { | |
| 455 | return pro vService; | |
| 456 | } | |
| 457 | retu rn null; | |
| 458 | } | |
| 459 | ||
| 460 | public s tatic doub le toRadia ns(double angle) | |
| 461 | { | |
| 462 | retu rn Math.PI * angle / 180.0; | |
| 463 | } | |
| 464 | } | |
| 465 | ||
| 466 | pu blic class ProviderI nRadius | |
| 467 | { | |
| 468 | public p pms_provid erservice ProviderSe rvice { ge t; set; } | |
| 469 | public d ouble Dist ance { get ; set; } | |
| 470 | } | |
| 471 | ||
| 472 | ||
| 473 | pu blic stati c string S erializee< T>(T data) | |
| 474 | { | |
| 475 | var ms = new Memor yStream(); | |
| 476 | var ser = new Data ContractJs onSerializ er(typeof( T)); | |
| 477 | ser.Writ eObject(ms , data); | |
| 478 | var json = ms.ToAr ray(); | |
| 479 | ms.Close (); | |
| 480 | ||
| 481 | return E ncoding.UT F8.GetStri ng(json, 0 , json.Len gth); | |
| 482 | } | |
| 483 | ||
| 484 | pu blic stati c T Deseri alize<T>(s tring json ) | |
| 485 | { | |
| 486 | var ms = new Memor yStream(En coding.UTF 8.GetBytes (json)); | |
| 487 | var ser = new Data ContractJs onSerializ er(typeof( T)); | |
| 488 | var resu lt = (T)se r.ReadObje ct(ms); | |
| 489 | ms.Close (); | |
| 490 | ||
| 491 | return r esult; | |
| 492 | } | |
| 493 | ||
| 494 | pr ivate stat ic HttpCli ent GetHtt pClient() | |
| 495 | { | |
| 496 | var clie ntHandler = new WebR equestHand ler(); | |
| 497 | clientHa ndler.Clie ntCertific ates.Add(G etCertKeyV ault()); | |
| 498 | //client Handler.Cl ientCertif icates.Add (GetLocalC ert()); | |
| 499 | return n ew HttpCli ent(client Handler); | |
| 500 | } | |
| 501 | ||
| 502 | pu blic stati c X509Cert ificate2 G etLocalCer t() | |
| 503 | { | |
| 504 | var stor e = new X5 09Store(St oreName.My , StoreLoc ation.Loca lMachine); | |
| 505 | store.Op en(OpenFla gs.OpenExi stingOnly | OpenFlag s.ReadOnly ); | |
| 506 | string cer tificateSu bjectName = "CN=dws. ppms. DNS , OU=PPMS, O=VA, L=W ashington, S=DC, C=U S"; | |
| 507 | var cert = store.C ertificate s.Find(X50 9FindType. FindBySubj ectDisting uishedName , certific ateSubject Name, true ); | |
| 508 | if (cert .Count < 1 ) | |
| 509 | { | |
| 510 | thro w new Exce ption(stri ng.Format( "Could not find a va lid client certifica te with su bject {0}" , certific ateSubject Name)); | |
| 511 | } | |
| 512 | return c ert[0]; | |
| 513 | } | |
| 514 | ||
| 515 | pr ivate stat ic X509Cer tificate2 GetCertKey Vault() | |
| 516 | { | |
| 517 | const stri ng appId = " REDACTED "; | |
| 518 | const stri ng secret = " REDACT E
|
|
| 519 | const stri ng tenantI d = " REDACTED "; | |
| 520 | //const st ring certU ri = "http s:// DNS .vault.usg ovcloudapi .net/certi ficates/np -dws-ppms- va-gov-ssl cert/ REDACTED "; | |
| 521 | const stri ng certUri = "https: // DNS .vault.usg ovcloudapi .net/certi ficates/np -dws-ppms- nprod/ REDACTED "; | |
| 522 | ||
| 523 | var toke n = GetTok en(appId, secret, te nantId); | |
| 524 | var cert = GetCert ificateFro mKeyVault( token.acce ss_token, certUri); | |
| 525 | var priv ateKey = G etPrivateK eyKeyVault (token.acc ess_token, cert.sid) ; | |
| 526 | ||
| 527 | //return new X509C ertificate 2(privateK ey, (strin g)null); | |
| 528 | return n ew X509Cer tificate2( privateKey , (string) null, X509 KeyStorage Flags.Mach ineKeySet | X509KeyS torageFlag s.PersistK eySet | X5 09KeyStora geFlags.Ex portable); | |
| 529 | } | |
| 530 | ||
| 531 | ||
| 532 | pr ivate stat ic TokenRe sponse Get Token(stri ng clientI d, string clientSecr et, string tenantId) | |
| 533 | { | |
| 534 | using (v ar httpCli ent = new HttpClient ()) | |
| 535 | { | |
| 536 | var formConten t = new Fo rmUrlEncod edContent( new[] | |
| 537 | { | |
| 538 | new KeyVal uePair<str ing, strin g>("resour ce", "http s://vault. usgovcloud api.net"), | |
| 539 | new KeyVal uePair<str ing, strin g>("client _id", clie ntId), | |
| 540 | new KeyVal uePair<str ing, strin g>("client _secret", clientSecr et), | |
| 541 | new KeyVal uePair<str ing, strin g>("grant_ type", "cl ient_crede ntials") | |
| 542 | }); | |
| 543 | ||
| 544 | var response = httpClien t.PostAsyn c("https:/ /login.win dows.net/" + tenantI d + "/oaut h2/token", formConte nt).GetAwa iter().Get Result(); | |
| 545 | ||
| 546 | retu rn Deseria lize<Token Response>( response.C ontent.Rea dAsStringA sync().Res ult); | |
| 547 | } | |
| 548 | } | |
| 549 | ||
| 550 | pu blic stati c Certific ateRespons e GetCerti ficateFrom KeyVault(s tring toke n, string certificat eUrl) | |
| 551 | { | |
| 552 | using (v ar httpCli ent = new HttpClient ()) | |
| 553 | { | |
| 554 | var request = new HttpRe questMessa ge(HttpMet hod.Get, n ew Uri(cer tificateUr l + "?api- version=20 16-10-01") ); | |
| 555 | requ est.Header s.Authoriz ation = ne w Authenti cationHead erValue("B earer", to ken); | |
| 556 | ||
| 557 | var response = httpClien t.SendAsyn c(request) .GetAwaite r().GetRes ult(); | |
| 558 | ||
| 559 | retu rn Deseria lize<Certi ficateResp onse>(resp onse.Conte nt.ReadAsS tringAsync ().GetAwai ter().GetR esult()); | |
| 560 | } | |
| 561 | } | |
| 562 | ||
| 563 | pu blic stati c byte[] G etPrivateK eyKeyVault (string to ken, strin g certific ateUrl) | |
| 564 | { | |
| 565 | using (v ar httpCli ent = new HttpClient ()) | |
| 566 | { | |
| 567 | var request = new HttpRe questMessa ge(HttpMet hod.Get, n ew Uri(cer tificateUr l + "?api- version=20 16-10-01") ); | |
| 568 | requ est.Header s.Authoriz ation = ne w Authenti cationHead erValue("B earer", to ken); | |
| 569 | var response = httpClien t.SendAsyn c(request) .GetAwaite r().GetRes ult(); | |
| 570 | var privateKey = Deseria lize<Priva teKeyRespo nse>(respo nse.Conten t.ReadAsSt ringAsync( ).GetAwait er().GetRe sult()); | |
| 571 | retu rn Convert .FromBase6 4String(pr ivateKey.v alue); | |
| 572 | } | |
| 573 | } | |
| 574 | ||
| 575 | ||
| 576 | } | |
| 577 | ||
| 578 | public class Tok enResponse | |
| 579 | { | |
| 580 | pu blic strin g token_ty pe { get; set; } | |
| 581 | pu blic strin g expires_ in { get; set; } | |
| 582 | pu blic strin g ext_expi res_in { g et; set; } | |
| 583 | pu blic strin g expires_ on { get; set; } | |
| 584 | pu blic strin g not_befo re { get; set; } | |
| 585 | pu blic strin g resource { get; se t; } | |
| 586 | pu blic strin g access_t oken { get ; set; } | |
| 587 | } | |
| 588 | ||
| 589 | public class Cer tificateRe sponse | |
| 590 | { | |
| 591 | pu blic strin g id { get ; set; } | |
| 592 | pu blic strin g kid { ge t; set; } | |
| 593 | pu blic strin g sid { ge t; set; } | |
| 594 | pu blic strin g x5t { ge t; set; } | |
| 595 | pu blic strin g cer { ge t; set; } | |
| 596 | } | |
| 597 | ||
| 598 | public class Pri vateKeyRes ponse | |
| 599 | { | |
| 600 | pu blic strin g value { get; set; } | |
| 601 | } | |
| 602 | ||
| 603 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.