using framework_business;
using framework_library;
using MediswitchWebService;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Text;
///
/// Summary description for MediSwitch
///
public class MediSwitch
{
MediswitchGatewayV2Service medClient;
oMSSetup mainSetup;
ArrayList mod0008IdList, mod0009IdList, mod0018IdList, mod0014IdList;
///
/// Constructor
///
public MediSwitch()
{
InstantiateClass();
}
private void InstantiateClass()
{
try
{
medClient = new MediswitchWebService.MediswitchGatewayV2Service();
medClient.Url = ConfigurationManager.AppSettings["Mediswitch.Gateway"];
if (!isOnline())
{
medClient.Url = ConfigurationManager.AppSettings["Mediswitch.Gateway1"];
if (!isOnline())
{
medClient.Url = ConfigurationManager.AppSettings["Mediswitch.Gateway2"];
}
}
foreach (oMSSetup setup in xData.GetTypedByCriteriaSpecific("recId", typeof(oMSSetup), "", ""))
{
mainSetup = setup;
}
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0, false);
}
}
///
/// check if online
///
///
public bool isOnline()
{
return medClient.echoOperation() == "Mediswitch Gateway OK";
}
/////
///// echo operation
/////
/////
//public string echoOperation()
//{
// try
// {
// return medClient.echoOperation();
// }
// catch (Exception ex)
// {
// exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
// return ex.Message.ToString();
// }
//}
///
/// single MSV call
///
///
///
///
public string MSVPatientDataSingle(string destinationCode, string memberNo, string patientDOB = "")
{
try
{
string txType = enumMSTransactionType.SwitchOnMembershipStatusValidation.GetHashCode().ToString(),
mode = "realtime",
txVersion = "119",
transmissionNo;
int mCounter = 1;//counter for all m records
int lastLogId = 0;
if (patientDOB != "" && patientDOB != "19000101")
{
foreach (oMSMsvResponse lastMSVResponse in xData.GetTypedByCriteriaSpecific("recId", typeof(oMSMsvResponse), "membershipNumber,msDestinationCode", memberNo + "," + destinationCode, "recId DESC"))
{
foreach (oMSMsvResponsePatient lastMSVResponsePatient in xData.GetTypedByCriteriaSpecific("recId", typeof(oMSMsvResponsePatient), "msvResponseId,patientDOB", lastMSVResponse.recId.ToString() + "," + patientDOB, "recId DESC"))
{
lastLogId = lastMSVResponse.msvLogId;
break;
}
break;
}
}
oMSLog logMSV = new oMSLog();
if (lastLogId > 0)
{
foreach (oMSLog log in xData.GetTypedByCriteriaSpecific("recId", typeof(oMSLog), "recId", lastLogId.ToString()))
{
logMSV = log;
}
}
else
{
if (patientDOB == "")//never do MSV when patientDOB is specified - only use last result
{
logMSV.operationType = pNums.MediswitchOperationType.MSV.GetHashCode();
logMSV.requestDate = DateTime.Now;
logMSV.recId = xData.SaveTyped("recId", typeof(oMSLog), logMSV);
transmissionNo = logMSV.recId.ToString(); //transactionNumber - get new trans number from raw table
logMSV.request = SetupPayloadMSV(txVersion, transmissionNo, mCounter, destinationCode, memberNo, patientDOB);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
submitResponse sResponse = medClient.submitOperation(mainSetup.user, mainSetup.passwd, mainSetup.package, destinationCode, txType, mode, txVersion, transmissionNo, logMSV.request);
stopwatch.Stop();
logMSV.roundTripElapsed = Convert.ToInt32(stopwatch.ElapsedMilliseconds);
logMSV.response = sResponse.responsePayload;
logMSV.status = sResponse.status;
logMSV.swref = sResponse.swref;
logMSV.retry = sResponse.retry;
if (sResponse.responsePayload == "XML Validation error")
{
Exception ex = new Exception("Custom Exception: XML Validation error");
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
else
ProcessMSVResponse(logMSV);
logMSV.responseDate = DateTime.Now;
xData.UpdateTyped("recId", logMSV.recId.ToString(), typeof(oMSLog), logMSV);
}
}
return logMSV.response;
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
private void ProcessMSVResponse(oMSLog logMSV)
{
try
{
string responsePayload = logMSV.response;
oMSMsvResponse msvResponse = new oMSMsvResponse();
msvResponse.msvLogId = logMSV.recId;
msvResponse.recId = xData.SaveTyped("recId", typeof(oMSMsvResponse), msvResponse);
using (System.IO.StringReader reader = new System.IO.StringReader(responsePayload.ToString()))
{
string line;
while ((line = reader.ReadLine()) != null)
{
string[] splitLine = line.Split('|');
switch (splitLine[0])
{
case "H":
break;
case "S":
break;
case "M":
msvResponse.msvLevel = Convert.ToInt32(splitLine[1]);
msvResponse.memberSurname = splitLine[2];
msvResponse.memberFullNames = splitLine[3];
msvResponse.membershipNumber = splitLine[4];
msvResponse.memberIdNumber = splitLine[5];
msvResponse.memberAccountNo = splitLine[6];
msvResponse.address1 = splitLine[7];
msvResponse.address2 = splitLine[8];
msvResponse.town = splitLine[9];
msvResponse.postalCode = splitLine[10];
msvResponse.mobileNo = splitLine[11];
msvResponse.medSchemeName = splitLine[12];
msvResponse.medSchemeRegNo = splitLine[13];
msvResponse.medSchemeRegTypeInd = splitLine[14];
msvResponse.medSchemePlanName = splitLine[15];
msvResponse.medSchemePlanRefNo = splitLine[16];
msvResponse.msDestinationCode = splitLine[17];
msvResponse.medSchemeContactNo = splitLine[18];
xData.UpdateTyped("recId", msvResponse.recId.ToString(), typeof(oMSMsvResponse), msvResponse);
break;
case "P":
oMSMsvResponsePatient msvResponsePatient = new oMSMsvResponsePatient();
msvResponsePatient.msvResponseId = msvResponse.recId;
msvResponsePatient.dependantCode = splitLine[1];
msvResponsePatient.patientSurname = splitLine[2];
msvResponsePatient.patientInitials = splitLine[3];
msvResponsePatient.patientFullName = splitLine[4];
msvResponsePatient.patientDOB = DateTime.ParseExact(splitLine[5] == "" ? "19000101" : splitLine[5], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
msvResponsePatient.patientIdNumber = splitLine[6];
msvResponsePatient.patientGender = splitLine[7];
msvResponsePatient.medSchemeEffectiveDate = DateTime.ParseExact(splitLine[8] == "" ? "19000101" : splitLine[8], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
msvResponsePatient.medSchemeTerminationDate = DateTime.ParseExact(splitLine[9] == "" ? "19000101" : splitLine[9], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
msvResponsePatient.medSchemeStatus = splitLine[10];
xData.SaveTyped("recId", typeof(oMSMsvResponsePatient), msvResponsePatient);
break;
case "RV":
oMSMsvResponseLine msvResponseLine = new oMSMsvResponseLine();
msvResponseLine.msvResponseId = msvResponse.recId;
break;
case "E":
break;
default: break;
}
}
}
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
}
///
/// MSV Request Payload
///
///
///
///
///
///
///
public string SetupPayloadMSV(string txVersion, string transmissionNo, int mCounter, string destinationCode, string memberNo, string patientDOB)
{
try
{
oMSMsv msv = new oMSMsv();
msv.msvLogId = Convert.ToInt32(transmissionNo);
StringBuilder payloadBuilder = new StringBuilder();
payloadBuilder.AppendLine("H|" +
transmissionNo + "|" +
txVersion + "|" +
mainSetup.softwareName + "|");
//S
string PMADatasetID = "1"; //???
payloadBuilder.AppendLine("S|" +
DateTime.Now.ToString("yyyyMMddhhmm") + "|" +
mainSetup.bpPCNS + "|" +
mainSetup.bpName + "|" +
PMADatasetID + "|");
//M
msv.msvLevel = 1;
msv.memberIdNumber = "";
msv.memberTitle = "";
msv.memberInitials = "";
msv.memberSurname = "";
msv.memberFullNames = "";
msv.membershipNumber = memberNo;
msv.cardSwipeInd = false;
msv.memberAccountNo = "1";
msv.msDestinationCode = destinationCode;
payloadBuilder.AppendLine("M|" +
msv.msvLevel + "|" +
msv.memberIdNumber + "|" +
msv.memberTitle + "|" +
msv.memberInitials + "|" +
msv.memberSurname + "|" +
msv.memberFullNames + "|" +
msv.membershipNumber + "|" +
(msv.cardSwipeInd ? "Y" : "N") + "|" +
msv.memberAccountNo + "|" +
msv.msDestinationCode + "|");
msv.recId = xData.SaveTyped("recId", typeof(oMSMsv), msv);
//P
oMSMsvPatient msvPatient = new oMSMsvPatient();
msvPatient.msvId = msv.recId;
msvPatient.dependantCode = "";
msvPatient.patientSurname = "";
msvPatient.patientInitials = "";
msvPatient.patientDOB = DateTime.ParseExact(patientDOB == "" ? "19000101" : patientDOB, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
msvPatient.patientGender = "";
msvPatient.patientRelationCode = "";
msvPatient.patientIdNumber = "";
payloadBuilder.AppendLine("P|" +
msvPatient.dependantCode + "|" +
msvPatient.patientSurname + "|" +
msvPatient.patientInitials + "|" +
msvPatient.patientFullName + "|" +
(msvPatient.patientDOB.ToString("yyyyMMdd") == "19000101" ? "" : msvPatient.patientDOB.ToString("yyyyMMdd")) + "|" +
msvPatient.patientGender + "|" +
msvPatient.patientRelationCode + "|" +
msvPatient.patientIdNumber + "|");
xData.SaveTyped("recId", typeof(oMSMsvPatient), msvPatient);
payloadBuilder.AppendLine("E|" +
transmissionNo + "|" +
mCounter.ToString() + "|");
return payloadBuilder.ToString();
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
///
/// 509 check
///
///
public string GetSchemes()
{
/*
TEST2874
test7139
SWITCHON
509
1
*/
try
{
fetchResponse fResponse = medClient.fetchOperation(mainSetup.user, mainSetup.passwd, mainSetup.package, "509", "", "1");
logFetchResponse(fResponse);
Process509(fResponse);
return fResponse.responsePayload.ToString();
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
private static void Process509(fetchResponse fResponse)
{
StringBuilder changeTable = new StringBuilder();
bool hasChanges = false;
changeTable.AppendLine("
");
changeTable.AppendLine("");
changeTable.AppendLine("| Medical Scheme Name | ");
changeTable.AppendLine("Administrator | ");
changeTable.AppendLine("QEDI Code | ");
changeTable.AppendLine("Destination Code | ");
changeTable.AppendLine("Allow MSV | ");
changeTable.AppendLine("Allow Reversal | ");
changeTable.AppendLine("Mediswitch End Date | ");
changeTable.AppendLine("New Entry | ");
changeTable.AppendLine("
");
using (System.IO.StringReader reader = new System.IO.StringReader(fResponse.responsePayload.ToString()))
{
string line;
//DC
string sDCCode = "",
sDCQEDICode = "",
sDCMedSchemeName = "",
sDCAdminName = "",
sDCMSVAllowed = "",
sDCReversalAllowed = "",
sDCMSEndDate = "";
while ((line = reader.ReadLine()) != null)
{
string[] splitLine = line.Split('|');
switch (splitLine[0])
{
case "DC":
sDCCode = splitLine[1];
sDCQEDICode = splitLine[2];
sDCMedSchemeName = splitLine[3];
sDCAdminName = splitLine[6];
sDCMSEndDate = splitLine[16];
sDCMSVAllowed = splitLine[17];
sDCReversalAllowed = splitLine[18];
//saveDC
oMedicalAdministrator medAdmin = new oMedicalAdministrator();
medAdmin.msDestinationCode = sDCCode;
medAdmin.msQEDICode = sDCQEDICode;
medAdmin.medSchemeName = sDCMedSchemeName;
medAdmin.administratorName = sDCAdminName;
medAdmin.msMSVAllowed = sDCMSVAllowed == "Y";
medAdmin.msReversalAllowed = sDCReversalAllowed == "Y";
medAdmin.msEndDate = DateTime.ParseExact(sDCMSEndDate == "" ? "19000101" : sDCMSEndDate, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
medAdmin.recId = 0;
foreach (oMedicalAdministrator admin in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalAdministrator), "msDestinationCode", sDCCode.ToString()))
{
medAdmin.recId = admin.recId;
medAdmin.dateAdded = admin.dateAdded;
medAdmin.dateUpdated = admin.dateUpdated;
if (!(admin.medSchemeName == medAdmin.medSchemeName &&
admin.administratorName == medAdmin.administratorName &&
admin.msQEDICode == medAdmin.msQEDICode &&
admin.msMSVAllowed == medAdmin.msMSVAllowed &&
admin.msReversalAllowed == medAdmin.msReversalAllowed &&
admin.msEndDate == medAdmin.msEndDate))
{
medAdmin.dateUpdated = DateTime.Now;
hasChanges = true;
//email admins change log
changeTable.AppendLine("");
changeTable.AppendLine("" + medAdmin.medSchemeName + " (was: " + admin.medSchemeName + ")" : ">" + medAdmin.medSchemeName) + " | ");
changeTable.AppendLine("" + medAdmin.administratorName + " (was: " + admin.administratorName + ")" : ">" + medAdmin.administratorName) + " | ");
changeTable.AppendLine("" + medAdmin.msQEDICode + " (was: " + admin.msQEDICode + ")" : ">" + medAdmin.msQEDICode) + " | ");
changeTable.AppendLine("" + medAdmin.msDestinationCode + " (was: " + admin.msDestinationCode + ")" : ">" + medAdmin.msDestinationCode) + " | ");
changeTable.AppendLine("" + medAdmin.msMSVAllowed + " (was: " + admin.msMSVAllowed + ")" : ">" + medAdmin.msMSVAllowed) + " | ");
changeTable.AppendLine("" + medAdmin.msReversalAllowed + " (was: " + admin.msReversalAllowed + ")" : ">" + medAdmin.msReversalAllowed) + " | ");
changeTable.AppendLine("" + medAdmin.msEndDate + " (was: " + admin.msEndDate + ")" : ">" + medAdmin.msEndDate) + " | ");
changeTable.AppendLine("No | ");
changeTable.AppendLine("
");
}
}
if (medAdmin.recId == 0)
{
medAdmin.dateAdded = DateTime.Now;
hasChanges = true;
changeTable.AppendLine("");
changeTable.AppendLine("| " + medAdmin.medSchemeName + " | ");
changeTable.AppendLine("" + medAdmin.administratorName + " | ");
changeTable.AppendLine("" + medAdmin.msQEDICode + " | ");
changeTable.AppendLine("" + medAdmin.msDestinationCode + " | ");
changeTable.AppendLine("" + medAdmin.msMSVAllowed + " | ");
changeTable.AppendLine("" + medAdmin.msReversalAllowed + " | ");
changeTable.AppendLine("" + medAdmin.msEndDate + " | ");
changeTable.AppendLine("Yes | ");
changeTable.AppendLine("
");
xData.SaveTyped("recId", typeof(oMedicalAdministrator), medAdmin);
}
else
xData.UpdateTyped("recId", medAdmin.recId.ToString(), typeof(oMedicalAdministrator), medAdmin);
break;
default:
break;
}
}
changeTable.AppendLine("
");
if (hasChanges)
{
string emailTemplate = string.Empty;
//get templates
foreach (oTemplate template in xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateTypeId", pNums.TemplateType.OutboundResponse.GetHashCode().ToString(), "templateName"))
{
if (template.templateName.ToLower().Contains("509"))
{
emailTemplate = template.templateContent;
}
}
emailTemplate = emailTemplate.Replace("{changeTable}", changeTable.ToString());
oEmail mail = new oEmail();
mail.Body = emailTemplate;
mail.Subject = "Medical Adminstrator Update";
mail.fromAddress = ConfigurationManager.AppSettings["from"];
mail.toAddress = ConfigurationManager.AppSettings["admin"];
communication.SendAnEmail(mail);
}
}
}
public string ClaimPatientDataSingle(oAccount account, bool testEra, bool send = false)
{
try
{
//JasR 2016-04-12 no need to do this check as mediswitch verifies it anyway
//if (!account.isIOD)
//{
// string msvResult = ValidateMSVPatientData(ref account);
// if (msvResult != string.Empty)
// {
// return "MSV Failed: " + msvResult;
// }
//}
string txType = enumMSTransactionType.SwitchClaim_GeneralMedical.GetHashCode().ToString(),
mode = "realtime",
txVersion = "120",
transmissionNo;
string msDestinationCode = "";
bool splitMods = false;
foreach (oMedicalScheme medScheme in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalScheme), "code", account.medCode))
{
msDestinationCode = medScheme.msDestinationCode;
foreach (oMedicalAdministrator medAdmin in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalAdministrator), "msDestinationCode", msDestinationCode))
{
splitMods = medAdmin.splitModifiers;
}
}
int mCounter = 1;//counter for all m records
oMSLog logClaim = new oMSLog();
logClaim.operationType = pNums.MediswitchOperationType.Claim.GetHashCode();
logClaim.requestDate = DateTime.Now;
logClaim.recId = xData.SaveTyped("recId", typeof(oMSLog), logClaim);
transmissionNo = logClaim.recId.ToString(); //transactionNumber - get new trans number from raw table
logClaim.request = SetupPayloadClaim(txVersion, transmissionNo, mCounter, account, testEra, "", splitMods);
if (logClaim.request == "No Valid Destination Code")
return "No Valid Destination Code";
if (logClaim.request == "No Valid Transactions")
return "No Valid Transactions";
if (send)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
submitResponse sResponse = medClient.submitOperation(mainSetup.user, mainSetup.passwd, mainSetup.package, msDestinationCode, txType, mode, txVersion, transmissionNo, logClaim.request);
stopwatch.Stop();
logClaim.roundTripElapsed = Convert.ToInt32(stopwatch.ElapsedMilliseconds);
logClaim.response = sResponse.responsePayload;
logClaim.status = sResponse.status;
logClaim.swref = sResponse.swref;
logClaim.retry = sResponse.retry;
if (sResponse.responsePayload == "XML Validation error")
{
Exception ex = new Exception("Custom Exception: XML Validation error");
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
else
{
if (logClaim.response.Contains("|"))//no pipes == error
{
ProcessClaimResponse(logClaim);
}
}
}
logClaim.responseDate = DateTime.Now;
xData.UpdateTyped("recId", logClaim.recId.ToString(), typeof(oMSLog), logClaim);
if (send)
return logClaim.response;
else
return logClaim.request;
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
public string ReverseClaim(string claimLogId)
{
try
{
oAccount account = new oAccount();
foreach (oMSClaimResponse msClaimResponse in xData.GetTypedByCriteriaSpecific("recId", typeof(oMSClaimResponse), "claimLogId", claimLogId))
{
foreach (oAccount acc in xData.GetTypedByCriteriaSpecific("recId", typeof(oAccount), "invoiceNo,isVisible", msClaimResponse.claimRefNo.ToString() + ",1"))
{
account = acc;
}
}
ValidateMSVPatientData(ref account);
string txType = enumMSTransactionType.SwitchClaim_Reversal.GetHashCode().ToString(),
mode = "realtime",
txVersion = "120",
transmissionNo = claimLogId;
string msDestinationCode = "";
foreach (oMedicalScheme medScheme in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalScheme), "code", account.medCode))
{
msDestinationCode = medScheme.msDestinationCode;
}
int mCounter = 1;//counter for all m records
oMSLog logClaim = new oMSLog();
logClaim.operationType = pNums.MediswitchOperationType.Reversal.GetHashCode();
logClaim.requestDate = DateTime.Now;
logClaim.recId = xData.SaveTyped("recId", typeof(oMSLog), logClaim);
transmissionNo = logClaim.recId.ToString(); //transactionNumber - get new trans number from raw table
logClaim.request = SetupPayloadClaim(txVersion, transmissionNo, mCounter, account, false, claimLogId);
if (logClaim.request == "No Valid Destination Code")
return "No Valid Destination Code";
if (logClaim.request == "No Valid Transactions")
return "No Valid Transactions";
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
submitResponse sResponse = medClient.submitOperation(mainSetup.user, mainSetup.passwd, mainSetup.package, msDestinationCode, txType, mode, txVersion, claimLogId, logClaim.request);
stopwatch.Stop();
logClaim.roundTripElapsed = Convert.ToInt32(stopwatch.ElapsedMilliseconds);
logClaim.responseDate = DateTime.Now;
logClaim.response = sResponse.responsePayload;
logClaim.retry = sResponse.retry;
logClaim.status = sResponse.status;
logClaim.swref = sResponse.swref;
xData.UpdateTyped("recId", logClaim.recId.ToString(), typeof(oMSLog), logClaim);
if (sResponse.responsePayload == "XML Validation error")
{
Exception ex = new Exception("Custom Exception: XML Validation error");
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
else if (sResponse.status == "ERROR")
return sResponse.responsePayload;
else
ProcessClaimResponse(logClaim, true);
return "";
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
public void ProcessDelayed()
{
try
{
bool moreFiles = false;
do
{
fetchResponse fResponse = GetDelayedResponses();
if (fResponse != null)
{
if (fResponse.feedbackType != string.Empty)
{
logFetchResponse(fResponse);
//check
switch (fResponse.feedbackType)
{
case "509"://destination codes
Process509(fResponse);
break;
case "302"://claim
GetRelatedClaimAndProcess(fResponse);
break;
case "303"://reversal
GetRelatedClaimAndProcess(fResponse);
break;
default:
LogUnknownFeedback(fResponse);
break;
}
//cater for all known - if not known - log and sent notify
}
moreFiles = (fResponse.moreFiles == "1");
}
} while (moreFiles);
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
}
private void LogUnknownFeedback(fetchResponse fResponse)
{
logFetchResponse(fResponse);
Exception ex = new Exception("Custom Exception: Unknown Response Downloaded");
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
private void GetRelatedClaimAndProcess(fetchResponse fResponse)
{
foreach (oMSLog logClaim in xData.GetTypedByCriteriaSpecific("recId", typeof(oMSLog), "recId", fResponse.originalUserRef))
{
logClaim.response = fResponse.responsePayload;
logClaim.responseDate = DateTime.Now;
xData.UpdateTyped("recId", logClaim.recId.ToString(), typeof(oMSLog), logClaim);
string invoiceNo = ProcessClaimResponse(logClaim);
//send mail notify
string patientName = "", patientSurname = "";
foreach (oAccount accountItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oAccount), "invoiceNo", invoiceNo))
{
patientName = accountItem.patientName;
patientSurname = accountItem.patientSurname;
break;
}
string emailTemplate = string.Empty;
//get templates
foreach (oTemplate template in xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateTypeId", pNums.TemplateType.OutboundResponse.GetHashCode().ToString(), "templateName"))
{
if (template.templateName.ToLower().Contains("Email Queued Response"))
{
emailTemplate = template.templateContent;
}
}
emailTemplate = emailTemplate.Replace("{patientName}", patientName);
emailTemplate = emailTemplate.Replace("{patientSurname}", patientSurname);
emailTemplate = emailTemplate.Replace("{invoiceNo}", invoiceNo);
oEmail mail = new oEmail();
mail.Body = emailTemplate;
mail.Subject = "Queued Transaction Processed";
mail.fromAddress = ConfigurationManager.AppSettings["from"];
mail.toAddress = ConfigurationManager.AppSettings["admin"];
communication.SendAnEmail(mail);
}
}
private fetchResponse GetDelayedResponses()
{
try
{
if (medClient == null)
InstantiateClass();
fetchResponse fResponse = medClient.fetchOperation(mainSetup.user, mainSetup.passwd, mainSetup.package, "", "", "0");
return fResponse;
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return null;
}
}
private void logFetchResponse(fetchResponse fResponse, int payloadLogId = 0)
{
try
{
oMSFetchResponseLog fetchResponseLog = new oMSFetchResponseLog();
fetchResponseLog.feedbackType = fResponse.feedbackType;
fetchResponseLog.feedbackVersion = fResponse.feedbackVersion;
fetchResponseLog.fileDate = fResponse.fileDate;
fetchResponseLog.fileName = fResponse.fileName;
fetchResponseLog.moreFiles = fResponse.moreFiles;
fetchResponseLog.originalDataSetId = fResponse.originalDataSetId;
fetchResponseLog.originalSwref = fResponse.originalSwref;
fetchResponseLog.originalUserRef = fResponse.originalUserRef;
fetchResponseLog.status = fResponse.status;
fetchResponseLog.responsePayloadId = payloadLogId;
xData.SaveTyped("recId", typeof(oMSFetchResponseLog), fetchResponseLog);
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
}
private string ValidateMSVPatientData(ref oAccount account)
{
try
{
string msDestinationCode = "";
foreach (oMedicalScheme medScheme in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalScheme), "code", account.medCode))
{
msDestinationCode = medScheme.msDestinationCode;
}
//if (msDestinationCode == "") - ne need for this check - the vClaimables view already checks
// return "No SwithClaim Destination Code Found";
string memberNo = account.medAidNumber;
string patientDOB;
DataTable surfaceData = xData.GetSurfaceItemData(0, account.surfaceItemId);
patientDOB = Convert.ToDateTime(surfaceData.Rows[0]["PatientInformation_PatientDetails_DateofBirth"]).ToString("yyyyMMdd");
string msvResponse = MSVPatientDataSingle(msDestinationCode, memberNo, patientDOB);
if (!msvResponse.Contains("|")) // no pipes == no payload
{
return msvResponse;
}
string pPatientDOB = string.Empty,
pMedSchemeEffectiveDate = string.Empty,
pMedSchemeTerminationDate = string.Empty,
pMedSchemeStatusCode = string.Empty;
string rvDecsription = string.Empty;
bool isValid = false;
using (System.IO.StringReader reader = new System.IO.StringReader(msvResponse.ToString()))
{
string line;
while ((line = reader.ReadLine()) != null)
{
string[] splitLine = line.Split('|');
switch (splitLine[0])
{
case "H":
break;
case "S":
break;
case "M":
break;
case "P":
if (patientDOB == "" || patientDOB == splitLine[5])
{
account.patientCode = splitLine[1] != "" ? splitLine[1] : account.patientCode;
account.patientSurname = splitLine[2] != "" ? splitLine[2] : account.patientSurname;
account.surname = splitLine[2] != "" ? splitLine[2] : account.surname;
account.patientInitials = splitLine[3] != "" ? splitLine[3] : account.patientInitials;
account.initials = splitLine[3] != "" ? splitLine[3] : account.initials;
account.patientName = splitLine[4] != "" ? splitLine[4] : account.patientName;
account.name = splitLine[4] != "" ? splitLine[4] : account.name;
pPatientDOB = splitLine[5];
account.birthDate = DateTime.ParseExact(splitLine[5] == "" ? "19000101" : splitLine[5], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
account.idNumber = splitLine[6] != "" ? splitLine[6] : account.idNumber;
switch (splitLine[7])
{
case "M":
account.gender = "Male";
break;
case "F":
account.gender = "Female";
break;
default:
account.gender = account.gender;
break;
}
pMedSchemeEffectiveDate = splitLine[8];
pMedSchemeTerminationDate = splitLine[9];
pMedSchemeStatusCode = splitLine[10];
}
break;
case "RV":
isValid = splitLine[1] == "02";
if (!isValid)
rvDecsription = splitLine[5];
break;
case "E":
break;
default: break;
}
}
}
return rvDecsription;
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
public string SetupPayloadClaim(string txVersion, string transmissionNo, int mCounter, oAccount account, bool testEra, string reversalRef = "", bool splitMods = false)
{
try
{
decimal fClaimNetAmount = 0,
fClaimGrossAmount = 0,
fTotalClaimAmount = 0,
fClaimDiscountAmount = 0,
fClaimLevyAmount = 0,
fClaimMMAPSurcharge = 0,
fClaimCoPaymentAmount = 0,
fClaimPatientLiablePortion = 0,
fClaimMedicalFundLiableAmount = 0,
fMemberReimbursementAmount = 0;
oMSClaim msClaim = new oMSClaim();
msClaim.claimLogId = Convert.ToInt32(transmissionNo);
StringBuilder payloadBuilder = new StringBuilder();
payloadBuilder.AppendLine(GetPayloadClaimH(reversalRef == "" ? transmissionNo : reversalRef, txVersion));
payloadBuilder.AppendLine(GetPayloadClaimS());
string msDestinationCode = string.Empty;
payloadBuilder.AppendLine(GetPayloadClaimM(account, testEra, ref msClaim, ref msDestinationCode));
if (msDestinationCode == string.Empty)
return "No Valid Destination Code";
payloadBuilder.AppendLine(GetPayloadClaimP(account, ref msClaim));
msClaim.recId = xData.SaveTyped("recId", typeof(oMSClaim), msClaim);
//refering dr number on account table - if > 0
if (account.referringDocNo != string.Empty && account.referringDocNo != "0")
payloadBuilder.AppendLine(GetPayloadClaimDR(account, enumDrTypeCode_DR.Referring_Doctor.GetHashCode(), msClaim.recId, 0));
int treatmentNumber = 0;
ArrayList accountsToClaim = xData.GetTypedByCriteriaSpecific("recId", typeof(oAccount), "invoiceNo,isVisible,claimSend,liableMed", account.invoiceNo.ToString() + ",1,1,~>0", "sequence");
int claimCount = 0;
oAccount modAccount0008 = new oAccount();
//modAccount0008.amount = 0;
//mod0008IdList = new ArrayList();
oAccount modAccount0009 = new oAccount();
//modAccount0009.amount = 0;
//mod0009IdList = new ArrayList();
oAccount modAccount0018 = new oAccount();
//modAccount0018.amount = 0;
//mod0018IdList = new ArrayList();
oAccount modAccount0014 = new oAccount();
//loop through all treatments for patient - all invoice lines
foreach (oAccount accountItem in accountsToClaim)
{
claimCount++;
//if (accountItem.liableMed > 0)
//{
if (accountItem.modifier1 != string.Empty)//is Modifier
{
if (claimCount > 1)
{
if (((oAccount)accountsToClaim[claimCount - 1]).procedureCode != accountItem.procedureCode)
{
continue;
}
}
else
{
continue;
}
}
oMSClaimTreatment msTreatment = new oMSClaimTreatment();
if (splitMods)
{
treatmentNumber++;
msTreatment.claimId = msClaim.recId;
msTreatment.treatmentNo = treatmentNumber;
payloadBuilder.AppendLine(GetPayloadClaimT(accountItem, testEra, ref msTreatment, reversalRef));
msTreatment.recId = xData.SaveTyped("recId", typeof(oMSClaimTreatment), msTreatment);
//DR - attending
payloadBuilder.AppendLine(GetPayloadClaimDR(accountItem, enumDrTypeCode_DR.Attending_Treating_Prescribing_Doctor.GetHashCode(), 0, msTreatment.recId));
//if assistant - dr
if ((accountItem.modifier1 == "0008" || accountItem.modifier1 == "0009") && accountItem.modifier2 != string.Empty)
{
payloadBuilder.AppendLine(GetPayloadClaimDR(accountItem, enumDrTypeCode_DR.Assisting_Doctor.GetHashCode(), 0, msTreatment.recId));
}
//MD - if inline
if (accountItem.modifier4 != string.Empty)
payloadBuilder.AppendLine(GetPayloadClaimMD(accountItem, msTreatment.recId));
//D - multi
//D primary
payloadBuilder.AppendLine(GetPayloadClaimD(accountItem, true, msTreatment.recId));
//D other
string icd10List = string.Empty;
if (accountItem.icd2 != string.Empty)
icd10List += accountItem.icd2 + ",";
if (accountItem.icd3 != string.Empty)
icd10List += accountItem.icd3 + ",";
if (accountItem.icd4 != string.Empty)
icd10List += accountItem.icd4 + ",";
if (accountItem.icd5 != string.Empty)
icd10List += accountItem.icd5 + ",";
//GR - Added external Cause code
if (accountItem.externalCause != String.Empty)
icd10List += accountItem.externalCause + ",";
if (icd10List != string.Empty)
{
foreach (string icd10Item in icd10List.Split(','))
{
if (icd10Item != string.Empty)
payloadBuilder.AppendLine(GetPayloadClaimD(accountItem, false, msTreatment.recId, icd10Item));
}
}
//Z
payloadBuilder.AppendLine(GetPayLoadClaimZ(accountItem,
ref fClaimNetAmount,
ref fClaimGrossAmount,
ref fTotalClaimAmount,
ref fClaimDiscountAmount,
ref fClaimLevyAmount,
ref fClaimMMAPSurcharge,
ref fClaimCoPaymentAmount,
ref fClaimPatientLiablePortion,
ref fClaimMedicalFundLiableAmount,
ref fMemberReimbursementAmount,
ref msTreatment));
xData.UpdateTyped("recId", msTreatment.recId.ToString(), typeof(oMSClaimTreatment), msTreatment);
//}
}
else
{
if (accountItem.modifier1 != string.Empty)//is Modifier
{
switch (accountItem.modifier1)
{
case "0008":
if (modAccount0008.recId == 0)
{
mod0008IdList = new ArrayList();
modAccount0008 = accountItem;
}
else
{
if (mod0008IdList == null)
{
mod0008IdList = new ArrayList();
modAccount0008 = accountItem;
}
modAccount0008.amount = modAccount0008.amount + accountItem.amount;
}
mod0008IdList.Add(accountItem.recId);
break;
case "0009":
if (modAccount0009.recId == 0)
{
mod0009IdList = new ArrayList();
modAccount0009 = accountItem;
}
else
{
if (mod0009IdList == null)
{
mod0009IdList = new ArrayList();
modAccount0009 = accountItem;
}
modAccount0009.amount = modAccount0009.amount + accountItem.amount;
}
mod0009IdList.Add(accountItem.recId);
break;
case "0018":
if (modAccount0018.recId == 0)
{
mod0018IdList = new ArrayList();
modAccount0018 = accountItem;
}
else
{
if (mod0018IdList == null)
{
mod0018IdList = new ArrayList();
modAccount0018 = accountItem;
}
modAccount0018.amount = modAccount0018.amount + accountItem.amount;
}
mod0018IdList.Add(accountItem.recId);
break;
case "0014":
if (modAccount0014.recId == 0)
{
mod0014IdList = new ArrayList();
modAccount0014 = accountItem;
}
else
{
if (mod0014IdList == null)
{
mod0014IdList = new ArrayList();
modAccount0014 = accountItem;
}
modAccount0014.amount = modAccount0014.amount + accountItem.amount;
}
mod0014IdList.Add(accountItem.recId);
break;
default:
break;
}
}
else
{
treatmentNumber++;
msTreatment.claimId = msClaim.recId;
msTreatment.treatmentNo = treatmentNumber;
payloadBuilder.AppendLine(GetPayloadClaimT(accountItem, testEra, ref msTreatment, reversalRef));
msTreatment.recId = xData.SaveTyped("recId", typeof(oMSClaimTreatment), msTreatment);
//DR - attending
payloadBuilder.AppendLine(GetPayloadClaimDR(accountItem, enumDrTypeCode_DR.Attending_Treating_Prescribing_Doctor.GetHashCode(), 0, msTreatment.recId));
//if assistant - dr
if ((accountItem.modifier1 == "0008" || accountItem.modifier1 == "0009") && accountItem.modifier2 != string.Empty)
{
payloadBuilder.AppendLine(GetPayloadClaimDR(accountItem, enumDrTypeCode_DR.Assisting_Doctor.GetHashCode(), 0, msTreatment.recId));
}
//MD - if inline
if (accountItem.modifier4 != string.Empty)
payloadBuilder.AppendLine(GetPayloadClaimMD(accountItem, msTreatment.recId));
//D - multi
//D primary
payloadBuilder.AppendLine(GetPayloadClaimD(accountItem, true, msTreatment.recId));
//D other
string icd10List = string.Empty;
if (accountItem.icd2 != string.Empty)
icd10List += accountItem.icd2 + ",";
if (accountItem.icd3 != string.Empty)
icd10List += accountItem.icd3 + ",";
if (accountItem.icd4 != string.Empty)
icd10List += accountItem.icd4 + ",";
if (accountItem.icd5 != string.Empty)
icd10List += accountItem.icd5 + ",";
//GR - Added external Cause code
if (accountItem.externalCause != String.Empty)
icd10List += accountItem.externalCause + ",";
if (icd10List != string.Empty)
{
foreach (string icd10Item in icd10List.Split(','))
{
if (icd10Item != string.Empty)
payloadBuilder.AppendLine(GetPayloadClaimD(accountItem, false, msTreatment.recId, icd10Item));
}
}
//Z
payloadBuilder.AppendLine(GetPayLoadClaimZ(accountItem,
ref fClaimNetAmount,
ref fClaimGrossAmount,
ref fTotalClaimAmount,
ref fClaimDiscountAmount,
ref fClaimLevyAmount,
ref fClaimMMAPSurcharge,
ref fClaimCoPaymentAmount,
ref fClaimPatientLiablePortion,
ref fClaimMedicalFundLiableAmount,
ref fMemberReimbursementAmount,
ref msTreatment));
xData.UpdateTyped("recId", msTreatment.recId.ToString(), typeof(oMSClaimTreatment), msTreatment);
//}
}
}
}
if (modAccount0008.amount > 0)
{
AppendModifierLines(reversalRef, testEra, ref fClaimNetAmount, ref fClaimGrossAmount, ref fTotalClaimAmount, ref fClaimDiscountAmount, ref fClaimLevyAmount, ref fClaimMMAPSurcharge, ref fClaimCoPaymentAmount, ref fClaimPatientLiablePortion, ref fClaimMedicalFundLiableAmount, ref fMemberReimbursementAmount, msClaim, ref payloadBuilder, ref treatmentNumber, modAccount0008);
}
if (modAccount0009.amount > 0)
{
AppendModifierLines(reversalRef, testEra, ref fClaimNetAmount, ref fClaimGrossAmount, ref fTotalClaimAmount, ref fClaimDiscountAmount, ref fClaimLevyAmount, ref fClaimMMAPSurcharge, ref fClaimCoPaymentAmount, ref fClaimPatientLiablePortion, ref fClaimMedicalFundLiableAmount, ref fMemberReimbursementAmount, msClaim, ref payloadBuilder, ref treatmentNumber, modAccount0009);
}
if (modAccount0018.amount > 0)
{
AppendModifierLines(reversalRef, testEra, ref fClaimNetAmount, ref fClaimGrossAmount, ref fTotalClaimAmount, ref fClaimDiscountAmount, ref fClaimLevyAmount, ref fClaimMMAPSurcharge, ref fClaimCoPaymentAmount, ref fClaimPatientLiablePortion, ref fClaimMedicalFundLiableAmount, ref fMemberReimbursementAmount, msClaim, ref payloadBuilder, ref treatmentNumber, modAccount0018);
}
if (modAccount0014.amount > 0)
{
AppendModifierLines(reversalRef, testEra, ref fClaimNetAmount, ref fClaimGrossAmount, ref fTotalClaimAmount, ref fClaimDiscountAmount, ref fClaimLevyAmount, ref fClaimMMAPSurcharge, ref fClaimCoPaymentAmount, ref fClaimPatientLiablePortion, ref fClaimMedicalFundLiableAmount, ref fMemberReimbursementAmount, msClaim, ref payloadBuilder, ref treatmentNumber, modAccount0014);
}
if (treatmentNumber == 0)
return "No Valid Transactions";
//F
payloadBuilder.AppendLine(GetPayloadClaimF(account, fClaimNetAmount, fClaimGrossAmount, fTotalClaimAmount, fClaimDiscountAmount, fClaimLevyAmount, fClaimMMAPSurcharge, fClaimCoPaymentAmount, fClaimPatientLiablePortion, fClaimMedicalFundLiableAmount, fMemberReimbursementAmount, ref msClaim));
xData.UpdateTyped("recId", msClaim.recId.ToString(), typeof(oMSClaim), msClaim);
//E
payloadBuilder.AppendLine(GetPayloadClaimE(reversalRef == "" ? transmissionNo : reversalRef, 1, fTotalClaimAmount));
return payloadBuilder.ToString();
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
private void AppendModifierLines(string reversalRef, bool testEra, ref decimal fClaimNetAmount, ref decimal fClaimGrossAmount, ref decimal fTotalClaimAmount, ref decimal fClaimDiscountAmount, ref decimal fClaimLevyAmount, ref decimal fClaimMMAPSurcharge, ref decimal fClaimCoPaymentAmount, ref decimal fClaimPatientLiablePortion, ref decimal fClaimMedicalFundLiableAmount, ref decimal fMemberReimbursementAmount, oMSClaim msClaim, ref StringBuilder payloadBuilder, ref int treatmentNumber, oAccount modAccount)
{
oMSClaimTreatment msTreatment = new oMSClaimTreatment();
treatmentNumber++;
msTreatment.claimId = msClaim.recId;
msTreatment.treatmentNo = treatmentNumber;
payloadBuilder.AppendLine(GetPayloadClaimT(modAccount, testEra, ref msTreatment, reversalRef));
msTreatment.recId = xData.SaveTyped("recId", typeof(oMSClaimTreatment), msTreatment);
//DR - attending
payloadBuilder.AppendLine(GetPayloadClaimDR(modAccount, enumDrTypeCode_DR.Attending_Treating_Prescribing_Doctor.GetHashCode(), 0, msTreatment.recId));
//if assistant - dr
if ((modAccount.modifier1 == "0008" || modAccount.modifier1 == "0009") && modAccount.modifier2 != string.Empty)
{
payloadBuilder.AppendLine(GetPayloadClaimDR(modAccount, enumDrTypeCode_DR.Assisting_Doctor.GetHashCode(), 0, msTreatment.recId));
}
//D - multi
//D primary
payloadBuilder.AppendLine(GetPayloadClaimD(modAccount, true, msTreatment.recId));
//D other
string icd10List = string.Empty;
if (modAccount.icd2 != string.Empty)
icd10List += modAccount.icd2 + ",";
if (modAccount.icd3 != string.Empty)
icd10List += modAccount.icd3 + ",";
if (modAccount.icd4 != string.Empty)
icd10List += modAccount.icd4 + ",";
if (modAccount.icd5 != string.Empty)
icd10List += modAccount.icd5 + ",";
//GR - Added external Cause code
if (modAccount.externalCause != String.Empty)
icd10List += modAccount.externalCause + ",";
if (icd10List != string.Empty)
{
foreach (string icd10Item in icd10List.Split(','))
{
if (icd10Item != string.Empty)
payloadBuilder.AppendLine(GetPayloadClaimD(modAccount, false, msTreatment.recId, icd10Item));
}
}
//Z
payloadBuilder.AppendLine(GetPayLoadClaimZ(modAccount,
ref fClaimNetAmount,
ref fClaimGrossAmount,
ref fTotalClaimAmount,
ref fClaimDiscountAmount,
ref fClaimLevyAmount,
ref fClaimMMAPSurcharge,
ref fClaimCoPaymentAmount,
ref fClaimPatientLiablePortion,
ref fClaimMedicalFundLiableAmount,
ref fMemberReimbursementAmount,
ref msTreatment));
xData.UpdateTyped("recId", msTreatment.recId.ToString(), typeof(oMSClaimTreatment), msTreatment);
}
#region Claim Request Lines
///
/// Header (Start of Message) Record
///
///
///
///
private string GetPayloadClaimH(string transmissionNo, string txVersion)
{
return "H|" +
transmissionNo.Trim() + "|" +
txVersion.Trim() + "|" +
mainSetup.softwareName.Trim() + "||";
}
///
/// Service Provider Record
///
///
private string GetPayloadClaimS()
{
try
{
string PMADatasetID = "1",
BPVatRegNo = "";
foreach (oMedicalPractice practice in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPractice), "practiceNo", mainSetup.bpPCNS))
{
BPVatRegNo = practice.vatNum;
}
return "S|" +
DateTime.Now.ToString("yyyMMddhhmm").Trim() + "|" +
mainSetup.bpPCNS.Trim() + "|" +
mainSetup.bpName.Trim() + "|" +
PMADatasetID.Trim() + "|" +
BPVatRegNo.Trim() + "|";
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
///
/// Member Record
///
///
///
private string GetPayloadClaimM(oAccount account, bool testEra, ref oMSClaim msClaim, ref string msDestinationCode)
{
try
{
DataTable surfaceData = xData.GetSurfaceItemData(0, account.surfaceItemId);
if (surfaceData.Rows[0]["PatientInformation_PersonResponsibleforAccountPayment_MobileNumber"] != null)
msClaim.memberCellphone = surfaceData.Rows[0]["PatientInformation_PersonResponsibleforAccountPayment_MobileNumber"].ToString();
else if (surfaceData.Rows[0]["PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_MobileNumber"] != null)
msClaim.memberCellphone = surfaceData.Rows[0]["PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_MobileNumber"].ToString();
foreach (oMedicalScheme medScheme in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalScheme), "code", account.medCode))
{
msClaim.msDestinationCode = medScheme.msDestinationCode;
msDestinationCode = medScheme.msDestinationCode;
}
foreach (oMedicalAdministrator medAdmin in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalAdministrator), "msDestinationCode", msClaim.msDestinationCode))
{
if (medAdmin.medSchemeName.Length > 20)
msClaim.medSchemeName = medAdmin.medSchemeName.Substring(0, 20);
else
msClaim.medSchemeName = medAdmin.medSchemeName;
}
//CVH 2018-01-18 Set Test ERA settings
if (testEra)
msClaim.msDestinationCode = "STES0005";
//CVH 2018-08-16 Only send valid South Africa ID Numbers in ID Number field, even though documentation says passport numbers are allowed, medical aids reject it, rather send blank if passport number
//msClaim.memberIdNumber = account.idNumber;
string idPassportNumber = account.idNumber;
decimal temp = 0;
if (idPassportNumber.Trim().Length == 13 && decimal.TryParse(idPassportNumber, out temp))
msClaim.memberIdNumber = idPassportNumber;
msClaim.memberTitle = account.title;
msClaim.memberInitials = account.initials;
msClaim.memberSurname = account.surname;
msClaim.memberFullNames = account.name;
string memberNumber = account.medAidNumber;
if (account.isIOD)
memberNumber = account.iodRefNo.Length > 20 ? account.iodRefNo.Substring(0, 20) : account.iodRefNo;
msClaim.membershipNumber = memberNumber;
msClaim.cardSwipeInd = false;
msClaim.memberAccountNo = account.patientNumber.ToString();
msClaim.address1 = "";
msClaim.address2 = "";
msClaim.town = "";
msClaim.postalCode = "";
msClaim.medSchemePlanName = "";
msClaim.medSchemePlanNo = "";
msClaim.medSchemeRegNo = "";
msClaim.medSchemeRegType = "";
msClaim.medSchemeClaimOption = "";
return "M|" +
msClaim.memberIdNumber.Trim() + "|" +
msClaim.memberTitle.Trim() + "|" +
msClaim.memberInitials.Trim() + "|" +
msClaim.memberSurname.Trim() + "|" +
msClaim.memberFullNames.Trim() + "|" +
msClaim.membershipNumber.Trim() + "|" +
(msClaim.cardSwipeInd ? "Y" : "N") + "|" +
msClaim.memberAccountNo.Trim() + "|" +
msClaim.address1.Trim() + "|" +
msClaim.address2.Trim() + "|" +
msClaim.town.Trim() + "|" +
msClaim.postalCode.Trim() + "|" +
msClaim.memberCellphone.Trim() + "|" +
msClaim.medSchemePlanName.Trim() + "|" +
msClaim.medSchemePlanNo.Trim() + "|" +
msClaim.medSchemeName.Trim() + "|" +
msClaim.medSchemeRegNo.Trim() + "|" +
msClaim.medSchemeRegType.Trim() + "|" +
msClaim.medSchemeClaimOption.Trim() + "|" +
msClaim.msDestinationCode.Trim() + "|";
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
///
/// Patient Record
///
///
///
private string GetPayloadClaimP(oAccount account, ref oMSClaim msClaim)
{
try
{
DataTable surfaceData = xData.GetSurfaceItemData(0, account.surfaceItemId);
msClaim.patientDOB = Convert.ToDateTime(surfaceData.Rows[0]["PatientInformation_PatientDetails_DateofBirth"]);
msClaim.patientGender = surfaceData.Rows[0]["PatientInformation_PatientDetails_Gender"].ToString().Substring(0, 1);
//CVH 2018-08-16 Only send valid South Africa ID Numbers in ID Number field, even though documentation says passport numbers are allowed, medical aids reject it, rather send blank if passport number
//msClaim.patientIdNumber = surfaceData.Rows[0]["PatientInformation_PatientDetails_IDPassportNumber"].ToString();
string idPassportNumber = surfaceData.Rows[0]["PatientInformation_PatientDetails_IDPassportNumber"].ToString();
decimal temp = 0;
if (idPassportNumber.Trim().Length == 13 && decimal.TryParse(idPassportNumber, out temp))
msClaim.patientIdNumber = idPassportNumber;
foreach (oPlaceOfService place in xData.GetTypedByCriteriaSpecific("recId", typeof(oPlaceOfService), "indicator,isActive", account.placeOfService.ToString() + ",1"))
{
msClaim.inOutHospitalInd = GetInOrOutOfHopsital(place.rateType);
}
msClaim.dependantCode = account.patientCode;
msClaim.patientSurname = account.patientSurname;
msClaim.patientInitials = account.patientInitials;
msClaim.patientFullName = account.patientName;
msClaim.patientAccountNo = account.patientNumber.ToString();
msClaim.claimRefNo = account.invoiceNo.ToString();
msClaim.medSchemeAuthNo = account.authorisationNo;
msClaim.patientRelationCode = "";// not required
msClaim.recallDate = new DateTime(1900, 1, 1); //Dentists Only
int patientHeight = 0, patientWeight = 0;
foreach (oAccount accountItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oAccount), "invoiceNo,isVisible,claimSend", account.invoiceNo.ToString() + ",1,1"))
{
if (accountItem.modifier1 == "0018")//BMI>50
{
Int32.TryParse(accountItem.modifier2, out patientHeight);
Int32.TryParse(accountItem.modifier3, out patientWeight);
patientWeight = patientWeight * 1000;//take from kg to g
break;
}
}
msClaim.patientHeight = patientHeight;
msClaim.patientWeight = patientWeight;
//Injury on Duty
msClaim.COIDInd = account.isIOD ? "01" : "";
msClaim.dateOfInjury = account.isIOD ? account.iodDate : new DateTime(1900, 1, 1);
msClaim.employerName = account.isIOD ? account.iodEmployerName : "";
msClaim.employerRegNo = account.isIOD ? account.iodEmployerRegNo : "";
msClaim.employeeNo = account.isIOD ? account.iodEmployeeNo : "";
msClaim.COIDRefNo = account.isIOD ? account.iodRefNo : "";
return "P|" +
msClaim.dependantCode.Trim() + "|" +
msClaim.patientSurname.Trim() + "|" +
msClaim.patientInitials.Trim() + "|" +
msClaim.patientFullName.Trim() + "|" +
utils.stripCharacters(msClaim.patientDOB.ToString("yyyyMMdd")) + "|" +
msClaim.patientGender.Trim() + "|" +
msClaim.patientRelationCode.Trim() + "|" +
msClaim.patientIdNumber.Trim() + "|" +
(msClaim.recallDate.ToString("yyyyMMdd") == "19000101" ? "" : msClaim.recallDate.ToString("yyyyMMdd")) + "|" +
msClaim.COIDInd.Trim() + "|" +
(msClaim.dateOfInjury.ToString("yyyyMMdd") == "19000101" ? "" : msClaim.dateOfInjury.ToString("yyyyMMdd")) + "|" +
msClaim.employerName.Trim() + "|" +
msClaim.employerRegNo.Trim() + "|" +
msClaim.employeeNo.Trim() + "|" +
msClaim.COIDRefNo.Trim() + "|" +
msClaim.medSchemeAuthNo.Trim() + "|" +
msClaim.medSchemeAuthNo.Trim() + "|" +
msClaim.patientAccountNo.Trim() + "|" +
msClaim.inOutHospitalInd.Trim() + "|" +
(msClaim.patientHeight == 0 ? "" : msClaim.patientHeight.ToString().Trim()) + "|" +
(msClaim.patientWeight == 0 ? "" : msClaim.patientWeight.ToString().Trim()) + "|" +
msClaim.claimRefNo.Trim() + "|";
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
///
/// Doctor Record
///
///
///
private string GetPayloadClaimDR(oAccount account, int drType, int claimId, int treatmentId)
{
try
{
oMSClaimDoctor msDoctor = new oMSClaimDoctor();
msDoctor.claimId = claimId;
msDoctor.treatmentId = treatmentId;
msDoctor.doctorTypeCode = ((enumDrTypeCode_DR)drType).GetHashCode().ToString().PadLeft(2, '0');
msDoctor.doctorCMSTypeInd = enumCMSDrType.HPCSA.GetHashCode().ToString().PadLeft(2, '0');
msDoctor.dispensingDocLicenseNo = "";
msDoctor.designatedServiceProviderInd = false;
msDoctor.doctorTrackingNo = "";
switch (drType)
{
case 1://attending
foreach (oMedicalDoctor doc in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalDoctor), "recId", account.doctorNo.ToString()))
{
msDoctor.doctorPCNSNumber = doc.BHFRegNo;
msDoctor.doctorName = doc.name + " " + doc.surname;
msDoctor.doctorCMSRegNo = doc.HPCSARegNo == "" ? "999999" : doc.HPCSARegNo;
}
break;
case 2://assisting
msDoctor.doctorPCNSNumber = account.modifier2;
msDoctor.doctorName = account.modifier3;
msDoctor.doctorCMSRegNo = "";
msDoctor.doctorCMSTypeInd = "";
break;
case 5://referring
msDoctor.doctorPCNSNumber = account.referringDocNo;
msDoctor.doctorName = account.referringDoctor;
msDoctor.doctorCMSRegNo = "";
msDoctor.doctorCMSTypeInd = "";
break;
default:
break;
}
xData.SaveTyped("recId", typeof(oMSClaimDoctor), msDoctor);
return "DR|" +
msDoctor.doctorPCNSNumber.Trim() + "|" +
msDoctor.doctorName.Trim() + "|" +
msDoctor.doctorTypeCode.Trim() + "|" +
msDoctor.doctorCMSRegNo.Trim() + "|" +
msDoctor.doctorCMSTypeInd.Trim() + "|" +
msDoctor.dispensingDocLicenseNo.Trim() + "|" +
(msDoctor.designatedServiceProviderInd ? "Y" : "N") + "|" +
msDoctor.doctorTrackingNo.Trim() + "|";
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
///
/// Doctor Diagnosis Record
///
///
///
private string GetPayloadClaimD(oAccount account, bool isPrimary, int treatmentId, string icd10Item = "")
{
try
{
oMSClaimDiagnosis msDiagnosis = new oMSClaimDiagnosis();
msDiagnosis.treatmentID = treatmentId;
msDiagnosis.doctorTypeCode = enumDrTypeCode_D.Attending_Doctor_Prescribing.GetHashCode().ToString().PadLeft(2, '0');
msDiagnosis.diagnosisCodeType = enumDiagnosisCodeType.ICD10.GetHashCode().ToString().PadLeft(2, '0');
msDiagnosis.diagnosisCode = icd10Item != "" ? icd10Item : account.icd1;
msDiagnosis.extendedDiagnosis = icd10Item != "" ? enumExterdedDiagnosis.Secondary.GetHashCode().ToString().PadLeft(2, '0') : enumExterdedDiagnosis.Primary.GetHashCode().ToString().PadLeft(2, '0');
foreach (oMedicalICD10 icd10 in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalICD10), "icdCode", msDiagnosis.diagnosisCode))
{
msDiagnosis.diagnosisDescription = icd10.icdDescription;
}
xData.SaveTyped("recId", typeof(oMSClaimDiagnosis), msDiagnosis);
return "D|" +
msDiagnosis.doctorTypeCode.Trim() + "|" +
msDiagnosis.diagnosisCodeType.Trim() + "|" +
msDiagnosis.diagnosisCode.Trim() + "|" +
msDiagnosis.diagnosisDescription.Trim() + "|" +
msDiagnosis.extendedDiagnosis.Trim() + "|";
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
///
/// Treatment Record
///
///
///
///
private string GetPayloadClaimT(oAccount account, bool testEra, ref oMSClaimTreatment msTreatment, string reversalRef = "")
{
try
{
string authNo = "";
if (reversalRef == "")
authNo = account.authorisationNo;
else
{
foreach (oMSClaimResponse msClaimResponse in xData.GetTypedByCriteriaSpecific("recId", typeof(oMSClaimResponse), "claimLogId", reversalRef))
{
authNo = msClaimResponse.authorizationNo;
}
}
msTreatment.treatmentStartDate = account.dateOfService; // .ToString("yyyyMMdd");
msTreatment.treatmentEndDate = new DateTime(1900, 1, 1);
msTreatment.authorizationNo = authNo;
msTreatment.invoiceNo = ""; // ???
msTreatment.claimLineNo = account.recId.ToString();
msTreatment.treatmentTypeInd = enumTreatmentTypeInd.Tariff.GetHashCode().ToString().PadLeft(2, '0');
msTreatment.qty = account.qty; // .ToString().Replace(".", "");
msTreatment.qtyTypeInd = enumQtyUnitTypeInd.Unit.GetHashCode().ToString().PadLeft(2, '0');
msTreatment.code = account.consumableCode != string.Empty ? account.consumableCode : account.procedureCode;
msTreatment.codeType = enumTariffTypeCode.NHRPL.GetHashCode().ToString().PadLeft(2, '0'); // ??? is it always NHRPL?
msTreatment.modifierType = "";
msTreatment.nappiCode = account.procedureNAPPI;
msTreatment.traiffInd = enumServiceRateInd.NHRPL.GetHashCode().ToString().PadLeft(2, '0'); // ??? is it always NHRPL? - can be COID
msTreatment.description = account.procedureDescription;
msTreatment.registeredPMB = false; // "N";
msTreatment.scriptWrittenDate = new DateTime(1900, 1, 1); //not applicable
msTreatment.benefitTypeInd = enumBenefitTypeInd.Acute.GetHashCode().ToString().PadLeft(2, '0');
msTreatment.hospitalTariffType = ""; //hospital only
msTreatment.labPCNS = ""; //dentists only
msTreatment.labRefNo = ""; //dentists only
msTreatment.labName = ""; //dentists only
msTreatment.resubmitReasonCode = ""; //get from enum - only if re-submitted
msTreatment.originalClaimNo = ""; // - only if re-submitted
msTreatment.originalClaimDate = new DateTime(1900, 1, 1); //CCYYMMDDhhmm - only if re-submitted
msTreatment.placeOfServiceCode = account.placeOfService.ToString();
if (account.modifier1.Length > 0)
{
msTreatment.treatmentTypeInd = enumTreatmentTypeInd.Modifier.GetHashCode().ToString().PadLeft(2, '0');
msTreatment.code = account.modifier1;
msTreatment.modifierType = enumModifierType.AddModifier.GetHashCode().ToString().PadLeft(2, '0');
foreach (oMedicalProcedure proc in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalProcedure), "code", account.modifier1))
{
msTreatment.description = proc.description;
}
}
//CVH 2018-01-18 Add test indicators to get ERA - use seconds to generate a "random" indator
if (testEra)
{
string indicator = "";
int seconds = System.DateTime.Now.Second;
if (seconds <= 15)
indicator = "#P#PF"; //Approved for full payment - Approved for full payment
else if (seconds <= 30)
indicator = "#S#PP"; //Aproved for part payment - Approved for part payment
else if (seconds <= 45)
indicator = "#P#AA"; //Aproved for part payment - Approved for part payment
else
indicator = "#P#R"; //Approved for full payment - Rejected
msTreatment.description = indicator + " " + msTreatment.description;
}
return "T|" +
msTreatment.treatmentNo.ToString().Trim() + "|" +
msTreatment.treatmentStartDate.ToString("yyyyMMdd") + "|" +
(msTreatment.treatmentEndDate.ToString("yyyyMMdd") == "19000101" ? "" : msTreatment.treatmentEndDate.ToString("yyyyMMdd")) + "|" +
msTreatment.authorizationNo.Trim() + "|" +
msTreatment.invoiceNo.Trim() + "|" +
msTreatment.claimLineNo.Trim() + "|" +
msTreatment.treatmentTypeInd.Trim() + "|" +
msTreatment.qty.ToString().Replace(".", "").Trim() + "|" +
msTreatment.qtyTypeInd.Trim() + "|" +
msTreatment.code.Trim() + "|" +
msTreatment.codeType.Trim() + "|" +
msTreatment.modifierType.Trim() + "|" +
msTreatment.nappiCode.Trim() + "|" +
msTreatment.traiffInd.Trim() + "|" +
msTreatment.description.Trim() + "|" +
(msTreatment.registeredPMB ? "Y" : "N") + "|" +
(msTreatment.scriptWrittenDate.ToString("yyyyMMdd") == "19000101" ? "" : msTreatment.scriptWrittenDate.ToString("yyyyMMdd")) + "|" +
msTreatment.benefitTypeInd.Trim() + "|" +
msTreatment.hospitalTariffType.Trim() + "|" +
msTreatment.labPCNS.Trim() + "|" +
msTreatment.labRefNo.Trim() + "|" +
msTreatment.labName.Trim() + "|" +
msTreatment.resubmitReasonCode.Trim() + "|" +
msTreatment.originalClaimNo.Trim() + "|" +
(msTreatment.originalClaimDate.ToString("yyyyMMdd") == "19000101" ? "" : msTreatment.originalClaimDate.ToString("yyyyMMdd")) + "|" +
msTreatment.placeOfServiceCode.Trim() + "|";
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
///
/// Modifier Record
///
///
///
private string GetPayloadClaimMD(oAccount account, int treatmentId)
{
try
{
oMSClaimModifier modifier = new oMSClaimModifier();
modifier.treatmentId = treatmentId;
if (account.modifier4 == "0005")
modifier.modifierType = enumModifierType.ReductionModifier.GetHashCode().ToString().PadLeft(2, '0');
modifier.modifierCode = account.modifier4;
xData.SaveTyped("recId", typeof(oMSClaimModifier), modifier);
return "MD|" +
modifier.modifierCode.Trim() + "|" +
modifier.modifierType.Trim() + "|";
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
///
/// General Comments Record
///
///
private string GetPayLoadClaimG()
{
try
{
string generalComments = "";
return "G|" +
generalComments + "|";
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
///
/// Treatment Financial Record
///
///
///
private string GetPayLoadClaimZ(oAccount account, ref decimal fClaimNetAmount, ref decimal fClaimGrossAmount, ref decimal fTotalClaimAmount, ref decimal fClaimDiscountAmount,
ref decimal fClaimLevyAmount, ref decimal fClaimMMAPSurcharge, ref decimal fClaimCoPaymentAmount, ref decimal fClaimPatientLiablePortion, ref decimal fClaimMedicalFundLiableAmount, ref decimal fMemberReimbursementAmount, ref oMSClaimTreatment msTreatment)
{
try
{
msTreatment.treatmentNetAmount = account.amount;//.ToString().Replace(".", "");
msTreatment.treatmentGrossAmount = account.amount;//.ToString().Replace(".", "");
msTreatment.dispensingFee = 0; //Pharmacy Only
msTreatment.containerFee = 0; //Pharmacy Only
msTreatment.excessTimeFee = 0; //Pharmacy Only
msTreatment.callOutFee = 0; //Pharmacy Only
msTreatment.copyFee = 0; //Pharmacy Only
msTreatment.deliveryFee = 0; //Pharmacy Only
msTreatment.contractFee = 0; //Pharmacy Only
msTreatment.treatmentClaimedAmount = account.amount;//.ToString().Replace(".", "");
msTreatment.discountAmount = 0;
msTreatment.patientLevyAmount = 0;
msTreatment.mmapSurcharge = 0;
msTreatment.patientCoPaymentAmount = 0;
msTreatment.patientLiableAmount = account.liablePat;
msTreatment.medicalFundLiableAmount = account.liableMed;//.ToString().Replace(".", "");
msTreatment.memberReimbursementAmount = 0;
fClaimNetAmount += account.amount;
fClaimGrossAmount += account.amount;
fTotalClaimAmount += account.amount;
fClaimDiscountAmount += 0;
fClaimLevyAmount += 0;
fClaimMMAPSurcharge += 0;
fClaimCoPaymentAmount += 0;
fClaimPatientLiablePortion += account.liablePat;
fClaimMedicalFundLiableAmount += account.liableMed;
fMemberReimbursementAmount += 0;
return "Z|" +
msTreatment.treatmentNetAmount.ToString().Replace(".", "").Trim() + "|" +
msTreatment.treatmentGrossAmount.ToString().Replace(".", "").Trim() + "|" +
msTreatment.dispensingFee.ToString().Replace(".", "").Trim() + "|" +
msTreatment.containerFee.ToString().Replace(".", "").Trim() + "|" +
msTreatment.excessTimeFee.ToString().Replace(".", "").Trim() + "|" +
msTreatment.callOutFee.ToString().Replace(".", "").Trim() + "|" +
msTreatment.copyFee.ToString().Replace(".", "").Trim() + "|" +
msTreatment.deliveryFee.ToString().Replace(".", "").Trim() + "|" +
msTreatment.contractFee.ToString().Replace(".", "").Trim() + "|" +
msTreatment.treatmentClaimedAmount.ToString().Replace(".", "").Trim() + "|" +
msTreatment.discountAmount.ToString().Replace(".", "").Trim() + "|" +
msTreatment.patientLevyAmount.ToString().Replace(".", "").Trim() + "|" +
msTreatment.mmapSurcharge.ToString().Replace(".", "").Trim() + "|" +
msTreatment.patientCoPaymentAmount.ToString().Replace(".", "").Trim() + "|" +
msTreatment.patientLiableAmount.ToString().Replace(".", "").Trim() + "|" +
msTreatment.medicalFundLiableAmount.ToString().Replace(".", "").Trim() + "|" +
msTreatment.memberReimbursementAmount.ToString().Replace(".", "").Trim() + "|";
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
///
/// Claim Financial Record
///
///
///
private string GetPayloadClaimF(oAccount account, decimal fClaimNetAmount, decimal fClaimGrossAmount, decimal fTotalClaimAmount, decimal fClaimDiscountAmount,
decimal fClaimLevyAmount, decimal fClaimMMAPSurcharge, decimal fClaimCoPaymentAmount, decimal fClaimPatientLiablePortion, decimal fClaimMedicalFundLiableAmount, decimal fMemberReimbursementAmount, ref oMSClaim msClaim)
{
try
{
msClaim.claimNetAmount = fClaimNetAmount;//.ToString().Replace(".", "");
msClaim.claimGrossAmount = fClaimGrossAmount;//.ToString().Replace(".", "");
msClaim.totalClaimedAmount = fTotalClaimAmount;//.ToString().Replace(".", "");
msClaim.claimDiscountAmount = fClaimDiscountAmount;
msClaim.claimDeductableLevyAmount = fClaimLevyAmount;
msClaim.claimMMAPSurcharge = fClaimMMAPSurcharge;
msClaim.claimCoPaymentAmount = fClaimCoPaymentAmount;
msClaim.receiptNo = "";
msClaim.claimPatientLiableAmount = fClaimPatientLiablePortion;
msClaim.claimMedicalFundLiableAmount = fClaimMedicalFundLiableAmount;//.ToString().Replace(".", "");
msClaim.memberReimbursementAmount = fMemberReimbursementAmount;
return "F|" +
msClaim.claimNetAmount.ToString().Replace(".", "").Trim() + "|" +
msClaim.claimGrossAmount.ToString().Replace(".", "").Trim() + "|" +
msClaim.totalClaimedAmount.ToString().Replace(".", "").Trim() + "|" +
msClaim.claimDiscountAmount.ToString().Replace(".", "").Trim() + "|" +
msClaim.claimDeductableLevyAmount.ToString().Replace(".", "").Trim() + "|" +
msClaim.claimMMAPSurcharge.ToString().Replace(".", "").Trim() + "|" +
msClaim.claimCoPaymentAmount.ToString().Replace(".", "").Trim() + "|" +
msClaim.receiptNo.Trim() + "|" +
msClaim.claimPatientLiableAmount.ToString().Replace(".", "").Trim() + "|" +
msClaim.claimMedicalFundLiableAmount.ToString().Replace(".", "").Trim() + "|" +
msClaim.memberReimbursementAmount.ToString().Replace(".", "").Trim() + "|";
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
///
/// Footer (End of Message) Record
///
///
private string GetPayloadClaimE(string transmissionNo, int numberOfClaims, decimal valueOfClaims)
{
return "E|" +
transmissionNo.Trim() + "|" +
numberOfClaims.ToString().Trim() + "|" +
valueOfClaims.ToString().Replace(".", "").Trim() + "|";
}
#endregion
#region Claim Response Lines
///
/// process response payload
///
///
private string ProcessClaimResponse(oMSLog logClaim, bool isReversal = false)
{
try
{
string invoiceNo = "";
string responsePayload = logClaim.response;
oMSClaimResponse msResponse = new oMSClaimResponse();
oMSClaimResponseTreatment msResponseTreatment = new oMSClaimResponseTreatment();
msResponse.claimLogId = logClaim.recId;
msResponse.recId = xData.SaveTyped("recId", typeof(oMSClaimResponse), msResponse);
using (System.IO.StringReader reader = new System.IO.StringReader(responsePayload))
{
string line;
while ((line = reader.ReadLine()) != null)
{
string[] splitLine = line.Split('|');
switch (splitLine[0])
{
case "H":
ProcessClaimResponseH(line);
break;
case "S":
ProcessClaimResponseS(line);
break;
case "M":
ProcessClaimResponseM(line, ref msResponse);
xData.UpdateTyped("recId", msResponse.recId.ToString(), typeof(oMSClaimResponse), msResponse);
break;
case "P":
ProcessClaimResponseP(line, ref msResponse);
xData.UpdateTyped("recId", msResponse.recId.ToString(), typeof(oMSClaimResponse), msResponse);
break;
case "T":
msResponseTreatment = new oMSClaimResponseTreatment();
msResponseTreatment.claimResponseId = msResponse.recId;
msResponseTreatment.recId = xData.SaveTyped("recId", typeof(oMSClaimResponseTreatment), msResponseTreatment);
ProcessClaimResponseT(line, ref msResponseTreatment);
xData.UpdateTyped("recId", msResponseTreatment.recId.ToString(), typeof(oMSClaimResponseTreatment), msResponseTreatment);
foreach (oAccount accountItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oAccount), "recId", msResponseTreatment.claimLineNo))
{
switch (accountItem.modifier1)
{
case "0008":
foreach (int modId in mod0008IdList)
{
foreach (oAccount modItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oAccount), "recId", modId.ToString()))
{
invoiceNo = UpdateTreatmentAccountItem(isReversal, msResponse, modItem);
}
}
break;
case "0009":
foreach (int modId in mod0009IdList)
{
foreach (oAccount modItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oAccount), "recId", modId.ToString()))
{
invoiceNo = UpdateTreatmentAccountItem(isReversal, msResponse, modItem);
}
}
break;
case "0018":
foreach (int modId in mod0018IdList)
{
foreach (oAccount modItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oAccount), "recId", modId.ToString()))
{
invoiceNo = UpdateTreatmentAccountItem(isReversal, msResponse, modItem);
}
}
break;
default://assume string.Empty ie no modifiers
invoiceNo = UpdateTreatmentAccountItem(isReversal, msResponse, accountItem);
break;
}
}
break;
case "R":
ProcessClaimResponseR(line, ref msResponseTreatment);
break;
case "G":
ProcessClaimResponseG(line, ref msResponseTreatment, ref msResponse);
break;
//case "FR"://ToDo
// ProcessClaimResponseFR(line);
// break;
case "Z":
ProcessClaimResponseZ(line, ref msResponseTreatment);
xData.UpdateTyped("recId", msResponseTreatment.recId.ToString(), typeof(oMSClaimResponseTreatment), msResponseTreatment);
break;
case "F":
ProcessClaimResponseF(line, ref msResponse);
xData.UpdateTyped("recId", msResponse.recId.ToString(), typeof(oMSClaimResponse), msResponse);
break;
case "E":
ProcessClaimResponseE(line);
break;
default:
break;
}
}
}
return invoiceNo;
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
private static string UpdateTreatmentAccountItem(bool isReversal, oMSClaimResponse msResponse, oAccount accountItem)
{
string invoiceNo;
if (isReversal)
{
accountItem.claimSent = false;
}
else
{
accountItem.claimSent = true;
accountItem.claimDate = DateTime.Now;
accountItem.claimNumber = msResponse.claimLogId;
//CVH 2018-08-06 If claim was rejected, need to set Patient Liable amounts
if (msResponse.responseResultCode == "03")
{
accountItem.liablePat += accountItem.liableMed;
accountItem.liableMed = 0;
}
}
xData.UpdateTyped("recId", accountItem.recId.ToString(), typeof(oAccount), accountItem);
invoiceNo = accountItem.invoiceNo.ToString();
return invoiceNo;
}
///
/// Header (Start of Message) Record – Type ‘H’
///
///
private void ProcessClaimResponseH(string line)
{
string[] splitLine = line.Split('|');
string transmissionNo = splitLine[1];
}
///
/// Service Provider Record – Type ‘S’
///
///
private void ProcessClaimResponseS(string line)
{
string[] splitLine = line.Split('|');
string responseFileCreationDateTime = splitLine[1],
bpPCNSNo = splitLine[2],
bpName = splitLine[3],
datasetId = splitLine[4],
rejectCount = splitLine[5];
}
///
/// Member Record – Type ‘M’
///
///
private void ProcessClaimResponseM(string line, ref oMSClaimResponse msResponse)
{
try
{
string[] splitLine = line.Split('|');
msResponse.memberSurname = splitLine[1];
msResponse.memberFullName = splitLine[2];
msResponse.membershipNo = splitLine[3];
msResponse.memberAccountNo = splitLine[4];
msResponse.medSchemeName = splitLine[5];
msResponse.medSchemeRegNo = splitLine[6];
msResponse.msDestinationCode = splitLine[7];
msResponse.msDestinationContactNo = splitLine[8];
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
}
///
/// Patient Record – Type ‘P’
///
///
private void ProcessClaimResponseP(string line, ref oMSClaimResponse msResponse)
{
try
{
string[] splitLine = line.Split('|');
msResponse.dependantCode = splitLine[1];
msResponse.patientSurname = splitLine[2];
msResponse.patientInitials = splitLine[3];
msResponse.patientFullName = splitLine[4];
msResponse.patientDOB = DateTime.ParseExact(splitLine[5] == "" ? "19000101" : splitLine[5], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
msResponse.patientIdNumber = splitLine[6];
msResponse.authorizationNo = splitLine[7];
msResponse.confirmationNo = splitLine[8];
msResponse.patientAccountNo = splitLine[9];
msResponse.inOutHospitalInd = splitLine[10];
msResponse.claimRefNo = splitLine[11];
msResponse.responseLevelInd = splitLine[12];
msResponse.responseResultCode = splitLine[13];
msResponse.respondingParty = splitLine[14];
msResponse.msDeliveryTypeInd = splitLine[15];
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
}
///
/// Treatment Record – Type ‘T’
///
///
private void ProcessClaimResponseT(string line, ref oMSClaimResponseTreatment msResponseTreatment)
{
try
{
string[] splitLine = line.Split('|');
switch (splitLine[1].Length)
{
case 8:
msResponseTreatment.treatmentStartDate = DateTime.ParseExact(splitLine[1], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
break;
case 12:
msResponseTreatment.treatmentStartDate = DateTime.ParseExact(splitLine[1], "yyyyMMddhhmm", CultureInfo.InvariantCulture, DateTimeStyles.None);
break;
default:
msResponseTreatment.treatmentStartDate = new DateTime(1900, 1, 1);
break;
}
switch (splitLine[2].Length)
{
case 8:
msResponseTreatment.treatmentEndDate = DateTime.ParseExact(splitLine[2], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
break;
case 12:
msResponseTreatment.treatmentEndDate = DateTime.ParseExact(splitLine[2], "yyyyMMddhhmm", CultureInfo.InvariantCulture, DateTimeStyles.None);
break;
default:
msResponseTreatment.treatmentEndDate = new DateTime(1900, 1, 1);
break;
}
msResponseTreatment.authorizationNo = splitLine[3];
msResponseTreatment.invoiceNo = splitLine[4];
msResponseTreatment.claimLineNo = splitLine[5];
msResponseTreatment.claimRefTrackingNo = splitLine[6];
msResponseTreatment.treatmentTypeInd = splitLine[7];
decimal dVal = 0;
Decimal.TryParse(splitLine[8], out dVal);
msResponseTreatment.qty = dVal;
msResponseTreatment.code = splitLine[9];
msResponseTreatment.nappiCode = splitLine[10];
msResponseTreatment.description = splitLine[11];
msResponseTreatment.benefitTypeInd = splitLine[12];
msResponseTreatment.labRefNo = splitLine[13];
msResponseTreatment.responseResultCode = splitLine[14];
msResponseTreatment.respondingParty = splitLine[15];
msResponseTreatment.msDeliveryTypeInd = splitLine[16];
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
}
///
/// Response Record – Type ‘R’
///
///
private void ProcessClaimResponseR(string line, ref oMSClaimResponseTreatment msResponseTreatment)
{
try
{
oMSClaimResponseLine msResponseLine = new oMSClaimResponseLine();
msResponseLine.responseTreatmentId = msResponseTreatment.recId;
string[] splitLine = line.Split('|');
msResponseLine.Code = splitLine[1];
msResponseLine.Description = splitLine[2];
xData.SaveTyped("recId", typeof(oMSClaimResponseLine), msResponseLine);
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
}
///
/// General Comments Record – Type ‘G’
///
///
private void ProcessClaimResponseG(string line, ref oMSClaimResponseTreatment msResponseTreatment, ref oMSClaimResponse msResponse)
{
try
{
oMSClaimResponseComment msResponseComment = new oMSClaimResponseComment();
msResponseComment.responseTreatmentId = msResponseTreatment.recId;
msResponseComment.claimResponseId = msResponse.recId;
string[] splitLine = line.Split('|');
msResponseComment.comment = splitLine[1];
xData.SaveTyped("recId", typeof(oMSClaimResponseComment), msResponseComment);
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
}
///
/// Failure Response Record – Type ‘FR’
///
///
private void ProcessClaimResponseFR(string line)
{
try
{
string[] splitLine = line.Split('|');
string failureResponseMssage = splitLine[1];
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
}
///
/// Treatment Financial Record – Type ‘Z’
///
///
private void ProcessClaimResponseZ(string line, ref oMSClaimResponseTreatment msResponseTreatment)
{
try
{
string[] splitLine = line.Split('|');
decimal dVal = 0;
Decimal.TryParse(splitLine[1], out dVal);
msResponseTreatment.treatmentNetAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[2], out dVal);
msResponseTreatment.treatmentGrossAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[3], out dVal);
msResponseTreatment.dispensingFee = dVal;
dVal = 0;
Decimal.TryParse(splitLine[4], out dVal);
msResponseTreatment.containerFee = dVal;
dVal = 0;
Decimal.TryParse(splitLine[5], out dVal);
msResponseTreatment.excessTimeFee = dVal;
dVal = 0;
Decimal.TryParse(splitLine[6], out dVal);
msResponseTreatment.callOutFee = dVal;
dVal = 0;
Decimal.TryParse(splitLine[7], out dVal);
msResponseTreatment.copyFee = dVal;
dVal = 0;
Decimal.TryParse(splitLine[8], out dVal);
msResponseTreatment.deliveryFee = dVal;
dVal = 0;
Decimal.TryParse(splitLine[9], out dVal);
msResponseTreatment.contractFee = dVal;
dVal = 0;
Decimal.TryParse(splitLine[10], out dVal);
msResponseTreatment.treatmentClaimedAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[11], out dVal);
msResponseTreatment.discountAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[12], out dVal);
msResponseTreatment.overchargedAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[13], out dVal);
msResponseTreatment.patientLevyAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[14], out dVal);
msResponseTreatment.mmapSurcharge = dVal;
dVal = 0;
Decimal.TryParse(splitLine[15], out dVal);
msResponseTreatment.patientCoPaymentAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[16], out dVal);
msResponseTreatment.patientLiableAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[17], out dVal);
msResponseTreatment.medicalFundLiableAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[18], out dVal);
msResponseTreatment.authAmountToProvider = dVal;
dVal = 0;
Decimal.TryParse(splitLine[19], out dVal);
msResponseTreatment.memberReimbursementAmount = dVal;
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
}
///
/// Claim Financial Record – Type ‘F’
///
///
private void ProcessClaimResponseF(string line, ref oMSClaimResponse msResponse)
{
try
{
string[] splitLine = line.Split('|');
decimal dVal = 0;
Decimal.TryParse(splitLine[1], out dVal);
msResponse.claimNetAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[2], out dVal);
msResponse.claimGrossAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[3], out dVal);
msResponse.totalClaimedAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[4], out dVal);
msResponse.claimDiscountAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[5], out dVal);
msResponse.claimOverchargeAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[6], out dVal);
msResponse.claimDeductableLevyAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[7], out dVal);
msResponse.claimMMAPSurcharge = dVal;
dVal = 0;
Decimal.TryParse(splitLine[8], out dVal);
msResponse.claimCoPaymentAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[9], out dVal);
msResponse.claimPatientLiableAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[10], out dVal);
msResponse.claimMedicalFundLiableAmount = dVal;
dVal = 0;
Decimal.TryParse(splitLine[11], out dVal);
msResponse.authAmountToProvider = dVal;
dVal = 0;
Decimal.TryParse(splitLine[12], out dVal);
msResponse.memberReimbursementAmount = dVal;
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
}
}
///
/// Footer (End of Message) Record – Type ‘E’
///
///
private void ProcessClaimResponseE(string line)
{
string[] splitLine = line.Split('|');
string transmissionNo = splitLine[1],
numberOfClaims = splitLine[2],
valueOfClaims = splitLine[3];
}
#endregion
#region Code methods
///
/// Get In or Out of Hopital Code
///
///
///
private string GetInOrOutOfHopsital(string rateType)
{
try
{
string returnCode = "";
switch (rateType)
{
case "IH":
returnCode = "01";
break;
case "OH":
returnCode = "02";
break;
default:
break;
}
return returnCode;
}
catch (Exception ex)
{
exception.HandleException("mediswitch class:", MethodBase.GetCurrentMethod().Name, ex, 0);
return ex.Message;
}
}
#endregion
#region enums
enum enumMSTransactionType
{
SwitchOnMembershipStatusValidation = 301,
SwitchClaim_GeneralMedical = 302,
SwitchClaim_Reversal = 303,
SwitchClaim_Hospital = 304
}
enum enumPatientRelationCode
{
MainMember = 01,
Son = 02,
Spouse = 03,
Daughter = 04,
Mother = 05,
Father = 06,
Other = 07
}
enum enumDrTypeCode_DR
{
Attending_Treating_Prescribing_Doctor = 01,
Assisting_Doctor = 02,
Anaesthetist = 03,
Admitting_Doctor = 04,
Referring_Doctor = 05,
Referred_to_Doctor = 06,
Discharging_Doctor = 07
}
enum enumCMSDrType
{
HPCSA = 01,
A_HPCSA = 02,
SACSSP = 03,
SADTC = 04,
SANC = 05,
SAPC = 06
}
enum enumDrTypeCode_D
{
Attending_Doctor_Prescribing = 01,
Admitting_Doctor = 02,
Referring_Doctor = 03,
Discharging_Doctor = 04
}
enum enumDiagnosisCodeType
{
ICD10 = 01,
ICD_DA_Dental = 02,
FreeText = 03
}
enum enumExterdedDiagnosis
{
Primary = 01,
Secondary = 02,
Co_Morbidity = 03,
Complication = 04,
Allergy = 05
}
enum enumTreatmentTypeInd
{
DispensedMedicine = 01,
Tariff = 02,
Modifier = 03
}
enum enumQtyUnitTypeInd
{
Day = 01,
Hour = 02,
Minute = 03,
Second = 04,
Kilometer = 05,
Unit = 06,
Item = 07,
TheatreTime = 08
}
enum enumTariffTypeCode
{
NHRPL = 01,
NAPPI = 02,
CPT_CCSA = 03,
CDT = 04,
SAOA = 05,
Orthotist = 06,
UPFS = 07
}
enum enumModifierType
{
InformationalModifier = 01,
ReductionModifier = 02,
AddModifier = 03,
CompoundModifier = 04
}
enum enumServiceRateInd
{
NHRPL = 01,
COID = 02,
FundTariff = 03,
ManagedFeeForService = 04,
GroupCapitation = 05,
IndividualCapitation = 06,
EthicalTariffRates_HPCSA = 07,
SAMA = 08,
SADA = 09,
SAOA = 10,
HASA = 11,
FixedFee_Hospital = 12,
PerDiem_Hospital = 13,
UPFS = 14
}
enum enumBenefitTypeInd
{
Acute = 01,
Chronic = 02,
OverTheCounter_PAT = 03,
Chemotherapy = 04
}
enum enumHospitalTariffType
{
WardFees = 01,
TheatreFees = 02,
TTO = 03,
WardExtra = 04,
Gas = 05,
DispensedDrugs = 06,
Exclusions = 07,
WardDrugs = 08,
TheatreDrugs = 09,
Miscellaneous = 10,
TheatreExtra = 11,
DispensaryFees = 12,
ManagementFees = 13
}
enum enumReSubmissionReasonCode
{
Unpaid = 01,
DetailsChanged = 02
}
enum enumProcCodeType
{
NHRPL = 01,
CPT_CCSA = 02,
CDT = 03
}
enum enumBasisOfDOT
{
NotSpecified = 01,
OnScript_ImplicitUsage = 02,
DispensersEstimation = 03,
DoctorsDirections = 04
}
enum enumDAW
{
NoDAW = 01,//default
DrDAW = 02,
PatDAW = 03,
RphDAW = 04,
NoGenericAvailable = 05,
BrandDispensedAsGeneric = 06
}
#endregion
}