You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
5.4 KiB

using DPMService.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace DPMService.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class PatientController : ControllerBase
{
private string tblpraefix = "";
private string tblname = "";
private string apikey = "";
private string secretkey = "";
private string tablename = "Patient";
private void GetKeys()
{
apikey = get_headerinfo("ApiKey");
secretkey = get_headerinfo("SecKey");
dbhelper dbh = new dbhelper();
tblpraefix = dbh.Get_TablePraefix(apikey);
}
private string get_headerinfo(string headertype)
{
Microsoft.Extensions.Primitives.StringValues headerValues;
var headerinfo = string.Empty;
if (Request.Headers.TryGetValue(headertype, out headerValues))
{
headerinfo = headerValues.FirstOrDefault();
return headerinfo;
}
else
{ return ""; };
}
private string get_sql(string sql)
{
string tmpsql = sql;
if (tblpraefix != "") tmpsql = tmpsql.Replace(tablename, tblpraefix + tablename);
if (secretkey != "") tmpsql = tmpsql.Replace("&seckey&", secretkey);
return tmpsql;
}
// GET: api/<Service_View_PatController>
[HttpGet]
public List<Patient> Get()
{
dbhelper dbh = new dbhelper();
List<Patient> Details = new List<Patient>();
return dbh.ConvertDataTable<Patient>(dbh.Get_Tabledata("Select * from [Patient]", false, true));
}
// GET api/<Service_View_PatController>/5
[HttpGet("{id}")]
public List<Patient> Get(int id)
{
dbhelper dbh = new dbhelper();
List<Patient> Details = new List<Patient>();
return dbh.ConvertDataTable<Patient>(dbh.Get_Tabledata("Select * from [Service_View_Pat] where id=" + id.ToString(), false, true));
}
[HttpGet]
[Route("search/{searchstring}")]
public List<Patient> Get(string searchstring)
{
//Models.Crypto enc = new Models.Crypto();
dbhelper dbh = new dbhelper();
dbh.Get_Tabeldata_for_Update("Select top 1 * from PatChargeLog where id=-1", false, true);
DataRow dr = dbh.dsdaten.Tables[0].NewRow();
//dr[1] = namefilterenc;
dbh.dsdaten.Tables[0].Rows.Add(dr);
dbh.Update_Tabeldata();
dbh.dsdaten.Tables.Clear();
List<Patient> Details = new List<Patient>();
return dbh.ConvertDataTable<Patient>(dbh.Get_Tabledata("Select * from [Service_View_Pat] where pat like '%" + searchstring + "%' order by pat", false, true));
}
// POST api/<Service_View_PatController>
[HttpPost]
public void Post([FromBody] Patient Patient)
{
GetKeys();
dbhelper dbh = new dbhelper();
string sql = "Insert [Patient] (id,pat) values(" + Patient.ID.ToString() + ",dbo.encrypt('&seckey&','" + Patient.Pat + "'))";
dbh.Get_Tabledata(get_sql(sql), false, true);
}
[HttpPost("{id},{charge}")]
public void Post(string id, string charge)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabeldata_for_Update("Select top 1 * from [Patient] where id=-1", false, true);
DataRow dr = dbh.dsdaten.Tables[0].NewRow();
dr[1] = id;
dr[2] = charge.ToString();
dr[3] = DateTime.Now;
dr[4] = DateTime.Now;
dr[5] = 1;
dr[6] = true;
dbh.dsdaten.Tables[0].Rows.Add(dr);
dbh.Update_Tabeldata();
}
// PUT api/<Service_View_PatController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] Patient Service_View_Pat)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabeldata_for_Update("Select top 1 * from Patient where id=" + id.ToString(), false, true);
DataRow dr = dbh.dsdaten.Tables[0].Rows[0];
Service_View_Pat.GetType().GetProperties().ToList().ForEach(f =>
{
try
{
if (f.PropertyType == typeof(DateTime))
{
dr[f.Name] = (DateTime)f.GetValue(Service_View_Pat, null);
}
else
{
dr[f.Name] = f.GetValue(Service_View_Pat, null);
}
}
catch (Exception ex) { string s = ex.Message; }
});
dbh.Update_Tabeldata();
}
// DELETE api/<Service_View_PatController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabeldata_for_Update("Select top 1 * from [patient] where id=" + id, false, true);
DataRow dr = dbh.dsdaten.Tables[0].Rows[0];
dr["Aktiv"] = false;
dr["mutiert_am"] = DateTime.Now;
dbh.Update_Tabeldata();
}
}
}