CernerUserSessionController.cs
2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using ADAM.CernerFHIR.Helper;
using AIAHTML5.API.Models;
using eLearningPlayer.model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace AIAHTML5.API.Controllers
{
public class CernerUserSessionController : ApiController
{
// GET api/<controller>
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<controller>/5
public HttpResponseMessage Get(int id)
{
var db = new DBModel();
var result = db.GetAIAImageIdWithJsonCerner(id);
HttpResponseMessage response = null;
response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(result)) };
return response;
}
// POST api/<controller>
public void Post([FromBody] string CernerSessionValues)
{
var cernerUserSessionInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CernerUserSessionInfo>(CernerSessionValues);
var db = new DBModel();
var result = db.SaveCernerFhirSessionInfo(cernerUserSessionInfo);
HttpResponseMessage response = null;
response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = null };
//return response;
}
// PUT api/<controller>/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/<controller>/5
public void Delete(int id)
{
}
[HttpGet]
[Route("UpdateCernerToken")]
public HttpResponseMessage UpdateCernerToken(string sessionId)
{
//Update cerner user session values.
var cernerSessionId = sessionId;
var db = new DBModel();
var CernerUserSession = db.CheckCernerUserSession(cernerSessionId).SingleOrDefault();
var NewLoginResult = AsyncToSyncTaskHelper.AsyncHelpers.RunSync(() => ADAM.CernerFHIR.Client.ResourceProcessor.GetCernerResourceRefreshToken(CernerUserSession.LoginResult));
NewLoginResult.EndPointURL = NewLoginResult.EndPointURL ?? CernerUserSession.LoginResult.EndPointURL;
var UpdatedCernerUserSession = new CernerUserSessionInfo()
{
CernerCode = CernerUserSession.CernerCode,
FhirUserSessionId = cernerSessionId,
CernerInfoJWT = CernerUserSession.CernerInfoJWT,
LoginResult = NewLoginResult
};
db.UpdateCernerFhirSessionInfo(UpdatedCernerUserSession);
HttpResponseMessage response = null;
return response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = null };
}
}
}