Commit 76e0bbc7 authored by Krishna Reddy Tamatam's avatar Krishna Reddy Tamatam

Changes upto 22-08-2025

parent 6fe1a321
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Threading.Tasks;
using FTP_Services.Core.Models;
using FTP_Services.Services;
using iTextSharp.text.pdf;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace FTP_Services.Services.Controllers
{
......@@ -41,7 +49,7 @@ namespace FTP_Services.Services.Controllers
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<Login>? RequestsList = adapter.LoginData(model.UserName);
List<Object>? RequestsList = adapter.LoginData(model.UserName);
return Ok(RequestsList);
}
catch (Exception ex)
......@@ -68,6 +76,7 @@ namespace FTP_Services.Services.Controllers
return NotFound("No results");
}
}
[HttpGet("GetSearchedPatients")]
public IActionResult GetSearchedPatients(string SearchText, int ProviderId, int LocationId, int DateType, string StartDate, string EndDate, int DischType)
{
......@@ -87,13 +96,13 @@ namespace FTP_Services.Services.Controllers
}
[HttpGet("GetAdmissionDataHistory")]
public IActionResult GetAdmissionDataHistory(int PatientID, int LocationID, int ProviderID, int DateType, string StartDate, string EndDate)
public IActionResult GetAdmissionDataHistory(int PatientID, int LocationID, int ProviderID, int DateType, string StartDate, string EndDate, int RecType)
{
log.Debug("GetAdmissionDataHistory ==> ");
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<object>? RequestsList = adapter.GetAdmissionDataHistory(PatientID, LocationID, ProviderID, DateType, StartDate, EndDate);
List<object>? RequestsList = adapter.GetAdmissionDataHistory(PatientID, LocationID, ProviderID, DateType, StartDate, EndDate, RecType);
return Ok(RequestsList);
}
catch (Exception ex)
......@@ -119,14 +128,15 @@ namespace FTP_Services.Services.Controllers
return NotFound("No results");
}
}
[HttpGet("LoadPhysicians")]
public IActionResult GetLoadPhysicians(int LocationId,Boolean IsOldData)
public IActionResult GetLoadPhysicians(int LocationId, int RecType)
{
log.Debug("LoadPhysicians ==> ");
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<object>? RequestsList = adapter.GeLoadPhysicians(LocationId,IsOldData);
List<object>? RequestsList = adapter.GeLoadPhysicians(LocationId, RecType);
return Ok(RequestsList);
}
catch (Exception ex)
......@@ -153,13 +163,13 @@ namespace FTP_Services.Services.Controllers
}
}
[HttpGet("GetLocations")]
public IActionResult GetLocations(Boolean IsLoadAll,Boolean IsOldData) //int LocationId,
public IActionResult GetLocations(Boolean IsLoadAll, int RecType) //int LocationId,
{
log.Debug("GetLocations ==> ");
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<object>? RequestsList = adapter.LoadLocations(IsLoadAll,IsOldData);//LocationId,
List<object>? RequestsList = adapter.LoadLocations(IsLoadAll, RecType);//LocationId,
return Ok(RequestsList);
}
catch (Exception ex)
......@@ -249,6 +259,7 @@ namespace FTP_Services.Services.Controllers
return NotFound("No results");
}
}
[HttpGet("GetProcedures")]
public IActionResult GetProcedures()
{
......@@ -337,6 +348,22 @@ namespace FTP_Services.Services.Controllers
return NotFound("No results");
}
}
[HttpGet("GetDocumentYears")]
public IActionResult GetDocumentYears(int Parm_DType)
{
log.Debug("GetDocumentYears ==> ");
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<object>? RequestsList = adapter.GetDocumentYears(Parm_DType);
return Ok(RequestsList);
}
catch (Exception ex)
{
log.Error("Fail to get data for patient documents - Error:" + ex.Message);
return NotFound("No results");
}
}
[HttpGet("GetPatientAdmissions")]
public IActionResult GetPatientAdmissions(int SPatientID)
......@@ -354,14 +381,15 @@ namespace FTP_Services.Services.Controllers
return NotFound("No results");
}
}
[HttpGet("GetAdmissionDischargeData")]
public IActionResult GetAdmissionDischargeData(int SndAdmissionID,int SndIsOldData)
public IActionResult GetAdmissionDischargeData(int SndAdmissionID, int SndRecType)
{
log.Debug("GetPatientAdmissions ==> ");
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<object>? RequestsList = adapter.AdmissionDischargeData(SndAdmissionID,SndIsOldData);
List<object>? RequestsList = adapter.AdmissionDischargeData(SndAdmissionID, SndRecType);
return Ok(RequestsList);
}
catch (Exception ex)
......@@ -370,22 +398,7 @@ namespace FTP_Services.Services.Controllers
return NotFound("No results");
}
}
// [HttpPost("SavePatientDocument")]
// public int SavePatientDocument_bkp([FromBody] PatientDocumentDetailsModel model)
// {
// log.Debug("SavePatientDocument ==> ");
// int SavePT = 0;
// try
// {
// FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
// SavePT = adapter.SavePatientDocumentData(model);
// }
// catch (Exception ex)
// {
// log.Error("Fail to get data for save patient documents - Error:" + ex.Message);
// }
// return SavePT;
// }
[HttpPost("UpdateImageCategory")]
public int UpdateImageCategory(int sndPatDocId, int sndDocTypeId, int sndUserID)
......@@ -471,33 +484,6 @@ namespace FTP_Services.Services.Controllers
}
// [HttpPost("SaveAdmissionDischargeData")]
// public int SaveAdmissionDischargeData(int MRDId, int ProviderId, int DepartmentId, int AdmissionAge, string AdmissionDate,int AdmissionTypeId, string DischargeDate,
// int DischargeTypeId, string Cause, int UserId,string MRD_Wards, string MRD_ICDS, string MRD_Procedures)
// {
// log.Debug("SaveAdmissionDischargeData ==> Received request.");
// int savedCount = 0;
// try
// {
// FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
// savedCount = adapter.SaveAdmissionDischargeData(
// MRDId, ProviderId, DepartmentId, AdmissionAge, AdmissionDate,
// AdmissionTypeId, DischargeDate, DischargeTypeId, Cause, UserId,
// MRD_Wards, MRD_ICDS, MRD_Procedures);
// log.Info($"SaveAdmissionDischargeData => Successfully saved {savedCount} records.");
// }
// catch (Exception ex)
// {
// log.Error("SaveAdmissionDischargeData -> Failed to save data - " + ex.Message);
// }
// return savedCount;
// }
[HttpGet("GetUserLocations")]
public IActionResult GetUserLocations(string sndUserName)
{
......@@ -599,32 +585,16 @@ namespace FTP_Services.Services.Controllers
}
}
// [HttpPost("DeletePatientDocument")]
// public int DeletePatientDocument(int DocumentID)
// {
// log.Debug("DeletePatientDocument ==> ");
// int DeletePT = 0;
// try
// {
// FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
// DeletePT = adapter.DeletePatientDocumentData(DocumentID);
// }
// catch (Exception ex)
// {
// log.Error("Fail to get data for delete patient documents - Error:" + ex.Message);
// }
// return DeletePT;
// }
[HttpPost("DeletePatientDocument")]
public string DeletePatientDocument(int AdmissionId, int DocumentID, int UserID,int SndIsOldData)
public string DeletePatientDocument(int AdmissionId, int DocumentID, int UserID, int SndRecType)
{
log.Debug("DeletePatientDocument ==> ");
string DeletePT = "";
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
DeletePT = adapter.DeletePatientDocumentData(AdmissionId, DocumentID, UserID,SndIsOldData);
DeletePT = adapter.DeletePatientDocumentData(AdmissionId, DocumentID, UserID, SndRecType);
}
catch (Exception ex)
{
......@@ -828,7 +798,6 @@ namespace FTP_Services.Services.Controllers
//Using for Scan upload
[HttpPost("UploadProfileImageAsync")]
public async Task<string> UploadProfileImageAsync(
[FromBody] FileResponseModel model,
......@@ -1365,115 +1334,6 @@ namespace FTP_Services.Services.Controllers
}
}
// public async Task<string> UploadFileWithStreamAsync(string fileName, Stream stream)
// {
// if (stream == null)
// {
// throw new ArgumentNullException(nameof(stream), "Stream cannot be null.");
// }
// if (string.IsNullOrWhiteSpace(fileName))
// {
// throw new ArgumentNullException(
// nameof(fileName),
// "File name cannot be null or empty."
// );
// }
// string ftpUrl = _appSettings.FTPConfiguration.FtpURL.ToString();
// string ftpUserName = _appSettings.FTPConfiguration.Username.ToString();
// string ftpPassword = _appSettings.FTPConfiguration.Password.ToString();
// if (!ftpUrl.StartsWith("ftp://", StringComparison.OrdinalIgnoreCase))
// {
// throw new ArgumentException("FTP URL must start with ftp://", nameof(ftpUrl));
// }
// if (!ftpUrl.EndsWith("/"))
// {
// ftpUrl += "/";
// }
// string uploadUrl = ftpUrl + fileName;
// try
// {
// Uri uri = new Uri(uploadUrl);
// string strFolderPath = uri.AbsoluteUri.Substring(
// 0,
// uri.AbsoluteUri.LastIndexOf('/')
// );
// if (!CheckFolderExists(strFolderPath, ftpUserName, ftpPassword))
// {
// CreateFolder(strFolderPath, ftpUserName, ftpPassword);
// }
// FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(uploadUrl);
// ftp.Credentials = new NetworkCredential(ftpUserName, ftpPassword);
// ftp.KeepAlive = true;
// ftp.UseBinary = true; // Ensure binary mode for PDFs
// ftp.UsePassive = true; // Use passive mode for better firewall compatibility
// ftp.Method = WebRequestMethods.Ftp.UploadFile;
// // Set high timeout values to ensure file upload completion
// ftp.Timeout = 2400000; // Increased timeout for large files (40 minutes)
// ftp.ReadWriteTimeout = 2400000; // Increased read/write timeout for large files
// // Choose an appropriate buffer size for large files (e.g., 512 KB buffer)
// byte[] buffer = new byte[1048576]; // 1 MB buffer
// int bytesRead;
// long totalBytesUploaded = 0;
// using (Stream ftpStream = await ftp.GetRequestStreamAsync())
// {
// while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
// {
// await ftpStream.WriteAsync(buffer, 0, bytesRead);
// totalBytesUploaded += bytesRead;
// }
// }
// using (FtpWebResponse response = (FtpWebResponse)await ftp.GetResponseAsync())
// {
// // Console.WriteLine($"FTP Response: {response.StatusCode}");
// if (response.StatusCode == FtpStatusCode.ClosingData)
// {
// return ""; // Success
// }
// else
// {
// return response.StatusDescription; // Return status description if not successful
// }
// }
// }
// catch (WebException ex)
// {
// if (ex.Response is FtpWebResponse response)
// {
// using (response)
// {
// return "FTP Error: " + response.StatusDescription;
// }
// }
// return "WebException: " + ex.Message;
// }
// catch (Exception ex)
// {
// return "Exception: " + ex.Message;
// }
// }
// public static byte[] ToImageBytes(string image) =>
// !string.IsNullOrEmpty(image)
// ? Convert.FromBase64String(
// Regex.Replace(
// image,
// "data:image/(png|jpg|PNG|JPG|JPEG|jpeg|gif|GIF|bmp|BMP);base64,",
// string.Empty
// )
// )
// : null;
public static byte[] ToImageBytes(string image)
{
if (string.IsNullOrEmpty(image))
......@@ -1649,135 +1509,6 @@ namespace FTP_Services.Services.Controllers
}
}
// [HttpPost("UploadProfileImageAsyncLargeFiles")]
// public async Task<string> UploadProfileImageAsyncLargeFiles(
// [FromBody] FileResponseModel model,
// string filePath
// )
// {
// if (string.IsNullOrEmpty(filePath) && string.IsNullOrEmpty(model.Base64String))
// {
// return "Should not be empty filePath and file..";
// }
// var imageBytes = ToImageBytes(model.Base64String);
// var imageStream = new MemoryStream(imageBytes);
// var uploadResponse = await this.UploadFileWithStreamAsync_New(filePath, imageStream);
// return uploadResponse;
// }
// public async Task<string> UploadFileWithStreamAsync_New(string fileName, Stream stream)
// {
// if (stream == null)
// {
// throw new ArgumentNullException(nameof(stream), "Stream cannot be null.");
// }
// if (string.IsNullOrWhiteSpace(fileName))
// {
// throw new ArgumentNullException(
// nameof(fileName),
// "File name cannot be null or empty."
// );
// }
// string ftpUrl = _appSettings.FTPConfiguration.FtpURL.ToString();
// string ftpUserName = _appSettings.FTPConfiguration.Username.ToString();
// string ftpPassword = _appSettings.FTPConfiguration.Password.ToString();
// // Ensure the URL starts with "ftp://" and ends with a slash
// if (!ftpUrl.StartsWith("ftp://", StringComparison.OrdinalIgnoreCase))
// {
// throw new ArgumentException("FTP URL must start with ftp://", nameof(ftpUrl));
// }
// if (!ftpUrl.EndsWith("/"))
// {
// ftpUrl += "/";
// }
// string uploadUrl = ftpUrl + fileName;
// try
// {
// // Extract the FTP server host from the FTP URL
// Uri uri = new Uri(uploadUrl);
// string ftpHost = uri.Host;
// // Create an FTP client using FluentFTP
// using (
// FluentFTP.FtpClient ftpClient = new FluentFTP.FtpClient(
// ftpHost,
// new NetworkCredential(ftpUserName, ftpPassword)
// )
// )
// {
// // Connect to the FTP server asynchronously
// await ftpClient.ConnectAsync();
// // Extract the folder path (directory) from the URL (excluding the protocol part and file name)
// string remoteFolderPath = uri.AbsolutePath;
// // Normalize the path: replace backslashes with forward slashes
// remoteFolderPath = remoteFolderPath.Replace("\\", "/");
// // Remove the file name from the path, leaving only the directory portion
// remoteFolderPath = Path.GetDirectoryName(remoteFolderPath);
// // Ensure the folder path ends with a slash
// if (!remoteFolderPath.EndsWith("/"))
// {
// remoteFolderPath += "/";
// }
// // Log the path for debugging
// Console.WriteLine($"Checking if directory exists: {remoteFolderPath}");
// // Check if the directory exists
// bool directoryExists = await ftpClient.DirectoryExistsAsync(remoteFolderPath);
// if (directoryExists)
// {
// Console.WriteLine("Directory exists.");
// }
// else
// {
// Console.WriteLine("Directory does not exist.");
// }
// // If the directory does not exist, create it
// if (!directoryExists)
// {
// await ftpClient.CreateDirectoryAsync(remoteFolderPath);
// Console.WriteLine("Directory created.");
// }
// // Upload the file to the FTP server
// FtpStatus uploadStatus = await ftpClient.UploadAsync(
// stream,
// fileName,
// FtpRemoteExists.Overwrite
// );
// // Check if the upload was successful
// if (uploadStatus == FtpStatus.Success)
// {
// return "";
// }
// else
// {
// return "File upload failed. Status: " + uploadStatus.ToString();
// }
// }
// }
// catch (FtpException ex)
// {
// return "FTP Error: " + ex.Message;
// }
// catch (Exception ex)
// {
// return "Exception: " + ex.Message;
// }
// }
[HttpPost("MoveFileAsync")]
public async Task<string> MoveFileAsync(string sourceFilePath, string destinationFilePath)
......@@ -1861,6 +1592,365 @@ namespace FTP_Services.Services.Controllers
}
}
//----------------------------------------history function ----------------------------------------------------------
[HttpGet("CheckPatAdmExist")]
public IActionResult GetHist_CheckPatAdmExist(int Parm_PatientId, string Parm_OldUMRNo, string Parm_NewUMRNo, int Parm_AdmId, string Parm_OldIPNo, string Parm_NewIPNo, Boolean Parm_IsEdit)
{
log.Debug("CheckPatAdmExist ==> ");
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<object>? RequestsList = adapter.GetHist_CheckPatAdmExist(Parm_PatientId, Parm_OldUMRNo, Parm_NewUMRNo, Parm_AdmId, Parm_OldIPNo, Parm_NewIPNo, Parm_IsEdit);
return Ok(RequestsList);
}
catch (Exception ex)
{
log.Error("Fail to get data for CheckPatAdmExist - Error:" + ex.Message);
return NotFound("No results");
}
}
[HttpGet("GetHistPatientData")]
public IActionResult GetHistPatientData(int Parm_PatientId)
{
log.Debug("GetHistPatientData ==> ");
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<object>? RequestsList = adapter.GetHist_PatientData(Parm_PatientId);
return Ok(RequestsList);
}
catch (Exception ex)
{
log.Error("Fail to get data for GetHistPatientData - Error:" + ex.Message);
return NotFound("No results");
}
}
[HttpGet("GetHistAdmissionData")]
public IActionResult GetAdmissionHistoryData(int Parm_HistAdmId)
{
log.Debug("GetHistAdmissionData ==> ");
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<object>? RequestsList = adapter.GetHist_AdmissIonData(Parm_HistAdmId);
return Ok(RequestsList);
}
catch (Exception ex)
{
log.Error("Fail to get data for GetHistAdmissionData - Error:" + ex.Message);
return NotFound("No results");
}
}
[HttpGet("LoadLookupValues")]
public IActionResult LoadLookupValues(string Parm_LookupName, string Parm_WhereCond, Boolean Parm_ShowBlankRow)
{
log.Debug("LoadLookupValues ==> ");
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<object>? RequestsList = adapter.LoadLookupValues(Parm_LookupName, Parm_WhereCond, Parm_ShowBlankRow);
return Ok(RequestsList);
}
catch (Exception ex)
{
log.Error("Fail to get data for LoadLookupValues - Error:" + ex.Message);
return NotFound("No results");
}
}
[HttpPost("SaveHistAdmissionDischargeData")]
public IActionResult SaveHistAdmissionDischargeData([FromBody] string Parm_AdmData)
{
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
int savedCount = adapter.SaveHistoryOfAdmissionDischargeData(Parm_AdmData);
log.Info($"SaveHistAdmissionDischargeData => Successfully saved {savedCount} records.");
return Ok(savedCount);
}
catch (Exception ex)
{
log.Error("SaveHistAdmissionDischargeData -> Failed to save data - " + ex.Message);
return StatusCode(500, "Internal server error");
}
}
[HttpPost("ExecuteNonQuery")]
public string ExecuteNonQuery([FromBody] string jsonSql)
{
if (string.IsNullOrWhiteSpace(jsonSql))
{
log.Error("Request string is null or empty.");
return "Request string is null or empty.";
}
return new FTPDataAdapter(_appSettings).ExecuteNonQuery(jsonSql);
}
[HttpPost("SaveHistoryPatient")]
public int SaveHistoryPatient([FromBody] string Parm_PatientData)//string Parm_PatientData
{
int savedCount = 0;
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
savedCount = adapter.SaveHistoryOfPatient(Parm_PatientData);
}
catch (Exception ex)
{
log.Error("SaveHistoryPatient -> Failed to save documents - Error: " + ex.Message);
}
return savedCount;
}
[HttpGet("GetDocumentCountList")]
public IActionResult GetDocumentCountList(string Parm_Year,int Parm_DType)
{
log.Debug("GetDocumentCountList ==> ");
try
{
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<object>? RequestsList = adapter.GetDocumentCountList(Parm_Year,Parm_DType);
return Ok(RequestsList);
}
catch (Exception ex)
{
log.Error("Fail to get data for GetDocumentCountList - Error:" + ex.Message);
return NotFound("No results");
}
}
//-------------------------------------------------------------------Patient docs Merge Api -----------------------
[HttpGet("GetPatientMergeDocuments")]
public async Task<bool> GetPatientMergeDocuments(int PatientID)
{
try
{
string rawPrimaryPath = _appSettings.FolderOptions.PrimaryFolderPath;
string rawSecondaryPath = _appSettings.FolderOptions.SecondaryFolderPath;
string primaryFolderPath = NormalizePathForCurrentOS(rawPrimaryPath);
string secondaryFolderPath = NormalizePathForCurrentOS(rawSecondaryPath);
FTPDataAdapter adapter = new FTPDataAdapter(_appSettings);
List<PatientDocumentsPathsData>? documentPaths = adapter.GetPatientDocumentPaths(
PatientID,
primaryFolderPath,
secondaryFolderPath
);
if (documentPaths == null || documentPaths.Count == 0)
return false;
List<byte[]> pdfByteArrays = new List<byte[]>();
foreach (var doc in documentPaths)
{
if (doc == null || string.IsNullOrWhiteSpace(doc.DocumentPath))
continue;
string FileFullPath = Path.GetFullPath(doc.DocumentPath);
await ProcessPatientDocFile(FileFullPath, pdfByteArrays);
}
if (pdfByteArrays.Count == 0)
return false;
byte[] mergedPdfBytes = ConcatenatePdfs_New(pdfByteArrays);
var SavedPathFile = documentPaths
?.FirstOrDefault(doc => doc.PatientId == PatientID)
?.DocumentPath;
if (!string.IsNullOrEmpty(SavedPathFile))
{
string strFileFullPath = Path.GetFullPath(SavedPathFile)
.Replace(primaryFolderPath, "")
.Replace(secondaryFolderPath, "");
string[] parts = strFileFullPath.Split('\\');
string resultpath = ""; string outputFileName = "";
if (parts.Length >= 3)
{
string patientId = parts[1];
string guid = parts[2];
outputFileName = Path.Combine($"{patientId}\\{guid}\\{"ALL Info"}", $"{PatientID}_AllInfoPatDocuments.pdf");
}
string outputFilePath = Path.Combine(primaryFolderPath, outputFileName);
var directoryPath = Path.GetDirectoryName(outputFilePath);
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
await System.IO.File.WriteAllBytesAsync(outputFilePath, mergedPdfBytes);
}
return true;
}
catch (Exception ex)
{
// Optional: use proper logger
Console.WriteLine(
$"GetPatientMergeDocuments failed for PatientID={PatientID}: {ex.Message}"
);
return false;
}
}
private async Task ProcessPatientDocFile(string filePath, List<byte[]> pdfByteList)
{
if (!System.IO.File.Exists(filePath))
return;
string ext = Path.GetExtension(filePath).ToLowerInvariant();
if (ext == ".doc" || ext == ".docx")
return;
try
{
byte[] pdfBytes;
if (ext == ".pdf")
{
pdfBytes = await System.IO.File.ReadAllBytesAsync(filePath);
}
else
{
pdfBytes = ConvertImageToPdfBytes(filePath);
}
if (pdfBytes != null && pdfBytes.Length > 0)
{
pdfByteList.Add(pdfBytes);
}
}
catch (Exception ex)
{
Console.WriteLine($"Error processing file: {filePath}, {ex.Message}");
}
}
public string NormalizePathForCurrentOS(string path)
{
if (string.IsNullOrEmpty(path))
return path;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Convert forward slashes to backslashes
path = path.Replace('/', '\\');
// If path is like "D:", add trailing backslash
if (path.Length == 2 && path[1] == ':')
path += '\\';
return path;
}
else if (
RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
|| RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
)
{
// Convert backslashes to forward slashes
return path.Replace('\\', '/');
}
else
{
throw new PlatformNotSupportedException("Unsupported OS platform.");
}
}
private async Task ProcessFolderFiles(string folderPath, List<byte[]> pdfByteList)
{
if (!Directory.Exists(folderPath))
return;
string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
foreach (var file in files)
{
string ext = Path.GetExtension(file).ToLowerInvariant();
if (ext == ".doc" || ext == ".docx")
continue;
byte[] pdfBytes;
if (ext == ".pdf")
{
pdfBytes = await System.IO.File.ReadAllBytesAsync(file);
}
else
{
pdfBytes = ConvertImageToPdfBytes(file);
}
pdfByteList.Add(pdfBytes);
}
}
public byte[] ConcatenatePdfs_New(List<byte[]> documents)
{
PdfReader.unethicalreading = true;
using (var ms = new MemoryStream())
{
iTextSharp.text.Document document = new iTextSharp.text.Document();
PdfCopy copy = new PdfCopy(document, ms);
document.Open();
foreach (var pdfBytes in documents)
{
using (var inputPdfStream = new MemoryStream(pdfBytes))
{
PdfReader reader = new PdfReader(inputPdfStream);
reader.ConsolidateNamedDestinations();
for (int i = 1; i <= reader.NumberOfPages; i++)
{
copy.AddPage(copy.GetImportedPage(reader, i));
}
copy.FreeReader(reader);
reader.Close();
}
}
document.Close();
return ms.ToArray();
}
}
private byte[] ConvertImageToPdfBytes(string imagePath)
{
using (MemoryStream ms = new MemoryStream())
{
using (
iTextSharp.text.Document doc = new iTextSharp.text.Document(
iTextSharp.text.PageSize.A4
)
)
{
PdfWriter.GetInstance(doc, ms);
doc.Open();
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imagePath);
img.ScaleToFit(doc.PageSize.Width - 40, doc.PageSize.Height - 40);
img.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
doc.Add(img);
doc.Close();
}
return ms.ToArray();
}
}
// private async Task<string> MoveFileToFtpAsync(string sourceFilePath, string destinationFilePath)
// {
// try
......@@ -1892,6 +1982,116 @@ namespace FTP_Services.Services.Controllers
// }
private byte[] DecryptFile(byte[] encryptedData, string encryptionKey)
{
byte[] keyBytes = Encoding.UTF8.GetBytes(encryptionKey);
byte[] decryptedBytes;
using (MemoryStream encryptedStream = new MemoryStream(encryptedData))
using (MemoryStream decryptedStream = new MemoryStream())
using (Aes aes = Aes.Create())
{
aes.Key = keyBytes;
aes.IV = keyBytes.Take(16).ToArray();
using (ICryptoTransform decryptor = aes.CreateDecryptor())
using (CryptoStream cryptoStream = new CryptoStream(encryptedStream, decryptor, CryptoStreamMode.Read))
{
cryptoStream.CopyTo(decryptedStream);
}
decryptedBytes = decryptedStream.ToArray();
}
return decryptedBytes;
}
[HttpPost("GetMRDCompressedIcons")]
public async Task<IActionResult> GetMRDCompressedIcons(
[FromBody] DocumentResponseModel model
)
{
if (model == null || string.IsNullOrWhiteSpace(model.FolderPath))
return BadRequest("Folder path is required.");
if (model.FilePaths == null || model.FilePaths.Count == 0)
return BadRequest("No file paths provided.");
string baseDir = _appSettings.MappedDriveSettings.BaseDirectory;
string encryptionKey = "12345678909876543210123456789098";
var results = new List<object>();
foreach (var fileName in model.FilePaths)
{
if (string.IsNullOrWhiteSpace(fileName))
{
results.Add(new { Path = fileName, Error = "Empty file name" });
continue;
}
string mainFolder = model.FolderPath.Replace(
"/",
Path.DirectorySeparatorChar.ToString()
);
string fullPath = Path.Combine(baseDir, mainFolder, fileName);
try
{
if (!System.IO.File.Exists(fullPath))
{
results.Add(
new
{
Path = Path.Combine(mainFolder, fileName),
Error = "File not found"
}
);
continue;
}
byte[] encryptedData = await System.IO.File.ReadAllBytesAsync(fullPath);
byte[] decryptedBytes = DecryptFile(encryptedData, encryptionKey);
using var msDecrypted = new MemoryStream(decryptedBytes);
using var originalImage = Image.FromStream(msDecrypted);
int height = int.Parse(_appSettings.ResolutionSettings.Height);
int width = int.Parse(_appSettings.ResolutionSettings.Width);
using var resizedImage = ResizeImage(originalImage, width, height);
using var msResized = new MemoryStream();
resizedImage.Save(msResized, ImageFormat.Jpeg);
string base64 = Convert.ToBase64String(msResized.ToArray());
results.Add(new { Path = Path.Combine(mainFolder, fileName), Base64 = base64 });
}
catch (Exception ex)
{
results.Add(
new { Path = Path.Combine(mainFolder, fileName), Error = ex.Message }
);
}
}
return Ok(results);
}
private Image ResizeImage(Image img, int width, int height)
{
var bmp = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.DrawImage(img, 0, 0, width, height);
}
img.Dispose();
return bmp;
}
public void WriteLog(string SndException)
......
......@@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="ExcelDataReader" Version="3.6.0" />
<PackageReference Include="ExcelDataReader.DataSet" Version="3.6.0" />
<PackageReference Include="iTextSharp" Version="5.5.13.4" />
<PackageReference Include="log4net" Version="2.0.14" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
......
......@@ -8,12 +8,17 @@ namespace FTP_Services.Core.Models
public AppSettings()
{
Secret ="";
Secret = "";
ConnectionString = "";
AdminConnectionString ="";
AdminConnectionString = "";
}
public FTPConfiguration FTPConfiguration { get; set; }
public FolderOptions FolderOptions { get; set; }
public MappedDriveSettings MappedDriveSettings { get; set; }
public ResolutionSettings ResolutionSettings { get; set; }
}
public class FTPConfiguration
......@@ -31,9 +36,32 @@ namespace FTP_Services.Core.Models
Password = "";
FtpURL = "";
FTPMODE = false;
DestinationPathFtp ="";
DestinationPathFile="";
DestinationPathFtp = "";
DestinationPathFile = "";
}
}
public class FolderOptions
{
public string PrimaryFolderPath { get; set; }
public string SecondaryFolderPath { get; set; }
public FolderOptions()
{
PrimaryFolderPath = "";
SecondaryFolderPath = "";
}
}
public class MappedDriveSettings
{
public string? BaseDirectory { get; set; }
}
public class ResolutionSettings
{
public string? Height { get; set; }
public string? Width { get; set; }
}
}
......@@ -16,7 +16,7 @@ namespace FTP_Services.Core.Models
public string UploadedDate { get; set; }
public int AdmissionID { get; set; }
public int SortNo { get; set; }
public int IsOldData{get; set; }
public int RecType { get; set; }
public PatientDocumentDetailsModel()
{
......@@ -34,7 +34,7 @@ namespace FTP_Services.Core.Models
UploadedDate = "";
AdmissionID = 0;
SortNo = 1;
IsOldData = 1;
RecType = 1;
}
}
......@@ -248,6 +248,20 @@ namespace FTP_Services.Core.Models
RecordCount = -1;
}
}
public class AdmissionDischargeHistData
{
public string Parm_AdmData { get; set; }
}
public class PatientHistData
{
public string Parm_PatientData { get; set; }
}
public class SQLRequest
{
public string sql { get; set; }
}
public class AdmissionDischargeModel
{
public int MRDId { get; set; }
......@@ -273,7 +287,7 @@ namespace FTP_Services.Core.Models
public string Diagnosis { get; set; }
public string MRD_OtherProcedures { get; set; }
public int IsOldData { get; set; }
public int RecType { get; set; }
}
// Supporting Models
......@@ -306,5 +320,18 @@ namespace FTP_Services.Core.Models
public int PatDocId { get; set; }
public int SortNo { get; set; }
}
public class PatientDocumentsPathsData
{
public int PatientId { get; set; }
public int PatientDocumentId { get; set; }
public bool ExternalFtp { get; set; }
public string? DocumentName { get; set; }
public string? DocumentPath { get; set; }
}
public class DocumentResponseModel
{
public string? FolderPath { get; set; }
public List<string>? FilePaths { get; set; }
}
}
......@@ -134,12 +134,12 @@ app.UseEndpoints(endpoints =>
if (app.Environment.IsDevelopment())
{
app.Run("http://localhost:5603");
app.Run("http://localhost:5604");
}
else
{
//app.Run(); //For Test Site
app.Run("http://*:4708"); // For Production
app.Run(); //For Test Site
//app.Run("http://*:4708"); // For Production
//app.Run("http://*:4709"); // For Admin
}
......
......@@ -17,6 +17,7 @@ using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Npgsql;
using PetaPoco;
using Newtonsoft.Json.Linq;
namespace FTP_Services.Services
{
......@@ -28,14 +29,14 @@ namespace FTP_Services.Services
log.Debug("FTPDataAdapter() Called");
}
public List<Login>? LoginData(string sndUserName)
public List<Object>? LoginData(string sndUserName)
{
List<Login>? LoginData = null;
List<Object>? LoginData = null;
try
{
using (var tx = _repository.GetTransaction())
{
LoginData = _repository.Fetch<Login>(
LoginData = _repository.Fetch<Object>(
"SELECT * FROM \"SPScanTool_GetLoginDetails\"(@Parm_UserName)",
new { Parm_UserName = sndUserName }
);
......@@ -252,7 +253,7 @@ namespace FTP_Services.Services
}
public List<object>? GeLoadPhysicians(int sndLocationId,Boolean sndIsOldData)
public List<object>? GeLoadPhysicians(int sndLocationId, int sndRecType)
{
List<object>? PhysiciansData = null;
try
......@@ -260,10 +261,10 @@ namespace FTP_Services.Services
using (var tx = _repository.GetTransaction())
{
string sqlQuery =
$"SELECT * FROM \"SPScanTool_LoadPhysicians\"(@Parm_LocationId,@Param_IsOldData)";
$"SELECT * FROM \"SPScanTool_LoadPhysicians\"(@Parm_LocationId,@Param_RecType)";
PhysiciansData = _repository.Fetch<object>(
sqlQuery,
new { Parm_LocationId = sndLocationId,Param_IsOldData = sndIsOldData }
new { Parm_LocationId = sndLocationId, Param_RecType = sndRecType }
);
GC.Collect();
tx.Complete();
......@@ -276,7 +277,7 @@ namespace FTP_Services.Services
return null;
}
}
public List<object>? GetAdmissionDataHistory(int PatientID, int LocationID, int ProviderID, int DateType, string StartDate, string EndDate)
public List<object>? GetAdmissionDataHistory(int PatientID, int LocationID, int ProviderID, int DateType, string StartDate, string EndDate, int RecType)
{
List<object>? AdmissionDataHistory = null;
try
......@@ -284,7 +285,7 @@ namespace FTP_Services.Services
using (var tx = _repository.GetTransaction())
{
string sqlQuery =
$"SELECT * FROM \"SPScanTool_GetAdmissionData_History\"(@Parm_PatientId,@Parm_LocationId,@Parm_ProviderID,@Parm_DateType,@Parm_StartDate,@Parm_EndDate)";
$"SELECT * FROM \"SPScanTool_GetAdmissionData_History\"(@Parm_PatientId,@Parm_LocationId,@Parm_ProviderId,@Parm_DateType,@Parm_StartDate::character varying,@Parm_EndDate::character varying,@Parm_RecType)";
AdmissionDataHistory = _repository.Fetch<object>(
sqlQuery,
......@@ -292,10 +293,11 @@ namespace FTP_Services.Services
{
Parm_PatientId = PatientID,
Parm_LocationId = LocationID,
Parm_ProviderID = ProviderID, // Notice the case change here
Parm_ProviderId = ProviderID,
Parm_DateType = DateType,
Parm_StartDate = StartDate,
Parm_EndDate = EndDate
Parm_EndDate = EndDate,
Parm_RecType = RecType
}
);
......@@ -361,7 +363,7 @@ namespace FTP_Services.Services
$"SELECT * FROM \"SPScanTool_GetSearchedPatients_History\"(@Parm_SearchText,@parm_ProviderId,@parm_LocationId,@parm_DateType,@parm_StartDate,@parm_EndDate)";
SearchedPatientsHistoryData = _repository.Fetch<object>(
sqlQuery,
new { Parm_SearchText = SearchText, parm_ProviderId = ProviderId, parm_LocationId = LocationId, parm_DateType = DateType, parm_StartDate = StartDate, parm_EndDate = EndDate}
new { Parm_SearchText = SearchText, parm_ProviderId = ProviderId, parm_LocationId = LocationId, parm_DateType = DateType, parm_StartDate = StartDate, parm_EndDate = EndDate }
);
GC.Collect();
tx.Complete();
......@@ -405,7 +407,7 @@ namespace FTP_Services.Services
}
}
public List<object>? LoadLocations(Boolean IsLoadAll,Boolean IsOldData)//int LocationId,
public List<object>? LoadLocations(Boolean IsLoadAll, int RecType)//int LocationId,
{
List<object>? LoadLocationsData = null;
try
......@@ -414,10 +416,10 @@ namespace FTP_Services.Services
{
string sqlQuery =
$"SELECT * FROM \"SPScanTool_LoadLocations\"(@Parm_LoadAll,@Param_IsOldData)";
$"SELECT * FROM \"SPScanTool_LoadLocations\"(@Parm_LoadAll,@Param_RecType)";
LoadLocationsData = _repository.Fetch<object>(
sqlQuery,
new { Parm_LoadAll = IsLoadAll,Param_IsOldData =IsOldData } //Parm_LocationId = LocationId,
new { Parm_LoadAll = IsLoadAll, Param_RecType = RecType } //Parm_LocationId = LocationId,
);
GC.Collect();
tx.Complete();
......@@ -592,7 +594,7 @@ namespace FTP_Services.Services
}
}
public List<object>? PatientDocuments(int SPatientID, int SLocationID,int SAppointmentID, int SAdmissionID, int SDocID, string? SDueFrom, string? SDueTO)
public List<object>? PatientDocuments(int SPatientID, int SLocationID, int SAppointmentID, int SAdmissionID, int SDocID, string? SDueFrom, string? SDueTO)
{
List<object>? PatientDocumentsData = null;
try
......@@ -651,7 +653,7 @@ namespace FTP_Services.Services
}
}
public List<object>? AdmissionDischargeData(int SndAdmissionId,int SndIsOldData)
public List<object>? AdmissionDischargeData(int SndAdmissionId, int SndRecType)
{
List<object>? AdmissionDischargeData = null;
try
......@@ -660,10 +662,10 @@ namespace FTP_Services.Services
{
string sqlQuery =
$"SELECT * FROM \"SPScanTool_GetAdmissionDischargeData\"(@Parm_AdmissionId,@Parm_IsOldData)";
$"SELECT * FROM \"SPScanTool_GetAdmissionDischargeData\"(@Parm_AdmissionId,@Parm_RecType)";
AdmissionDischargeData = _repository.Fetch<object>(
sqlQuery,
new { Parm_AdmissionId = SndAdmissionId,Parm_IsOldData = SndIsOldData }
new { Parm_AdmissionId = SndAdmissionId, Parm_RecType = SndRecType }
);
GC.Collect();
tx.Complete();
......@@ -686,7 +688,7 @@ namespace FTP_Services.Services
string SQLStr = "SELECT public.\"SPScanTool_SaveAdmissionDischargeData\"(@MRDId, @PatientId, @AdmissionId, @ProviderId, " +
"@LocationId, @DepartmentId, @AdmissionAge, @AdmissionDate, @AdmissionTypeId, @DischargeDate, " +
"@DischargeType, @Cause, @UserId, @IsWardChanged, @IsICDChanged, @IsProcChanged, " +
"@Wards::jsonb, @ICDCodes::jsonb, @Procedures::jsonb, @MRD_Diagnosis,@MRD_OtherProcedures,@Parm_IsOldData)"; // Explicitly cast JSON to jsonb @MRD_Diagnosis::jsonb
"@Wards::jsonb, @ICDCodes::jsonb, @Procedures::jsonb, @MRD_Diagnosis,@MRD_OtherProcedures,@Parm_RecType)"; // Explicitly cast JSON to jsonb @MRD_Diagnosis::jsonb
foreach (var model in models)
{
......@@ -714,7 +716,7 @@ namespace FTP_Services.Services
Procedures = model.Procedures != null ? JsonConvert.SerializeObject(model.Procedures) : (object)DBNull.Value,
MRD_Diagnosis = string.IsNullOrEmpty(model.Diagnosis) ? (object)DBNull.Value : model.Diagnosis.ToString(),
MRD_OtherProcedures = string.IsNullOrEmpty(model.MRD_OtherProcedures) ? (object)DBNull.Value : model.MRD_OtherProcedures.ToString(),
Parm_IsOldData = model.IsOldData
Parm_RecType = model.RecType
};
savedCount += _repository.Single<int>(SQLStr, parameters);
......@@ -746,7 +748,7 @@ namespace FTP_Services.Services
foreach (var doc in patientDocs)
{
string SQLStr = "SELECT * FROM \"SPScanTool_SavePatientDocument\"(@PatDocId, @UploadedDate, @PatientId, @UploadedBy, " +
"@DocumentName, @DocumentType, @ContentType, @Size, @Description, @DocumentUrl, @ThumbnailUrl,@SortNo, @SplID, @AdmissionID,@Parm_IsOldData)";
"@DocumentName, @DocumentType, @ContentType, @Size, @Description, @DocumentUrl, @ThumbnailUrl,@SortNo, @SplID, @AdmissionID,@Parm_RecType)";
var parameters = new
{
......@@ -764,7 +766,7 @@ namespace FTP_Services.Services
SortNo = doc.SortNo,
SplID = doc.SplID,
AdmissionID = doc.AdmissionID,
Parm_IsOldData =doc.IsOldData
Parm_RecType = doc.RecType
};
_repository.Single<int>(SQLStr, parameters);
......@@ -907,7 +909,7 @@ namespace FTP_Services.Services
// return _Delete;
// }
public string DeletePatientDocumentData(int SndAdmissionId,int SndPatDocRecID, int SndUserID,int SndIsOldData)
public string DeletePatientDocumentData(int SndAdmissionId, int SndPatDocRecID, int SndUserID, int SndRecType)
{
string result = string.Empty;
try
......@@ -916,7 +918,7 @@ namespace FTP_Services.Services
{
string SQLStr =
"SELECT * FROM \"SPScanTool_DeletePatientDocument\"("
+ SndAdmissionId + ',' + SndPatDocRecID + ',' + SndUserID + ','+ SndIsOldData
+ SndAdmissionId + ',' + SndPatDocRecID + ',' + SndUserID + ',' + SndRecType
+ ");";
result = _repository.Single<string>(SQLStr);
......@@ -962,5 +964,307 @@ namespace FTP_Services.Services
return false;
}
}
//---------------------------------------------------------------- Added for Hsitory ------------------------------------------------------------------------------------
public List<object>? GetHist_CheckPatAdmExist(int sndPatientId, string sndOldUMRNo, string sndNewUMRNo, int sndAdmId, string sndOldIPNo, string sndNewIPNo, Boolean sndIsEdit)
{
List<object>? AdmissionHistoryData = null;
try
{
using (var tx = _repository.GetTransaction())
{
string sqlQuery =
$"SELECT * FROM \"SPScanTool_Hist_CheckPatAdmExist\"(@Parm_PatientId,@Parm_OldUMRNo,@Parm_NewUMRNo,@Parm_AdmId,@Parm_OldIPNo,@Parm_NewIPNo,@Parm_IsEdit)";
AdmissionHistoryData = _repository.Fetch<object>(
sqlQuery,
new
{
Parm_PatientId = sndPatientId,
Parm_OldUMRNo = sndOldUMRNo,
Parm_NewUMRNo = sndNewUMRNo,
Parm_AdmId = sndAdmId,
Parm_OldIPNo = sndOldIPNo,
Parm_NewIPNo = sndNewIPNo,
Parm_IsEdit = sndIsEdit
}
);
GC.Collect();
tx.Complete();
}
return AdmissionHistoryData;
}
catch (Exception ex)
{
log.Error("AdmissionHistoryData->Failed to get info from db - " + ex.Message);
return null;
}
}
public List<object>? GetHist_PatientData(int sndPatientId)
{
List<object>? PatientHistoryData = null;
try
{
using (var tx = _repository.GetTransaction())
{
string sqlQuery =
$"SELECT * FROM \"SPScanTool_Hist_GetPatientData\"(@Parm_PatientId)";
PatientHistoryData = _repository.Fetch<object>(
sqlQuery,
new
{
Parm_PatientId = sndPatientId
}
);
GC.Collect();
tx.Complete();
}
return PatientHistoryData;
}
catch (Exception ex)
{
log.Error("PatientHistoryData->Failed to get info from db - " + ex.Message);
return null;
}
}
public List<object>? LoadLookupValues(string sndLookupName, string sndWhereCond, Boolean sndShowBlankRow) //string Parm_LookupName,string Parm_WhereCond,Boolean Parm_ShowBlankRow
{
List<object>? PatientAdmissionHistoryData = null;
try
{
using (var tx = _repository.GetTransaction())
{
string sqlQuery =
$"SELECT * FROM \"SPScanTool_LoadLookupValues\"(@Parm_LookupName,@Parm_WhereCond,@Parm_ShowBlankRow)";
PatientAdmissionHistoryData = _repository.Fetch<object>(
sqlQuery,
new
{
Parm_LookupName = sndLookupName,
Parm_WhereCond = sndWhereCond,
Parm_ShowBlankRow = sndShowBlankRow
}
);
GC.Collect();
tx.Complete();
}
return PatientAdmissionHistoryData;
}
catch (Exception ex)
{
log.Error("PatientAdmissionHistoryData->Failed to get info from db - " + ex.Message);
return null;
}
}
public List<object>? GetHist_AdmissIonData(int sndPHistAdmId)
{
List<object>? PatientAdmissionHistoryData = null;
try
{
using (var tx = _repository.GetTransaction())
{
string sqlQuery =
$"SELECT * FROM \"SPScanTool_Hist_GetAdmissIonData\"(@Parm_HistAdmId)";
PatientAdmissionHistoryData = _repository.Fetch<object>(
sqlQuery,
new
{
Parm_HistAdmId = sndPHistAdmId
}
);
GC.Collect();
tx.Complete();
}
return PatientAdmissionHistoryData;
}
catch (Exception ex)
{
log.Error("PatientAdmissionHistoryData->Failed to get info from db - " + ex.Message);
return null;
}
}
public int SaveHistoryOfAdmissionDischargeData(string admissionDischargeJson)
{
int result = 0;
try
{
using (var tx = _repository.GetTransaction())
{
string escaped = admissionDischargeJson;
var obj = JsonConvert.DeserializeObject<object>(escaped);
string cleanJson = JsonConvert.SerializeObject(obj);
string SQLStr = "SELECT * FROM \"SPScanTool_Hist_SaveAdmissionDischargeData\"(@Parm_AdmData::jsonb)"; //::json
var parameters = new { Parm_AdmData = cleanJson };
result = _repository.Single<int>(SQLStr, parameters);
tx.Complete();
}
}
catch (Exception ex)
{
log.Error("SaveHistoryOfAdmissionDischargeData -> Failed to save admission/discharge data - Error: " + ex.Message);
}
return result;
}
public string ExecuteNonQuery(string sndSQL)
{
string result = "";
try
{
using (var tx = _repository.GetTransaction())
{
string escaped = sndSQL;
var obj = JsonConvert.DeserializeObject<object>(escaped);
string cleanJson = JsonConvert.SerializeObject(obj);
Console.WriteLine(cleanJson);
// No deserialization — use sndSQL directly
string SQLStr = "SELECT * FROM \"SPScanTool_ExecuteNonQuery\"(@Parm_SQL::jsonb)";
var parameters = new { Parm_SQL = cleanJson }; // Use the raw JSON string
result = _repository.Single<string>(SQLStr, parameters);
tx.Complete();
}
}
catch (Exception ex)
{
log.Error("ExecuteNonQuery -> Failed to save ExecuteNonQuery - Error: " + ex.Message);
}
return result;
}
public int SaveHistoryOfPatient(string patientDataJson)
{
int result = 0;
try
{
using (var tx = _repository.GetTransaction())
{
string escaped = patientDataJson;
var obj = JsonConvert.DeserializeObject<object>(escaped);
string cleanJson = JsonConvert.SerializeObject(obj);
//Console.WriteLine(cleanJson);
string SQLStr = "SELECT * FROM \"SPScanTool_SaveHistoryPatient\"(@Parm_PatientData::jsonb)";
var parameters = new { Parm_PatientData = cleanJson }; // No serialization here
result = _repository.Single<int>(SQLStr, parameters);
tx.Complete();
}
}
catch (Exception ex)
{
log.Error("SaveHistoryPatient -> Failed to save patient history data - Error: " + ex.Message);
}
return result;
}
public List<object>? GetDocumentCountList(string sndParm_Year,int sndDType)
{
List<object>? documentCountList = null;
try
{
using (var tx = _repository.GetTransaction())
{
string sqlQuery = $"SELECT * FROM \"SPScanTool_GetDocumentCountList\"(@Parm_Year,@Parm_DType)";
documentCountList = _repository.Fetch<object>(
sqlQuery,
new
{
Parm_Year = sndParm_Year,
Parm_DType = sndDType
});
GC.Collect();
tx.Complete();
}
return documentCountList;
}
catch (Exception ex)
{
log.Error("GetDocumentCountList -> Failed to get document count list from db - " + ex.Message);
return null;
}
}
public List<object>? GetDocumentYears(int sndDType)
{
List<object>? documentsYearsList = null;
try
{
using (var tx = _repository.GetTransaction())
{
string sqlQuery = $"SELECT * FROM \"SPScanTool_GetDocumentYears\"(@Parm_DType)";
documentsYearsList = _repository.Fetch<object>(sqlQuery,
new { Parm_DType = sndDType }
);
// documentsYearsList = _repository.Fetch<object>(
// "SELECT * FROM \"SPScanTool_GetDocumentYears\"()"
// );
GC.Collect();
tx.Complete();
}
return documentsYearsList;
}
catch (Exception ex)
{
log.Error("documentsYearsList -> Failed to get document count list from db - " + ex.Message);
return null;
}
}
public List<PatientDocumentsPathsData>? GetPatientDocumentPaths(
int PatientID,
string PrimaryFolderPath,
string SecondaryFolderPath
)
{
List<PatientDocumentsPathsData> PatientDocumentPaths = new List<PatientDocumentsPathsData>();
try
{
using (var tx = _repository.GetTransaction())
{
string sql = @"SELECT * FROM ""get_patient_documentsPaths""(@0, @1, @2);";
PatientDocumentPaths = _repository.Fetch<PatientDocumentsPathsData>(
sql,
PatientID,
PrimaryFolderPath,
SecondaryFolderPath
);
tx.Complete();
return PatientDocumentPaths;
}
}
catch (Exception ex)
{
log.Error("GetPatientDocumentPaths -> Failed to get info from db - " + ex.Message);
return null;
}
}
}
}
{
"AppSettings": {
"Secret": "A78E-F7FA-B0FD-DAA45BB866CD-AA73D560-DACC-978C-4A9B-9924-5DE7E33F0040-GCD00",
"ConnectionString": "SERVER=192.168.1.101;PORT=5432;UID=dbuser;PWD=dbuser123!;Database=FF_test_20250620;Timeout=1000",
"ConnectionString158": "SERVER=10.11.12.158;PORT=5432;UID=himsdbuser;PWD=dbuser@hims123!;Database=FF_TEST_16052025;Timeout=1000",
"AdminConnectionString": "SERVER=10.11.12.106;PORT=5432;UID=himsdbuser;PWD=dbuser@hims123!;database=CareaxesAdmin;Timeout=1000",
"ConnectionString": "SERVER=10.11.12.106;PORT=5432;UID=himsdbuser;PWD=dbuser@hims123!;Database=fernandez_20241125;Timeout=1000",
"ConnectionString106": "SERVER=10.11.12.106;PORT=5432;UID=himsdbuser;PWD=dbuser@hims123!;Database=fernandez_20241125;Timeout=1000",
"ConnectionString207": "SERVER=192.168.7.207;PORT=5432;UID=ff4dbuser;PWD=dbuser4ff123!;Database=fernandez_test_20250409_dev;Timeout=1000",
"ConnectionString1": "SERVER=10.11.12.106;PORT=5432;UID=himsdbuser;PWD=dbuser@hims123!;database=fernandez_20241125;Timeout=1000",
"AdminConnectionString1": "SERVER=10.11.12.106;PORT=5432;UID=himsdbuser;PWD=dbuser@hims123!;database=fernandez_20241125;Timeout=1000",
"FTPConfiguration": {
"Username": "admin",
"Password": "Fmh@xp@rt01",
......@@ -14,6 +13,17 @@
"FTPMODE": false,
"DestinationPathFile": "/ftproot/FTPRoot/",
"DestinationPathFtp": "/apachetomcat/webapps/documents/"
},
"FolderOptions": {
"PrimaryFolderPath": "D:\\GT\\PrimaryFolder",
"SecondaryFolderPath": "D:\\GT\\Second_Folder"
},
"MappedDriveSettings": {
"BaseDirectory": "Z:\\FTPAPI"
},
"ResolutionSettings": {
"Height": "20",
"Width":"20"
}
},
"https_port": 8001,
......
<html>
<head>
<title>FTP API</title>
<title>HIMS Scanner API</title>
</head>
<body>
<h1>Welcome to FTP API</h1>
<h1>Welcome to HIMS Scanner API</h1>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment