Lots of updates
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PWAPPv2.Source.API
|
||||
{
|
||||
class APIConnection
|
||||
{
|
||||
private static string BaseURL;
|
||||
|
||||
public DataObjects.APICredentials Credentials;
|
||||
|
||||
private static bool ResponseReady = false;
|
||||
private static string Response = "";
|
||||
|
||||
public APIConnection(string baseUrl, DataObjects.APICredentials credentials)
|
||||
{
|
||||
Credentials = credentials;
|
||||
BaseURL = baseUrl;
|
||||
}
|
||||
|
||||
public string GetResponse()
|
||||
{
|
||||
while (!ResponseReady) ;
|
||||
return Response;
|
||||
}
|
||||
|
||||
public static async void APIGet(string Call)
|
||||
{
|
||||
//WebRequest request = WebRequest.Create(BaseURL + Call);
|
||||
//request.Method = "GET";
|
||||
//request.ContentType = "application/json; charset=utf-8";
|
||||
//var response = (HttpWebResponse)request.GetResponse();
|
||||
//string text;
|
||||
//using (var sr = new StreamReader(response.GetResponseStream()))
|
||||
//{
|
||||
// text = sr.ReadToEnd();
|
||||
//}
|
||||
//return text;
|
||||
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.BaseAddress = new Uri(BaseURL);
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
HttpResponseMessage response = await client.GetAsync(Call);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public string APIPost()
|
||||
{
|
||||
string text;
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://apipatientweb.azurewebsites.net/api/PWReferralTypes");
|
||||
request.Method = "POST";
|
||||
request.ContentType = "application/json; charset=\"utf-8\"";
|
||||
request.Accept = "application/json";
|
||||
|
||||
string postData = Source.API.APIRequestBuilder.BuildJsonBodyRequest(Credentials);
|
||||
|
||||
ASCIIEncoding encoding = new ASCIIEncoding();
|
||||
byte[] data = encoding.GetBytes(postData);
|
||||
request.ContentLength = data.Length;
|
||||
Stream newStream = request.GetRequestStream();
|
||||
newStream.Write(data, 0, data.Length);
|
||||
newStream.Close();
|
||||
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
using (var sr = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
text = sr.ReadToEnd();
|
||||
}
|
||||
}
|
||||
catch(WebException wex)
|
||||
{
|
||||
text = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd();
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public string SendPostRequestAsync(string apiUri)
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
client.BaseAddress = new Uri(BaseURL);
|
||||
client.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
StringContent contetnt = new StringContent(Credentials.ToJsonString(), Encoding.UTF8, "application/json");
|
||||
|
||||
var response = client.PostAsync(apiUri, contetnt).Result;
|
||||
|
||||
if(response.IsSuccessStatusCode)
|
||||
{
|
||||
return response.Content.ReadAsStringAsync().Result;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public string SendPostRequestAsync(string apiUri, string PostData)
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
client.BaseAddress = new Uri(BaseURL);
|
||||
client.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
StringContent contetnt = new StringContent(PostData, Encoding.UTF8, "application/json");
|
||||
|
||||
var response = client.PostAsync(apiUri, contetnt).Result;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return response.Content.ReadAsStringAsync().Result;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PWAPPv2.Source.API
|
||||
{
|
||||
class APIRequestBuilder
|
||||
{
|
||||
public static string BuildJsonBodyRequest(Object src)
|
||||
{
|
||||
return JsonConvert.SerializeObject(src);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PWAPPv2.Source.DataObjects
|
||||
{
|
||||
class APICredentials
|
||||
{
|
||||
public string UserID;
|
||||
public string Password;
|
||||
public string PracticeId;
|
||||
public string APIid;
|
||||
|
||||
public APICredentials(Source.APIConfig config)
|
||||
{
|
||||
UserID = config.PWUserID;
|
||||
Password = config.PWPassword;
|
||||
PracticeId = config.PWPracticeID;
|
||||
APIid = config.PWApiID;
|
||||
}
|
||||
|
||||
public string BuildJsonBodyContents()
|
||||
{
|
||||
return "'UserID':'" + UserID + "'," +
|
||||
"'Password':'" + Password + "'," +
|
||||
"'PracticeId':'" + PracticeId + "'," +
|
||||
"'APIid':'" + APIid + "'";
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return "\"{" + BuildJsonBodyContents() + "}\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace PWAPPv2.Source.DataObjects
|
||||
{
|
||||
abstract class ComboBoxData
|
||||
{
|
||||
protected ComboBox Box;
|
||||
|
||||
public ComboBoxData(ComboBox box)
|
||||
{
|
||||
Box = box;
|
||||
}
|
||||
|
||||
public void Add(string content)
|
||||
{
|
||||
Box.Items.Add(content);
|
||||
}
|
||||
|
||||
public string GetSelectedData()
|
||||
{
|
||||
return Box.SelectedItem.ToString();
|
||||
}
|
||||
|
||||
public abstract void Update();
|
||||
|
||||
public abstract int GetSelectedIndex(string content);
|
||||
|
||||
public abstract int GetSelectedID();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PWAPPv2.Source.DataObjects
|
||||
{
|
||||
class Exceptions
|
||||
{
|
||||
}
|
||||
|
||||
class DataInvalidException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PWAPPv2.Source.DataObjects
|
||||
{
|
||||
class NumValList
|
||||
{
|
||||
private List<NumValPair> Pairs;
|
||||
|
||||
public NumValList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public NumValList(string Content, char Delim)
|
||||
{
|
||||
string[] split = Content.Split(Delim);
|
||||
if((split.Length % 2) != 0)
|
||||
{
|
||||
throw new UnevenValuesException();
|
||||
}
|
||||
for(int i = 0; i < split.Length; i++)
|
||||
{
|
||||
this.Add(int.Parse(split[i]), split[i + 1]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(int Num, string Val)
|
||||
{
|
||||
Pairs.Add(new NumValPair(Num, Val));
|
||||
}
|
||||
|
||||
public string GetValFromNum(int Num)
|
||||
{
|
||||
for (int i = 0; i < Pairs.Count; i++)
|
||||
{
|
||||
if (Pairs[i].Num == Num)
|
||||
{
|
||||
return Pairs[i].Value;
|
||||
}
|
||||
}
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
public int GetNumFromVal(string Val)
|
||||
{
|
||||
for (int i = 0; i < Pairs.Count; i++)
|
||||
{
|
||||
if (Pairs[i].Value == Val)
|
||||
{
|
||||
return Pairs[i].Num;
|
||||
}
|
||||
}
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class NotFoundException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
class UnevenValuesException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PWAPPv2.Source.DataObjects
|
||||
{
|
||||
class NumValPair
|
||||
{
|
||||
public int Num;
|
||||
public string Value;
|
||||
|
||||
public NumValPair(int N, string Val)
|
||||
{
|
||||
Num = N;
|
||||
Value = Val;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace PWAPPv2.Source.DataObjects
|
||||
{
|
||||
class ReferFromBox : ComboBoxData
|
||||
{
|
||||
List<string> DoctorName;
|
||||
List<int> DoctorID;
|
||||
public ReferFromBox(ComboBox box, string data) : base(box)
|
||||
{
|
||||
this.Add("Choose Refer From");
|
||||
DoctorName = new List<string>();
|
||||
DoctorID = new List<int>();
|
||||
data = data.Replace("\\n", "");
|
||||
data = data.Replace("\"", "");
|
||||
string[] split = data.Split('|');
|
||||
for (int i = 0; i < split.Length; i = i + 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
int id = int.Parse(split[i]);
|
||||
DoctorID.Add(id);
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new DataInvalidException();
|
||||
}
|
||||
DoctorName.Add(split[i + 1]);
|
||||
|
||||
}
|
||||
|
||||
foreach (string name in DoctorName)
|
||||
{
|
||||
Add(name);
|
||||
}
|
||||
|
||||
Box.SelectedItem = "Choose Refer From";
|
||||
|
||||
}
|
||||
|
||||
public override int GetSelectedID()
|
||||
{
|
||||
string Selected = GetSelectedData();
|
||||
if (Selected == "Choose Refer From")
|
||||
{
|
||||
throw new ReferFromDefaultException();
|
||||
}
|
||||
for (int i = 0; i < DoctorName.Count; i++)
|
||||
{
|
||||
if (DoctorName[i] == Selected)
|
||||
{
|
||||
return DoctorID[i];
|
||||
}
|
||||
}
|
||||
throw new InvalidReferralTypeException();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int GetSelectedIndex(string content)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ReferFromDefaultException : Exception
|
||||
{ }
|
||||
public class InvalidDoctorException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace PWAPPv2.Source.DataObjects
|
||||
{
|
||||
class ReferToBox : ComboBoxData
|
||||
{
|
||||
List<int> PractieID;
|
||||
List<string> ToName;
|
||||
List<int> DoctorID;
|
||||
|
||||
public ReferToBox(ComboBox box, string data) : base(box)
|
||||
{
|
||||
this.Add("Choose Refer To");
|
||||
ToName = new List<string>();
|
||||
DoctorID = new List<int>();
|
||||
PractieID = new List<int>();
|
||||
data = data.Replace("\\n", "");
|
||||
data = data.Replace("\"", "");
|
||||
string[] split = data.Split('|');
|
||||
for (int i = 0; i < split.Length; i = i + 3)
|
||||
{
|
||||
try
|
||||
{
|
||||
PractieID.Add(int.Parse(split[i]));
|
||||
ToName.Add(split[i + 1]);
|
||||
DoctorID.Add(int.Parse(split[i + 2]));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new DataInvalidException();
|
||||
}
|
||||
}
|
||||
foreach (string name in ToName)
|
||||
{
|
||||
this.Add(name);
|
||||
}
|
||||
Box.SelectedItem = "Choose Refer To";
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int GetSelectedID()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
public int GetSelectedPracticeID()
|
||||
{
|
||||
string selected = GetSelectedData();
|
||||
if (selected == "Choose Refer To")
|
||||
{
|
||||
throw new ReferToDefaultException();
|
||||
}
|
||||
for (int i = 0; i < ToName.Count; i++)
|
||||
{
|
||||
if (ToName[i] == selected)
|
||||
{
|
||||
return PractieID[i];
|
||||
}
|
||||
}
|
||||
throw new InvalidReferToException();
|
||||
}
|
||||
|
||||
public int GetSelectedDoctorID()
|
||||
{
|
||||
string selected = GetSelectedData();
|
||||
if (selected == "Choose Refer To")
|
||||
{
|
||||
throw new ReferToDefaultException();
|
||||
}
|
||||
for (int i = 0; i < ToName.Count; i++)
|
||||
{
|
||||
if (ToName[i] == selected)
|
||||
{
|
||||
return DoctorID[i];
|
||||
}
|
||||
}
|
||||
throw new InvalidReferToException();
|
||||
}
|
||||
|
||||
public override int GetSelectedIndex(string content)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class ReferToDefaultException : Exception
|
||||
{ }
|
||||
|
||||
public class InvalidReferToException : Exception
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows;
|
||||
|
||||
namespace PWAPPv2.Source.DataObjects
|
||||
{
|
||||
class Referral
|
||||
{
|
||||
APICredentials ApiCredentials;
|
||||
Patient PatientData;
|
||||
ReferToBox ReferTo;
|
||||
ReferFromBox ReferFrom;
|
||||
ReferralTypeBox ReferralType;
|
||||
|
||||
RichTextBox RemarksBox;
|
||||
CheckBox ContactBox;
|
||||
|
||||
public Referral(APICredentials apiCredentials, Patient patient, ReferralTypeBox referralType, ReferToBox referTo, ReferFromBox referFrom, RichTextBox remarksBox, CheckBox contactBox)
|
||||
{
|
||||
ApiCredentials = apiCredentials;
|
||||
PatientData = patient;
|
||||
ReferralType = referralType;
|
||||
ReferTo = referTo;
|
||||
ReferFrom = referFrom;
|
||||
RemarksBox = remarksBox;
|
||||
ContactBox = contactBox;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
|
||||
string RemarksText = new TextRange(RemarksBox.Document.ContentStart, RemarksBox.Document.ContentEnd).Text;
|
||||
|
||||
int contact = 0;
|
||||
if(ContactBox.IsChecked == true)
|
||||
{
|
||||
contact = 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return "\"{" + ApiCredentials.BuildJsonBodyContents() + "," +
|
||||
"'LName':'" + PatientData.LName + "'," +
|
||||
"'FName':'" + PatientData.FName + "'," +
|
||||
"'Birthday':'" + PatientData.DoB + "'," +
|
||||
"'Address':'" + PatientData.Address + "'," +
|
||||
"'Address2':'" + PatientData.Address2 + "'," +
|
||||
"'City':'" + PatientData.City + "'," +
|
||||
"'State':'" + PatientData.State + "'," +
|
||||
"'Zip':'" + PatientData.Zip + "'," +
|
||||
"'HmPhone':'" + PatientData.HomePhone + "'," +
|
||||
"'WkPhone':'" + PatientData.WorkPhone + "'," +
|
||||
"'WirelessPhone':'" + PatientData.WirelessPhone + "'," +
|
||||
"'Email':'" + PatientData.Email + "'," +
|
||||
"'ReferralType':'" + ReferralType.GetSelectedID() + "'," +
|
||||
"'SubmittedBy':'" + ReferFrom.GetSelectedID() + "'," +
|
||||
"'ToPracticeId':'" + ReferTo.GetSelectedPracticeID() + "'," +
|
||||
"'ToDoctorID':'" + ReferTo.GetSelectedDoctorID() + "'," +
|
||||
"'Attachments':'False'," +
|
||||
"'Remarks':'" + RemarksText + "'," +
|
||||
"'Contact':'" + contact + "'}\"";
|
||||
}
|
||||
catch (Source.DataObjects.ReferralTypeDefaultException)
|
||||
{
|
||||
MessageBox.Show("Please select a referral type");
|
||||
}
|
||||
catch(Source.DataObjects.ReferToDefaultException)
|
||||
{
|
||||
MessageBox.Show("Please select a refer to");
|
||||
}
|
||||
catch(Source.DataObjects.ReferFromDefaultException)
|
||||
{
|
||||
MessageBox.Show("Please select a refer from");
|
||||
}
|
||||
throw new InvalidReferalDataException();
|
||||
}
|
||||
|
||||
public class InvalidReferalDataException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace PWAPPv2.Source.DataObjects
|
||||
{
|
||||
class ReferralTypeBox : ComboBoxData
|
||||
{
|
||||
List<string> TypeName;
|
||||
List<int> TypeID;
|
||||
public ReferralTypeBox(ComboBox box, string data) : base(box)
|
||||
{
|
||||
this.Add("Choose Referral Type");
|
||||
TypeName = new List<string>();
|
||||
TypeID = new List<int>();
|
||||
data = data.Replace("\\n", "");
|
||||
data = data.Replace("\"", "");
|
||||
string[] split = data.Split('|');
|
||||
for (int i = 0; i < split.Length; i = i + 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
int id = int.Parse(split[i]);
|
||||
TypeID.Add(id);
|
||||
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
throw new DataInvalidException();
|
||||
}
|
||||
TypeName.Add(split[i + 1]);
|
||||
|
||||
}
|
||||
|
||||
foreach(string name in TypeName)
|
||||
{
|
||||
Add(name);
|
||||
}
|
||||
|
||||
Box.SelectedItem = "Choose Referral Type";
|
||||
|
||||
}
|
||||
|
||||
public override int GetSelectedID()
|
||||
{
|
||||
string Selected = GetSelectedData();
|
||||
if (Selected == "Choose Referral Type")
|
||||
{
|
||||
throw new ReferralTypeDefaultException();
|
||||
}
|
||||
for(int i = 0; i < TypeName.Count; i++)
|
||||
{
|
||||
if(TypeName[i] == Selected)
|
||||
{
|
||||
return TypeID[i];
|
||||
}
|
||||
}
|
||||
throw new InvalidReferralTypeException();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int GetSelectedIndex(string content)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class InvalidReferralTypeException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class ReferralTypeDefaultException : Exception
|
||||
{ }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace PWAPPv2.Source.Database
|
||||
{
|
||||
class DatabaseConfig
|
||||
{
|
||||
public string host;
|
||||
public string user;
|
||||
public string password;
|
||||
public string database;
|
||||
|
||||
|
||||
public DatabaseConfig(string path)
|
||||
{
|
||||
XmlDocument cfg = new XmlDocument();
|
||||
try
|
||||
{
|
||||
cfg.Load(path);
|
||||
}
|
||||
catch(XmlException)
|
||||
{
|
||||
Console.WriteLine("An error has occured parsing the config file.");
|
||||
return;
|
||||
}
|
||||
catch(System.IO.FileNotFoundException)
|
||||
{
|
||||
Console.WriteLine("Config file could not be found!");
|
||||
}
|
||||
|
||||
XmlNodeList XHost = cfg.GetElementsByTagName("ODhost");
|
||||
XmlNodeList XUser = cfg.GetElementsByTagName("ODuser");
|
||||
XmlNodeList XPassword = cfg.GetElementsByTagName("ODpassword");
|
||||
XmlNodeList XDatabase = cfg.GetElementsByTagName("ODdatabase");
|
||||
|
||||
host = XHost[0].InnerText;
|
||||
user = XUser[0].InnerText;
|
||||
password = XPassword[0].InnerText;
|
||||
database = XDatabase[0].InnerText;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace PWAPPv2.Source.Database
|
||||
{
|
||||
class DatabaseConnection
|
||||
{
|
||||
|
||||
private MySqlConnection Connection;
|
||||
private string SqlString;
|
||||
DatabaseConfig Config;
|
||||
|
||||
public DatabaseConnection(DatabaseConfig config)
|
||||
{
|
||||
Config = config;
|
||||
SqlString = "server=" + config.host + ";Uid=" + config.user + ";database=" + config.database + ";Pwd=" + config.password;
|
||||
Connection = new MySqlConnection(SqlString);
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
try
|
||||
{
|
||||
Connection.Open();
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
throw new DatabaseConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
public List<string> QueryDatabase(string query)
|
||||
{
|
||||
try
|
||||
{
|
||||
Connection.Open();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new CouldNotOpenConnectionException();
|
||||
}
|
||||
|
||||
MySqlCommand Command = new MySqlCommand(query, Connection);
|
||||
MySqlDataReader reader;
|
||||
try
|
||||
{
|
||||
reader = Command.ExecuteReader();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Connection.Close();
|
||||
throw new ReaderException();
|
||||
}
|
||||
List<string> result = new List<string>();
|
||||
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
int n = reader.VisibleFieldCount;
|
||||
for (int i = 0; i < reader.VisibleFieldCount; i++)
|
||||
{
|
||||
var type = reader.GetFieldType(i);
|
||||
if (type.Name == "Int64")
|
||||
{
|
||||
result.Add(reader.GetInt64(i).ToString());
|
||||
}
|
||||
if (type.Name == "Int32")
|
||||
{
|
||||
result.Add(reader.GetInt32(i).ToString());
|
||||
}
|
||||
if (type.Name == "String")
|
||||
{
|
||||
result.Add(reader.GetString(i));
|
||||
|
||||
}
|
||||
if (type.Name == "Byte")
|
||||
{
|
||||
result.Add(reader.GetByte(i).ToString());
|
||||
}
|
||||
if (type.Name == "DateTime")
|
||||
{
|
||||
result.Add(reader.GetDateTime(i).ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Connection.Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DatabaseConfigurationException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class DatabaseConnectionException : Exception
|
||||
{ }
|
||||
|
||||
class CouldNotOpenConnectionException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class ReaderException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,48 @@ namespace PWAPPv2.Source
|
||||
{
|
||||
class Patient
|
||||
{
|
||||
public string PatNum;
|
||||
|
||||
public string FName;
|
||||
public string MName;
|
||||
public string LName;
|
||||
public string Gender;
|
||||
public string DoB;
|
||||
public string SSN;
|
||||
public string Address;
|
||||
public string Address2;
|
||||
public string City;
|
||||
public string State;
|
||||
public string Zip;
|
||||
|
||||
public string HomePhone;
|
||||
public string WorkPhone;
|
||||
public string WirelessPhone;
|
||||
public string Email;
|
||||
|
||||
|
||||
public void BuildFromDatabase(Database.DatabaseConnection databaseConnection, string patNum)
|
||||
{
|
||||
List<string> result = databaseConnection.QueryDatabase("SELECT PatNum, LName, FName, MiddleI, Gender, Birthdate," +
|
||||
"SSN, Address, Address2, City, State, Zip, HmPhone, WkPhone, WirelessPhone, Email FROM patient WHERE PatNum = " + patNum);
|
||||
PatNum = result[0];
|
||||
LName = result[1];
|
||||
FName = result[2];
|
||||
MName = result[3];
|
||||
Gender = result[4];
|
||||
DoB = result[5];
|
||||
SSN = result[6];
|
||||
Address = result[7];
|
||||
Address2 = result[8];
|
||||
City = result[9];
|
||||
State = result[10];
|
||||
Zip = result[11];
|
||||
HomePhone = result[12];
|
||||
WorkPhone = result[13];
|
||||
WirelessPhone = result[14];
|
||||
Email = result[15];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ namespace PWAPPv2.Source
|
||||
public string txtCity { get { return p.City; } }
|
||||
public string txtState { get { return p.State; } }
|
||||
public string txtZip { get { return p.Zip; } }
|
||||
public string txtHomePhone { get { return p.HomePhone; } }
|
||||
public string txtWorkPhone { get { return p.WorkPhone; } }
|
||||
public string txtWirelessPhone { get { return p.WirelessPhone; } }
|
||||
public string txtEmail { get { return p.Email; } }
|
||||
|
||||
public PatientGUIAdapter(Patient patient)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user