using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Security.Policy;
using System.Net;
using System.IO;
namespace getrxhistory
{
public partial class frmGetRXHistory : Form
{
public frmGetRXHistory()
{
InitializeComponent();
}
// Variables from the Send Medication History BT 07/22/09
string strDisposal;
string strProviderId;
string strProviderPwd;
string strPracticeId;
string strVendorId;
string strVendorPwd;
string strPracticeUniqueIdentExt;
string strVendorUniqueIdentExt;
string strLastName;
string strFirstName;
string strDob;
string strGender;
string strZip;
string strPatientUniqueIdent;
string strYearSt;
string strMonthSt;
string strDaySt;
string stryearEn;
string strMonthEn;
string strDayEn;
string strPatientID;
string strTest = "";
string bbxdata;
// Security Validation Method
public bool MyCertValidationCb(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors)
{
//WindowsEventLogger.LogMessageWarning((cName & ": Remote Certificate Chain Error") + Constants.vbNewLine + c_url)
return true;
}
else if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch)
{
System.Security.Policy.Zone z = null;
z = System.Security.Policy.Zone.CreateFromUrl(((HttpWebRequest)sender).RequestUri.ToString());
if ((z.SecurityZone == System.Security.SecurityZone.Intranet | z.SecurityZone == System.Security.SecurityZone.MyComputer))
{
return true;
}
else
{
//WindowsEventLogger.LogMessageWarning((cName & ": Remote Certificate Name Mismatch") + Constants.vbNewLine + c_url)
return false;
}
}
else if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateNotAvailable)
{
//WindowsEventLogger.LogMessageWarning((cName & ": Remote Certificate not available") + Constants.vbNewLine + c_url)
return false;
}
else if (sslPolicyErrors == SslPolicyErrors.None)
{
return true;
}
return true;
}
// End of Security Method
private void btnTest_Click(object sender, EventArgs e)
{
// Call the Security Policy Method BT-06/19/09
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(MyCertValidationCb);
// Code added from Send Medication History BT-07-22-09 *************************************************************
// *****************************************************************************************************************
// Get the Patient ID - BT 05/27/09
// readFile(); // Unrem this out before rebuilding the C# EXE file. BT-05/31/09 Remmed 07/23/09
strTest = "TEST"; // Unrem this when testing. BT-05/31/09
// string strPatientID = txtRXTest.Text;
// if (strTest == "")
{
//Get info from Digital Medicine - BT 04/27/09 (Updated Nov2010)
foreach (string arg in Environment.GetCommandLineArgs())
{
Console.WriteLine(arg); // This line should be taken out in production. BT-05/03/2009
string bbxinfo = arg;
string store_bbxinfo = arg; // Keep this variable unchanged, it may be needed in revisions. BT-05/03/2009
// txtRXTest.Text = arg;
bbxdata = arg;
}
// strPatientID = txtRXTest.Text;
strPatientID = bbxdata;
{
// MessageBox.Show("strPatientID value. " + strPatientID); // Added 07/24/09 Take this one out last - leave in just comment out for testing.
int intComma;
intComma = strPatientID.IndexOf(","); // Delimiter. I am setting it to Horizontal Tab - BT-07/23/09
//strPatientID = strPatientID.Remove(0, intComma + 1); //
strProviderId = strPatientID.Substring(0, intComma); // Get the Patient Job+Patient No. from the Dr. Practice. BT-07/22/09
strPatientID = strPatientID.Remove(0, intComma + 1); //Remove the first field and work on the next.
intComma = strPatientID.IndexOf(",");
strProviderPwd = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strPracticeId = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strVendorId = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strVendorPwd = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strPracticeUniqueIdentExt = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strVendorUniqueIdentExt = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strLastName = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strFirstName = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strDob = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strGender = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strZip = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strPatientUniqueIdent = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strYearSt = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strMonthSt = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strDaySt = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
stryearEn = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
intComma = strPatientID.IndexOf(",");
strMonthEn = strPatientID.Substring(0, intComma);
strPatientID = strPatientID.Remove(0, intComma + 1);
// intComma = strPatientID.IndexOf(","); Only data left no commas BT-07/22/09 7:15pm
strDayEn = strPatientID; //.Substring(0, intComma);
// strPatientID = strPatientID.Remove(0, intComma + 1);
}
if (strTest == "")
{
//Get info from BBX - BT 04/27/09
foreach (string arg in Environment.GetCommandLineArgs())
{
Console.WriteLine(arg); // This line should be taken out in production. BT-05/03/2009
// MessageBox.Show(arg); //REMOVE July 27, 09
string bbxinfo = arg;
string store_bbxinfo = arg; // Keep this variable unchanged, it may be needed in revisions. BT-05/03/2009
// MessageBox.Show("HEY BOB "+arg); // Unremmed BT 07/22/09 So I can see what arg is coming from BBX paramaters sent to C#
// txtRXTest.Text = arg;
}
// bbxdata = txtRXTest.Text; // can be removed, just a placesetter. BT-05/31/09
//MessageBox.Show(bbxdata);
}
else
{
// bbxdata = txtRXTest.Text;
}
// bbxdata = txtRXTest.Text; // can be removed, just a placesetter. BT-05/31/09
// MessageBox.Show("strPatientID= " + strPatientID);
// ****************************************************************************************************************************
// **************************************************************************************************************************
//ws is the webservice instance on which the web methods will be called.
drx.DigitalRxIntegrationServicesService ws = new drx.DigitalRxIntegrationServicesService();
ws.Url = "https://www.h2hdigitalrx.com/service/PartnerIntegrationService?wsdl";
// https://h2hdigitalrx.com/service/PartnerIntegrationService?wsdl
drx.SenderInformation si = new drx.SenderInformation();
si.drxProviderId = strProviderId; //Get this from Dr. Joe's program BT-06/11/2009 updated 6/19/09
si.drxProviderPwd = strProviderPwd; // Get this also from OfficeMedicine 06/11/09-BT updated 6/19/09
si.practiceId = strPracticeId;
si.vendorId = strVendorId;
si.vendorPassword = strVendorPwd;
si.practiceUniqueIdentifierExt = strPracticeUniqueIdentExt;
si.vendorUniqueIdentifierExt = strVendorUniqueIdentExt;
//Create the status object.
drx.DigitalRxStatus drxstat = new drx.DigitalRxStatus();
//Create patient data
drx.patientInfo pi = new drx.patientInfo();
pi.lastName = strLastName;
pi.firstName = strFirstName;
pi.dob = strDob;
pi.gender = strGender;
pi.zip = strZip;
// pi.patientUniqueIdentifier = "9999999ccccc9999ddd9s9s9s99s9ss9"; Identifier changed for privacy-Nov2010
pi.patientUniqueIdentifier = strPatientUniqueIdent; //per Sanjeev - 7/20/09
drx.DrxDate st = new getrxhistory.drx.DrxDate(); //Since I called the program getrxhistory BT-06/19/09
st.year = int.Parse(strYearSt);
st.month = int.Parse(strMonthSt);
st.day = int.Parse(strDaySt);
drx.DrxDate en = new getrxhistory.drx.DrxDate();
en.year = int.Parse(stryearEn);
en.month = int.Parse(strMonthEn);
en.day = int.Parse(strDayEn);
// MessageBox.Show(pi.zip);
// Create a Prescription Detail Object per Dr. Joe - Jul 15, 2009
drx.PrescriptionDetail drxPrescrip = new drx.PrescriptionDetail();
// MessageBox.Show(pi.zip);
try
{
drx.DigitalRxMedicationHistory[] drxhistory = ws.getDigitalRxMedicationHistory(si, out drxstat, "ALL", pi, st, en, true);
int noRx = drxhistory.Count(); // How many drug records BT-07/21/09
// Grab the drxhistory
// Open a Text file to store the drug records. BT-07/21/09
String FILE_NAME = "C:\\om8\\work\\RxTextFileBeta.txt";
string rxText = "";
string rxFields = "";
if (System.IO.File.Exists(FILE_NAME) == true)
{
System.IO.StreamWriter objWriter = new System.IO.StreamWriter(FILE_NAME);
// Loop through ALL the drug records and their fields. BT-07/22/09
// Put in field Titles for the records. BT 07/22/09
rxText = ("activeFlag,createdDate,daysSupply,PatientID,PhyID,dosageForm,drugID,drugName,drugType,instructions,PhyAddress,PhyName,quantity,refills,rxMode,sig,status,strength,strengthUnit" + "\n");
rxText += "\n";
for (int i = 0; i < noRx; i++)
{
rxFields = "";
rxFields += drxhistory[i].activeFlag + ",";
rxFields += drxhistory[i].createdDate + ",";
rxFields += drxhistory[i].daysSupply + ",";
rxFields += drxhistory[i].digitalRxPatientId + ",";
rxFields += drxhistory[i].digitalRxPhysicianUserId + ",";
rxFields += drxhistory[i].dosageForm + ",";
rxFields += drxhistory[i].drugId + ",";
rxFields += drxhistory[i].drugName + ",";
rxFields += drxhistory[i].drugType + ",";
rxFields += drxhistory[i].instructions + ",";
rxFields += drxhistory[i].physicianAddress + ",";
rxFields += drxhistory[i].physicianName + ",";
rxFields += drxhistory[i].quantity + ",";
rxFields += drxhistory[i].refills + ",";
rxFields += drxhistory[i].route + ",";
rxFields += drxhistory[i].rxMode + ",";
rxFields += drxhistory[i].sig + ",";
rxFields += drxhistory[i].status + ",";
rxFields += drxhistory[i].strength + ",";
rxFields += drxhistory[i].strengthUnit; //Last field no comma
// MessageBox.Show(rxFields); REMOVE on 7/23/09
rxText += rxFields + "\n";
rxText += "\n";
// rxText += drxhistory[i - 1].drugName + "\n";
}
objWriter.Write(rxText);
objWriter.Close();
}
else
{
MessageBox.Show("File Does Not Exist");
}
MessageBox.Show(rxText);
}
catch (Exception ex) //General catch handler BT-07/24/09
{
MessageBox.Show("There is possibly a problem with the Web Service. Please try again later.");
MessageBox.Show(ex.Message);
}
/* Following lines Array Test Note: The following lines left here to Show how Anchor array is setup. This is helpful
to VB.Net programmers, to understand how to declare arrays. Just comment or remove the below lines when testing. BT-06/27/09
int[] intArray = new int[3];
intArray[0] = 3;
intArray[1] = 6;
intArray[2] = 9;
// MessageBox.Show(intArray[1].ToString());
foreach (int s in intArray)
{
MessageBox.Show(s.ToString());
}
*/
}
}
public void readFile()
{
StreamReader sr;
try
{
sr = new StreamReader(File.Open(@"C:\om8\work\GetDataBeta.txt", FileMode.Open));
try
{
txtRXTest.Text = sr.ReadToEnd(); // Remove this in production BT-05/27/09
strPatientID = txtRXTest.Text;
}
finally
{
sr.Close();
}
}
catch (Exception Exc)
{
txtRXTest.Text = Exc.Message;
}
}
public void readTestFile()
{
strTest = "TEST";
StreamReader sr;
try
{
sr = new StreamReader(File.Open(@"C:\om8\work\getdatabeta.txt", FileMode.Open));
try
{
txtRXTest.Text = sr.ReadToEnd(); // Remove this in production BT-05/27/09
strPatientID = txtRXTest.Text;
bbxdata = strPatientID; // I think this will put in the rx data. BT-05/27/09
}
finally
{
sr.Close();
}
}
catch (Exception Exc)
{
txtRXTest.Text = Exc.Message;
}
}
}
}