Esempio n. 1
0
        //public string PostDoctorReport(string EMRID, string FilePath, string EMRPatientID)
        public string PostDocument(dynamic data)
        {
            try
            {
                //int i = 1;
                //var client = new RestClient("http://emr.intellih.com/api/document/PostDocument");
                //client.Timeout = -1;
                //var request = new RestRequest(Method.POST);
                //request.AddHeader("Content-Type", "application/json");
                //request.AddParameter("application/json", "{\r\n  \"emrId\": \""+ i +"\",\r\n  \"accessToken\": \"fkAFfJzfLdpHoyjpDNnSYZpeZNOV6C\",\r\n  \"filePath\": \"C:\\\\intellihApps\\\\dev\\\\emr\\\\TestPDF.pdf\",\r\n  \"emrPatientid\": \"87734739\",\r\n  \"doctorId\": \"123\",\r\n  \"documentDate\": \"2020-12-01\",\r\n  \"documentDescription\": \"Test Document 01Dec2020 1\"\r\n}", ParameterType.RequestBody);
                //IRestResponse response = client.Execute(request);
                //return response.Content;

                //request.AddParameter("application/json", " {\r\n  \"emrId\": \"" + param.emrId + "\" ,\r\n  \"accessToken\": \"" + accessToken + "\",\r\n  \"filePath\": \"C:\\intellihApps\\dev\\emr\\TestPDF.pdf\",\r\n  \"emrPatientid\": \"" + emrPatient.EMRPatientId + "\",\r\n  \"doctorId\": \"128999\",\r\n  \"documentDate\": \"" +  DateTime.UtcNow.ToString() + "\" ,\r\n  \"documentDescription\": \"CB_2374$%#.;'_20201013_055038PM.pdf\"\r\n}", ParameterType.RequestBody);
                //request.AddParameter("application/json", " {\r\n  \"emrId\": \"1\",\r\n  \"accessToken\": \"1\",\r\n  \"filePath\": \"C:\\\\intellihApps\\\\dev\\\\emr\\\\TestPDF.pdf\",\r\n  \"emrPatientid\": \"1\",\r\n  \"doctorId\": \"128999\",\r\n  \"documentDate\": \"01-Dec-20 12:54:12 PM\",\r\n  \"documentDescription\": \"CB_2374$%#.;'_20201013_055038PM.pdf\"\r\n}", ParameterType.RequestBody);
                //request.AddParameter("application/json", " {\r\n  \"emrId\": \"1\",\r\n  \"accessToken\": \"1\",\r\n  \"filePath\": \"C:\\\\intellihApps\\\\dev\\\\emr\\\\TestPDF.pdf\",\r\n  \"emrPatientid\": \"1\",\r\n  \"doctorId\": \"128999\",\r\n  \"documentDate\": \"01-Dec-20 12:54:12 PM\",\r\n  \"documentDescription\": \"CB_2374$%#.;'_20201013_055038PM.pdf\"\r\n}", ParameterType.RequestBody);
                //request.AddParameter("application/json", " {\r\n  \"emrId\": \"" + param.emrId + "\",\r\n  \"accessToken\": \"" + accessToken + "\",\r\n  \"filePath\": \"C:\\\\intellihApps\\\\dev\\\\emr\\\\TestPDF.pdf\",\r\n  \"emrPatientid\": \"" + emrPatient.EMRPatientId + "\",\r\n  \"doctorId\": \"128999\",\r\n  \"documentDate\": \"" + DateTime.UtcNow.ToString() + "\",\r\n  \"documentDescription\": \"CB_2374$%#.;'_20201013_055038PM.pdf\"\r\n}", ParameterType.RequestBody);
                //request.AddParameter("application/json", " {\r\n  \"emrId\": \"6\",\r\n  \"accessToken\": \"kmw6ylb7H4NQpgAAbTSZlavWceC0zB\",\r\n  \"filePath\": \"C:\\\\intellihApps\\\\dev\\\\emr\\\\TestPDF.pdf\",\r\n  \"emrPatientid\": \"87701984\",\r\n  \"doctorId\": \"128999\",\r\n  \"documentDate\": \"2013-02-24\",\r\n  \"documentDescription\": \"CB_011220206.06PM.pdf\"\r\n}", ParameterType.RequestBody);

                string UserID = string.Empty;
                //string DepartmentID = "1";
                string        JSONString       = string.Empty;
                StringBuilder JSONStringReturn = new StringBuilder();
                string        ModuleID         = "0";
                string        EMRId            = ((Newtonsoft.Json.Linq.JValue)data.emrId).Value.ToString();
                string        EMRPatientId     = ((Newtonsoft.Json.Linq.JValue)data.emrPatientId).Value.ToString();

                oMasterConnection.EMRIntegrationMasterConStr = ConfigurationManager.ConnectionStrings["EMRIntegrationMaster"].ConnectionString;
                SqlConnection oConnMaster = new SqlConnection(oMasterConnection.EMRIntegrationMasterConStr);
                oMasterConnection.oConnEmrMaster = oConnMaster;

                string RequestID = objLog.LogRequest(oMasterConnection, Logs.Status.GotPushDoctorReportRequestFromIntelliH, EMRId, ModuleID, EMRPatientId);
                string result    = string.Empty;

                switch (EMRId)
                {
                case "1":    //Athena
                    objLog.LogRequest(oMasterConnection, Logs.Status.ConnectionRequestSentToEMR, RequestID, EMRId, ModuleID, EMRPatientId);
                    EMRIntegrations.Athena.AthenaAPI objAthenaAPI = new EMRIntegrations.Athena.AthenaAPI();
                    objLog.LogRequest(oMasterConnection, Logs.Status.ConnectionEstablishedWithEMR, RequestID, EMRId, ModuleID, EMRPatientId);
                    objLog.LogRequest(oMasterConnection, Logs.Status.DataPushDoctorReportRequestSendingToEMR, RequestID, EMRId, ModuleID, EMRPatientId);
                    result = objAthenaAPI.PostClinicalDocuments(data.emrPatientid, data.DepartmentID, data.FilePath, RequestID);
                    objLog.LogRequest(oMasterConnection, Logs.Status.DoctorReportSentToEMR, RequestID, EMRId, ModuleID, EMRPatientId);
                    return(result);

                //break;
                case "6":    //DrChrono

                    #region Temp code for doctorid
                    oMasterConnection.EmrStagingDBConStr = ConfigurationManager.ConnectionStrings["EMRStagingDB"].ConnectionString;
                    SqlConnection oConnStaging = new SqlConnection(oMasterConnection.EmrStagingDBConStr);
                    oMasterConnection.oConnEmrStagingDB = oConnStaging;
                    string        doctoridfromstaging = string.Empty;
                    SqlDataReader doctoridreader      = SqlHelper.ExecuteReader(oMasterConnection.oConnEmrStagingDB, System.Data.CommandType.Text, "select top 1 doctor as doctorid from [drchrono].[PatientDemographics] where id = '" + EMRPatientId + "' order by requestid desc");
                    if (doctoridreader.HasRows)
                    {
                        while (doctoridreader.Read())
                        {
                            doctoridfromstaging = doctoridreader.GetString(0);
                        }
                    }
                    doctoridreader.Close();
                    #endregion

                    objLog.LogRequest(oMasterConnection, Logs.Status.ConnectionRequestSentToEMR, RequestID, EMRId, ModuleID, EMRPatientId);
                    EMRIntegrations.DrChrono.DrChronoAPI objDrChronoAPI = new EMRIntegrations.DrChrono.DrChronoAPI(data, doctoridfromstaging);
                    objLog.LogRequest(oMasterConnection, Logs.Status.ConnectionEstablishedWithEMR, RequestID, EMRId, ModuleID, EMRPatientId);
                    objLog.LogRequest(oMasterConnection, Logs.Status.DataPushDoctorReportRequestSendingToEMR, RequestID, EMRId, ModuleID, EMRPatientId);
                    DataTable dtDocumentData = objDrChronoAPI.PostDocument(EMRPatientId, oMasterConnection.EmrStagingDBConStr, RequestID, ((Newtonsoft.Json.Linq.JValue)data.accessToken).Value.ToString());
                    objLog.LogRequest(oMasterConnection, Logs.Status.DoctorReportSentToEMR, RequestID, EMRId, ModuleID, EMRPatientId);
                    objDrChronoAPI.SaveDocumentUpload(dtDocumentData, oMasterConnection.EmrStagingDBConStr, RequestID);
                    objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRId, ModuleID, EMRPatientId);
                    JSONString = objDrChronoAPI.GetJSONDocumentUpload(dtDocumentData, EMRPatientId, RequestID, EMRId, ModuleID, UserID);
                    return(JSONString);

                default:
                    JSONStringReturn.Append("{");
                    JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientId + "\",");
                    JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRId + "\",");
                    JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                    JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                    JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                    JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                    JSONStringReturn.Append("\"EMRID is not Found\"");
                    JSONStringReturn.Append("}");
                    return(JSONStringReturn.ToString());
                }
            }
            catch (Exception ex)
            {
                //throw new Exception("EMRID is not Found");
                return(ex.Message + " " + ex.StackTrace);
            }
        }
Esempio n. 2
0
        public string GetModuleData(string EMRID, string ModuleID, string EMRPatientID, string AccessToken)
        {
            StringBuilder JSONStringReturn = new StringBuilder();
            string        RequestID        = string.Empty;

            try
            {
                string UserID       = string.Empty;
                string DepartmentID = "1";
                string JSONString   = string.Empty;

                // Get the variable values from JSON

                oMasterConnection.EMRIntegrationMasterConStr = ConfigurationManager.ConnectionStrings["EMRIntegrationMaster"].ConnectionString;
                SqlConnection oConnMaster = new SqlConnection(oMasterConnection.EMRIntegrationMasterConStr);
                oMasterConnection.oConnEmrMaster = oConnMaster;

                oMasterConnection.EmrStagingDBConStr = ConfigurationManager.ConnectionStrings["EMRStagingDB"].ConnectionString;
                SqlConnection oConnStaging = new SqlConnection(oMasterConnection.EmrStagingDBConStr);
                oMasterConnection.oConnEmrStagingDB = oConnStaging;

                switch (EMRID)
                {
                case "1":    //Athena
                    EMRIntegrations.Athena.AthenaAPI objAthenaAPI;
                    switch (ModuleID)
                    {
                    case "11":        //PatientDemographics
                        RequestID    = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objAthenaAPI = new EMRIntegrations.Athena.AthenaAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtPatientData = objAthenaAPI.GetPatientDemographics(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objAthenaAPI.SavePatientDemographics(dtPatientData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objAthenaAPI.GetJSONPatientDemographics(dtPatientData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);

                        //PostDataToIntelliH("https://apis-dev.intellih.com/api/EMR/SaveDataFromStagingToIntelliH", JSONString);

                        break;

                    case "15":        //Allergy
                        RequestID    = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objAthenaAPI = new EMRIntegrations.Athena.AthenaAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtAllergy = objAthenaAPI.GetAllergy(EMRPatientID, DepartmentID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objAthenaAPI.SaveAllergy(dtAllergy, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objAthenaAPI.GetJSONAllergy(dtAllergy, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    case "5":        //Medications
                        RequestID    = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objAthenaAPI = new EMRIntegrations.Athena.AthenaAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtMedication = objAthenaAPI.GetMedications(EMRPatientID, DepartmentID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objAthenaAPI.SaveMedications(dtMedication, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objAthenaAPI.GetJSONMedications(dtMedication, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    case "12":        //PatientInsurance
                        RequestID    = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objAthenaAPI = new EMRIntegrations.Athena.AthenaAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtInsurance = objAthenaAPI.GetInsurances(EMRPatientID, DepartmentID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objAthenaAPI.SaveInsurances(dtInsurance, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objAthenaAPI.GetJSONInsurances(dtInsurance, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    case "13":        //PatientPicture
                        RequestID    = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objAthenaAPI = new EMRIntegrations.Athena.AthenaAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtPicture = objAthenaAPI.GetPatientPicture(EMRPatientID, DepartmentID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objAthenaAPI.SavePictures(dtPicture, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objAthenaAPI.GetJSONPictures(dtPicture, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    default:
                        JSONStringReturn.Append("{");
                        JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientID + "\",");
                        JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRID + "\",");
                        JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                        JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                        JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                        JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                        JSONStringReturn.Append("\"ModuleID is not Found\"");
                        JSONStringReturn.Append("}");
                        return(JSONStringReturn.ToString());
                    }
                    objLog.LogRequest(oMasterConnection, Logs.Status.DataSentToIntelliH, RequestID, EMRID, ModuleID, EMRPatientID);
                    break;

                case "2":    //Cerner
                    EMRIntegrations.CernerMillenium.CernerMilleniumAPI objCernerAPI;
                    switch (ModuleID)
                    {
                    case "11":        //PatientDemographics
                        RequestID    = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objCernerAPI = new EMRIntegrations.CernerMillenium.CernerMilleniumAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtPatientData = objCernerAPI.GetPatientDemographics(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID);

                        if (dtPatientData.Rows.Count == 0)
                        {
                            JSONStringReturn.Append("{");
                            JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientID + "\",");
                            JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRID + "\",");
                            JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                            JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                            JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                            JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                            JSONStringReturn.Append("\"No Patient Found\"");
                            JSONStringReturn.Append("}");
                            return(JSONStringReturn.ToString());
                        }

                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objCernerAPI.SavePatientDemographics(dtPatientData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objCernerAPI.GetJSONPatientDemographics(dtPatientData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);

                        //PostDataToIntelliH("https://apis-dev.intellih.com/api/EMR/SaveDataFromStagingToIntelliH", JSONString);

                        break;

                    case "15":        //Allergy
                        RequestID    = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objCernerAPI = new EMRIntegrations.CernerMillenium.CernerMilleniumAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtAllergyData = objCernerAPI.GetAllergy(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objCernerAPI.SaveAllergy(dtAllergyData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objCernerAPI.GetJSONAllergy(dtAllergyData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    case "5":        //Medications
                        RequestID    = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objCernerAPI = new EMRIntegrations.CernerMillenium.CernerMilleniumAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtMedicationData = objCernerAPI.GetMedications(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objCernerAPI.SaveMedications(dtMedicationData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objCernerAPI.GetJSONMedications(dtMedicationData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);

                        //PostDataToIntelliH("https://apis-dev.intellih.com/api/EMR/SaveDataFromStagingToIntelliH", JSONString);

                        break;

                    default:
                        JSONStringReturn.Append("{");
                        JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientID + "\",");
                        JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRID + "\",");
                        JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                        JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                        JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                        JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                        JSONStringReturn.Append("\"ModuleID is not Found\"");
                        JSONStringReturn.Append("}");
                        return(JSONStringReturn.ToString());
                    }
                    objLog.LogRequest(oMasterConnection, Logs.Status.DataSentToIntelliH, RequestID, EMRID, ModuleID, EMRPatientID);
                    break;

                case "3":    //Epic
                    EMRIntegrations.Epic.EpicAPI objEpicAPI;
                    switch (ModuleID)
                    {
                    case "11":        //PatientDemographics
                        RequestID  = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objEpicAPI = new EMRIntegrations.Epic.EpicAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtPatientData = objEpicAPI.GetPatientDemographics(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID);

                        if (dtPatientData.Rows.Count == 0)
                        {
                            JSONStringReturn.Append("{");
                            JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientID + "\",");
                            JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRID + "\",");
                            JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                            JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                            JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                            JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                            JSONStringReturn.Append("\"No Patient Found\"");
                            JSONStringReturn.Append("}");
                            return(JSONStringReturn.ToString());
                        }

                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objEpicAPI.SavePatientDemographics(dtPatientData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objEpicAPI.GetJSONPatientDemographics(dtPatientData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    case "15":        //Allergy
                        RequestID  = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objEpicAPI = new EMRIntegrations.Epic.EpicAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtAllergyData = objEpicAPI.GetAllergy(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objEpicAPI.SaveAllergy(dtAllergyData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objEpicAPI.GetJSONAllergy(dtAllergyData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    case "5":        //Medications
                        RequestID  = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objEpicAPI = new EMRIntegrations.Epic.EpicAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtMedicationData = objEpicAPI.GetMedications(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objEpicAPI.SaveMedications(dtMedicationData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objEpicAPI.GetJSONMedications(dtMedicationData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);

                        //PostDataToIntelliH("https://apis-dev.intellih.com/api/EMR/SaveDataFromStagingToIntelliH", JSONString);

                        break;

                    case "1":        //Vitals
                        RequestID  = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objEpicAPI = new EMRIntegrations.Epic.EpicAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtVitalsData = objEpicAPI.GetVitals(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objEpicAPI.SaveVitals(dtVitalsData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objEpicAPI.GetJSONVitals(dtVitalsData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    default:
                        JSONStringReturn.Append("{");
                        JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientID + "\",");
                        JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRID + "\",");
                        JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                        JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                        JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                        JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                        JSONStringReturn.Append("\"ModuleID is not Found\"");
                        JSONStringReturn.Append("}");
                        return(JSONStringReturn.ToString());
                    }
                    objLog.LogRequest(oMasterConnection, Logs.Status.DataSentToIntelliH, RequestID, EMRID, ModuleID, EMRPatientID);
                    break;

                case "5":    //EpicR4
                    EMRIntegrations.EpicR4.EpicR4API objEpicR4API;
                    switch (ModuleID)
                    {
                    case "11":        //PatientDemographics
                        RequestID    = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objEpicR4API = new EMRIntegrations.EpicR4.EpicR4API();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtPatientData = objEpicR4API.GetPatientDemographics(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID);

                        if (dtPatientData.Rows.Count == 0)
                        {
                            JSONStringReturn.Append("{");
                            JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientID + "\",");
                            JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRID + "\",");
                            JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                            JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                            JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                            JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                            JSONStringReturn.Append("\"No Patient Found\"");
                            JSONStringReturn.Append("}");
                            return(JSONStringReturn.ToString());
                        }

                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objEpicR4API.SavePatientDemographics(dtPatientData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objEpicR4API.GetJSONPatientDemographics(dtPatientData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    case "15":        //Allergy
                        RequestID    = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objEpicR4API = new EMRIntegrations.EpicR4.EpicR4API();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtAllergyData = objEpicR4API.GetAllergy(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objEpicR4API.SaveAllergy(dtAllergyData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objEpicR4API.GetJSONAllergy(dtAllergyData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    case "5":        //Medications
                        RequestID    = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objEpicR4API = new EMRIntegrations.EpicR4.EpicR4API();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtMedicationData = objEpicR4API.GetMedications(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objEpicR4API.SaveMedications(dtMedicationData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objEpicR4API.GetJSONMedications(dtMedicationData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);

                        //PostDataToIntelliH("https://apis-dev.intellih.com/api/EMR/SaveDataFromStagingToIntelliH", JSONString);

                        break;

                    default:
                        JSONStringReturn.Append("{");
                        JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientID + "\",");
                        JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRID + "\",");
                        JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                        JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                        JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                        JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                        JSONStringReturn.Append("\"ModuleID is not Found\"");
                        JSONStringReturn.Append("}");
                        return(JSONStringReturn.ToString());
                    }
                    objLog.LogRequest(oMasterConnection, Logs.Status.DataSentToIntelliH, RequestID, EMRID, ModuleID, EMRPatientID);
                    break;

                case "6":    //DrChrono
                    EMRIntegrations.DrChrono.DrChronoAPI objDrChronoAPI;
                    switch (ModuleID)
                    {
                    case "11":        //PatientDemographics
                        RequestID      = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objDrChronoAPI = new EMRIntegrations.DrChrono.DrChronoAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtPatientData = objDrChronoAPI.GetPatientDemographics(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID, AccessToken);

                        if (dtPatientData.Rows.Count == 0)
                        {
                            JSONStringReturn.Append("{");
                            JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientID + "\",");
                            JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRID + "\",");
                            JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                            JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                            JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                            JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                            JSONStringReturn.Append("\"No Patient Found\"");
                            JSONStringReturn.Append("}");
                            return(JSONStringReturn.ToString());
                        }

                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objDrChronoAPI.SavePatientDemographics(dtPatientData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objDrChronoAPI.GetJSONPatientDemographics(dtPatientData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    case "5":        //Medications
                        RequestID      = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objDrChronoAPI = new EMRIntegrations.DrChrono.DrChronoAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtMedicationData = objDrChronoAPI.GetMedications(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID, AccessToken);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objDrChronoAPI.SaveMedications(dtMedicationData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objDrChronoAPI.GetJSONMedications(dtMedicationData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    case "12":        //Problemlist
                        RequestID      = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objDrChronoAPI = new EMRIntegrations.DrChrono.DrChronoAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtProblemlistData = objDrChronoAPI.GetProblemlist(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID, AccessToken);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objDrChronoAPI.SaveProblemlist(dtProblemlistData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objDrChronoAPI.GetJSONProblemlist(dtProblemlistData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    case "15":        //Allergy
                        RequestID      = InitialLog1(EMRID, ModuleID, EMRPatientID);
                        objDrChronoAPI = new EMRIntegrations.DrChrono.DrChronoAPI();
                        InitialLog2(EMRID, ModuleID, EMRPatientID, RequestID);

                        DataTable dtAllergyData = objDrChronoAPI.GetAllergy(EMRPatientID, oMasterConnection.EmrStagingDBConStr, RequestID, AccessToken);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataPulledInMemoryFromEMR, RequestID, EMRID, ModuleID, EMRPatientID);
                        objDrChronoAPI.SaveAllergy(dtAllergyData, oMasterConnection.EmrStagingDBConStr, RequestID);
                        objLog.LogRequest(oMasterConnection, Logs.Status.DataSavedInStagingDatabase, RequestID, EMRID, ModuleID, EMRPatientID);
                        JSONString = objDrChronoAPI.GetJSONAllergy(dtAllergyData, EMRPatientID, RequestID, EMRID, ModuleID, UserID);
                        break;

                    default:
                        JSONStringReturn.Append("{");
                        JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientID + "\",");
                        JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRID + "\",");
                        JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                        JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                        JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                        JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                        JSONStringReturn.Append("\"ModuleID is not Found\"");
                        JSONStringReturn.Append("}");
                        return(JSONStringReturn.ToString());
                    }
                    objLog.LogRequest(oMasterConnection, Logs.Status.DataSentToIntelliH, RequestID, EMRID, ModuleID, EMRPatientID);
                    break;

                default:
                    JSONStringReturn.Append("{");
                    JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientID + "\",");
                    JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRID + "\",");
                    JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                    JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                    JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                    JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                    JSONStringReturn.Append("\"EMRID is not Found\"");
                    JSONStringReturn.Append("}");
                    return(JSONStringReturn.ToString());
                }

                //if (EMRIntegration.Data.SqlHelper.TestSQLConnection(Startup.ConnectionString) == false)
                //{
                //    //Generate Log file
                //    return new DataTable();
                //}

                return(JSONString);
            }
            catch (Exception ex)
            {
                JSONStringReturn.Append("{");
                JSONStringReturn.Append("\"EMRPatientId\":" + "\"" + EMRPatientID + "\",");
                JSONStringReturn.Append("\"EMRId\":" + "\"" + EMRID + "\",");
                JSONStringReturn.Append("\"ModuleId\":" + "\"" + ModuleID + "\",");
                JSONStringReturn.Append("\"RequestId\":" + "\"" + RequestID + "\",");
                JSONStringReturn.Append("\"CreatedBy\":" + "\"\",");
                JSONStringReturn.Append("\"EMRUserExtensionLogDetails\":");
                JSONStringReturn.Append("\"" + ex.Message + "\"");
                JSONStringReturn.Append("}");
                return(JSONStringReturn.ToString());
            }
        }