Ejemplo n.º 1
0
        public async Task <IActionResult> GetAction(string resourceType, string resourceId)
        {
            var    scopes = new string[] { $"{_configuration["FhirImportService:Audience"].TrimEnd('/')}/.default" };
            string accessToken;

            try
            {
                accessToken = await _tokenAcquisition.GetAccessTokenOnBehalfOfUser(HttpContext, scopes);
            }
            catch (MsalUiRequiredException ex)
            {
                AuthenticationProperties properties = AuthenticationPropertiesBuilder.BuildForIncrementalConsent(scopes, HttpContext, ex);
                return(Challenge(properties));
            }

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_configuration["FhirServerUrl"]);
                client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");

                HttpResponseMessage result = await client.GetAsync($"/{resourceType}/{resourceId}");

                result.EnsureSuccessStatusCode();

                ViewData["ResourceJson"] = await result.Content.ReadAsStringAsync();
            }

            return(View("Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            var    scopes = new string[] { $"{_configuration["FhirServerAudience"].TrimEnd('/')}/.default" };
            string accessToken;

            try
            {
                accessToken = await _tokenAcquisition.GetAccessTokenOnBehalfOfUser(HttpContext, scopes);
            }
            catch (MsalUiRequiredException ex)
            {
                AuthenticationProperties properties = AuthenticationPropertiesBuilder.BuildForIncrementalConsent(scopes, HttpContext, ex);
                return(Challenge(properties));
            }

            var            client         = GetClientAsync(accessToken);
            Bundle         result         = null;
            List <Patient> patientResults = new List <Patient>();

            try
            {
                if (!string.IsNullOrEmpty(Request.Query["ct"]))
                {
                    string cont = Request.Query["ct"];
                    result = client.Search <Patient>(new string[] { $"ct={cont}" });
                }
                else
                {
                    result = client.Search <Patient>();
                }

                if (result.Entry != null)
                {
                    foreach (var e in result.Entry)
                    {
                        patientResults.Add((Patient)e.Resource);
                    }
                }

                if (result.NextLink != null)
                {
                    ViewData["NextLink"] = result.NextLink.PathAndQuery;
                }
            }
            catch (Exception e)
            {
                ViewData["ErrorMessage"] = e.Message;
            }

            return(View(patientResults));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AboutMe()
        {
            var    identity           = User.Identity as ClaimsIdentity; // Azure AD V2 endpoint specific
            string preferred_username = identity.Claims.FirstOrDefault(c => c.Type == "preferred_username")?.Value;

            ViewData["FhirServerUrl"] = _configuration["FhirServerUrl"];
            ViewData["UPN"]           = preferred_username;

            var scopes = new string[] { $"{_configuration["FhirServerAudience"].TrimEnd('/')}/.default" };

            try
            {
                var accessToken = await _tokenAcquisition.GetAccessTokenOnBehalfOfUser(HttpContext, scopes);

                ViewData["token"] = accessToken;
                return(View());
            }
            catch (MsalUiRequiredException ex)
            {
                AuthenticationProperties properties = AuthenticationPropertiesBuilder.BuildForIncrementalConsent(scopes, HttpContext, ex);
                return(Challenge(properties));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Details(string id)
        {
            var    scopes = new string[] { $"{_configuration["FhirServerAudience"].TrimEnd('/')}/.default" };
            string accessToken;

            try
            {
                accessToken = await _tokenAcquisition.GetAccessTokenOnBehalfOfUser(HttpContext, scopes);
            }
            catch (MsalUiRequiredException ex)
            {
                AuthenticationProperties properties = AuthenticationPropertiesBuilder.BuildForIncrementalConsent(scopes, HttpContext, ex);
                return(Challenge(properties));
            }

            var           client        = GetClientAsync(accessToken);
            PatientRecord patientRecord = new PatientRecord();

            try
            {
                var patientResult = client.Search <Patient>(new string[] { $"_id={id}" });
                if ((patientResult.Entry != null) && (patientResult.Entry.Count > 0))
                {
                    patientRecord.Patient = (Patient)patientResult.Entry[0].Resource;
                }

                if (patientRecord.Patient != null)
                {
                    patientRecord.Observations = new List <Observation>();
                    var observationResult = client.Search <Observation>(new string[] { $"subject=Patient/{patientRecord.Patient.Id}" });

                    while (observationResult != null)
                    {
                        foreach (var o in observationResult.Entry)
                        {
                            patientRecord.Observations.Add((Observation)o.Resource);
                        }

                        observationResult = client.Continue(observationResult);
                    }

                    patientRecord.Encounters = new List <Encounter>();
                    var encounterResult = client.Search <Encounter>(new string[] { $"subject=Patient/{patientRecord.Patient.Id}" });

                    while (encounterResult != null)
                    {
                        foreach (var e in encounterResult.Entry)
                        {
                            patientRecord.Encounters.Add((Encounter)e.Resource);
                        }

                        encounterResult = client.Continue(encounterResult);
                    }

                    patientRecord.Conditions = new List <Condition>();
                    var conditionResult = client.Search <Condition>(new string[] { $"subject=Patient/{patientRecord.Patient.Id}" });

                    while (conditionResult != null)
                    {
                        foreach (var e in conditionResult.Entry)
                        {
                            patientRecord.Conditions.Add((Condition)e.Resource);
                        }

                        conditionResult = client.Continue(conditionResult);
                    }
                }
            }
            catch (Exception e)
            {
                ViewData["ErrorMessage"] = e.Message;
            }

            var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new { patient = id }));
            var launchContext  = Convert.ToBase64String(plainTextBytes);

            ViewData["launchContext"] = HttpUtility.UrlEncode(launchContext);
            ViewData["fhirServerUrl"] = _configuration["FhirServerUrl"];

            // Configure available Smart Apps for this patient
            // TODO: Add logic to figure out if app is relevant for patient
            patientRecord.SmartApps = new List <SmartAppConfig>();
            _configuration.Bind("SmartOnFhirApps", patientRecord.SmartApps);

            return(View(patientRecord));
        }