Hi,
I've been working on an application to help manage a Health Management Organization departments.
Its my first commercial piece of software and I'm excited about rounding up this week if I can get this issue sorted out.
Here's the problem...
The MIS department receives a PDF 4 times a year. This PDF contains 2 pieces of information.
a) A list of all hospitals registered under the orgnanisation.
b) A list of Enrollee's registered under each hospital.
I was tasked with writing a program that retrieve's all hospitals in the PDF, registering them in the application's database, then retrieving all enrollee's and registering them in the database under their respective hospitals(This is managed using a foreign key relationship in the database).
I used Regex to write a solution that registers all the hospitals, and save for some delay when parsing the PDF(which is 4000 pages long) it works perfectly.
The problem is that my solution to register the enrollee's is not as efficient as it should be, about 2 out of 10 enrollee's don't get registered due to inefficiencies in my code.
And when I transfer the already partially working solution to the client's server where it will finally reside, I get an error which says
"Source Code Could Not Be Found". But when I run it in debug mode to check what the problem might be, it extracts the enrollee details as expected. So I'm very confused about that.
If I can get help with a)The "source code cannot be found" error or b)Why my code works on my development machine but not the server I would be very grateful.
Ill include my code and would also include a snapshot of the PDF as well but I doubt stack lets attachments with questions.
Thanks.
private void extractEnrolleesFromPDF(string enrolleeExtraction, string hospital)
{
int start;
int end;
string substring;
try
{
MatchCollection policyNumbers = Regex.Matches(enrolleeExtraction, @"(\*)(\d{8})(\*)");
foreach (var policyNumber in policyNumbers)
{
Match match = Regex.Match(enrolleeExtraction, "\\" + policyNumber.ToString());
if (match.Success)
{
start = match.Index;
Match match2 = Regex.Match(enrolleeExtraction.Substring(start + 10), @"(\*)");
if (match2.Success)
{
end = match2.Index + 9;
substring = enrolleeExtraction.Substring(start, end);
enrolleePolicyNumber.Add(substring);
}
}
}
ArrayList individualEnrolees = new ArrayList();
int numberOfEnrollees = enrolleePolicyNumber.Count;
bool principal = false;
string fName;
string lName;
DateTime dob;
string sex;
string hospitalCode = hospital.Substring(1, 7);
for (int i = 0; i < numberOfEnrollees; i++)
{
string enrolleePolNumber;
Match policyNumber = Regex.Match(enrolleePolicyNumber[i].ToString(), @"((\*)(\d{8})(\*))");
if (policyNumber.Success)
{
enrolleePolNumber = policyNumber.Value;
}
MatchCollection enrolleeRecords = Regex.Matches(enrolleePolicyNumber[i].ToString(), @"(\d{1})(\s)(\D*)(\d{2})/(\d{2})/(\d{4})");
individualEnrolees.Clear();
foreach (var record in enrolleeRecords)
{
individualEnrolees.Add(record);
}
try
{
Match lastPolicyNumberInHospital = Regex.Match(enrolleeExtraction, @"(\*)(\d{8})(\*)", RegexOptions.RightToLeft);
string lastRecord = enrolleeExtraction.Substring(lastPolicyNumberInHospital.Index);
enrolleePolicyNumber.Add(lastRecord);
}
catch (Exception ex)
{
MessageBox.Show("Failed to extract last record: " + ex.Message);
}
foreach (var record in individualEnrolees)
{
string princ;
string[] splitEnrolleeData = record.ToString().Split(' ');
int splitSectionCount = splitEnrolleeData.Count();
if (splitSectionCount == 5)
{
princ = splitEnrolleeData[1].ToString();
if (princ == "Principal")
{
principal = true;
}
else
{
principal = false;
}
}
else if (splitSectionCount == 4)
{
if (splitEnrolleeData[0].ToString().Contains("0"))
{
principal = true;
}
else if (!splitEnrolleeData[0].ToString().Contains("0"))
{
principal = false;
}
}
enrolleePolNumber = policyNumber.Value.Substring(1, policyNumber.Value.Length - 2);
if (splitSectionCount == 5)
{
lName = splitEnrolleeData[2].ToString();
fName = splitEnrolleeData[3].ToString();
dob = Convert.ToDateTime(splitEnrolleeData[4].ToString());
hosp = getHospitalID(hospitalCode);
if (principal == true)
{
if (checkIfPolicyNumberExists(enrolleePolNumber) == false)
{
registerEnrollee(enrolleePolNumber, fName, lName, dob, hosp.ToString());
}
}
else if (principal == false)
{
if (checkIfDependantPolicyNumberExists(enrolleePolNumber, fName) == false)
{
registerDependant(enrolleePolNumber, fName, lName, dob, hosp.ToString());
}
}
}
else if (splitSectionCount == 4)
{
lName = splitEnrolleeData[1].ToString();
fName = splitEnrolleeData[2].ToString();
dob = Convert.ToDateTime(splitEnrolleeData[3].ToString());
hosp = getHospitalID(hospitalCode);
if (principal == true)
{
if (checkIfPolicyNumberExists(enrolleePolNumber) == false)
{
registerEnrollee(enrolleePolNumber, fName, lName, dob, hosp.ToString());
}
}
else if (principal == false)
{
if (checkIfDependantPolicyNumberExists(enrolleePolNumber, fName) == false)
{
registerDependant(enrolleePolNumber, fName, lName, dob, hosp.ToString());
}
}
}
}
}
}
catch (Exception ex)
{
MetroFramework.MetroMessageBox.Show(this, "Error retrieving subsitring: " + ex.Message);
}
}