Commit e8b6fcab authored by Sandeep Sagar Panjala's avatar Sandeep Sagar Panjala

initial commit

parent bb60a83e
namespace Hims.Infrastructure.Services
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Domain.Entities;
using Domain.Repositories.UnitOfWork;
using Domain.Services;
using Shared.EntityModels;
using Shared.UserModels.Filters;
using Shared.UserModels.Pharmacy;
/// <inheritdoc />
public class DepartmentService : IDepartmentService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IDepartmentService" />
public DepartmentService(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
/// <inheritdoc />
public Task<IEnumerable<DepartmentModel>> FetchAsync(DepartmentFilterModel model)
{
var where = " WHERE 1 = 1 ";
if (model.CreatedBy != 0)
{
where += $@"and D.""CreatedBy"" = '{model.CreatedBy}'";
}
if (model.FromDate != null)
{
where += $@" and D.""CreatedDate""::date >= '{model.FromDate}' ";
}
if (model.ToDate != null)
{
where += $@" and D.""CreatedDate""::date <= '{model.ToDate}' ";
}
if (model.LocationIds != 0)
{
where += $@" and L.""LocationId""={model.LocationIds} ";
}
if (model.DepartmentId != null)
{
where += $@" and D.""DepartmentId""={model.DepartmentId} ";
}
if (!string.IsNullOrEmpty(model.DepartmentName))
{
where += $@" AND TRIM(UPPER(""DepartmentName"")) = '{model.DepartmentName.Trim().ToUpper()}'";
}
if (model.Active)
{
where += $@" and ""Active"" is true";
}
var query = $@"select
Count(*) OVER() AS ""TotalItems"",D.*,
string_agg(l.""Name"", ', ') as ""LocationNames"",string_agg(l.""LocationId""::text, ', ') as ""LocationIds""
from ""Department"" D
left join ""LocationDepartmentMap"" LM ON LM.""DepartmentId"" = D.""DepartmentId""
left join ""Location"" L ON L.""LocationId"" = LM.""LocationId""
{where}
group by D.""DepartmentId"" order by D.""CreatedDate"" desc ";
if (model.PageIndex <= 0)
{
return this.unitOfWork.Current.QueryAsync<DepartmentModel>(query);
}
model.PageIndex -= 1;
query += " LIMIT " + model.PageSize + " offset " + (model.PageIndex * model.PageSize);
return this.unitOfWork.Current.QueryAsync<DepartmentModel>(query);
}
/// <inheritdoc />
public async Task<int> AddAsync(DepartmentModel model)
{
using (var transaction = this.unitOfWork.BeginTransaction())
{
try
{
var checkIf = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"SELECT COUNT(""DepartmentId"") FROM ""Department"" WHERE TRIM(UPPER(""DepartmentName"")) = '{model.DepartmentName.ToUpper().Trim()}'");
//var query = $@"select COUNT(d.""DepartmentId"") FROM ""Department"" d join ""LocationDepartmentMap"" ldm on d.""DepartmentId"" = ldm.""DepartmentId"" WHERE TRIM(UPPER(""DepartmentName"")) = '{model.DepartmentName.ToUpper().Trim()}' AND ldm.""LocationId"" IN( {model.LocationIds} )";
//var checkIf = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>(query);
if (checkIf > 0)
{
return -1;
}
var department = new Department
{
DepartmentName = model.DepartmentName,
DeptType=model.DeptType,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
Active = true,
};
department.DepartmentId = await this.unitOfWork.Departments.InsertAsync(department, transaction);
if (department.DepartmentId == 0)
{
transaction.Rollback();
return 0;
}
if (model.LocationIds != null)
{
var ids = model.LocationIds.Split(',');
foreach (var locationId in ids)
{
var location = new LocationDepartmentMap
{
DepartmentId = department.DepartmentId,
LocationId = Convert.ToInt32(locationId)
};
var locationInsertId = await this.unitOfWork.LocationDepartmentMap.InsertAsync(location, transaction);
if (locationInsertId == 0)
{
transaction.Rollback();
return 0;
}
}
}
transaction.Commit();
return department.DepartmentId;
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
return 0;
}
}
}
/// <inheritdoc />
public async Task<int> UpdateAsync(DepartmentModel model)
{
using (var transaction = this.unitOfWork.BeginTransaction())
{
var checkIf = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"SELECT COUNT(""DepartmentId"") FROM ""Department"" WHERE TRIM(UPPER(""DepartmentName"")) = '{model.DepartmentName.ToUpper().Trim()}' AND ""DepartmentId"" <> {model.DepartmentId}");
if (checkIf > 0)
{
return -1;
}
var department = await this.unitOfWork.Departments.FindAsync(m => m.DepartmentId == model.DepartmentId);
department.DepartmentName = model.DepartmentName;
department.DeptType = model.DeptType;
department.Active = true;
department.ModifiedBy = model.ModifiedBy;
department.ModifiedDate = DateTime.Now;
var updated = await this.unitOfWork.Departments.UpdateAsync(department, transaction);
if (updated == 0)
{
transaction.Rollback();
return 0;
}
var query = $@"DELETE from ""LocationDepartmentMap"" where ""DepartmentId""= {department.DepartmentId} ";
var res = await this.unitOfWork.Current.QuerySingleOrDefaultAsync(query, transaction);
if (res == 0)
{
transaction.Rollback();
return 0;
}
if (model.LocationIds != null)
{
var ids = model.LocationIds.Split(',');
foreach (var locationId in ids)
{
var location = new LocationDepartmentMap
{
DepartmentId = department.DepartmentId,
LocationId = Convert.ToInt32(locationId)
};
var locationInsertId = await this.unitOfWork.LocationDepartmentMap.InsertAsync(location, transaction);
if (locationInsertId == 0)
{
transaction.Rollback();
return 0;
}
}
}
transaction.Commit();
return updated;
}
}
/// <inheritdoc />
public Task<int> DeleteAsync(int departmentId)
{
var query = $@"DELETE FROM ""Department"" WHERE ""DepartmentId""= {departmentId}";
return this.unitOfWork.Current.ExecuteAsync(query);
}
public async Task<string> FindNameByDepartmentId(int departmentId)
{
var query = $@"SELECT ""DepartmentName"" FROM ""Department"" WHERE ""DepartmentId"" = {departmentId}";
var response = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<string>(query);
return response;
}
}
}
\ No newline at end of file
namespace Hims.Infrastructure.Services
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Domain.Entities;
using Domain.Repositories.UnitOfWork;
using Domain.Services;
using Hims.Domain.Configurations;
using Hims.Shared.EntityModels;
using Newtonsoft.Json.Linq;
using Shared.UserModels.Filters;
/// <inheritdoc />
public class DietGuidLinesService : IDietGuidLinesService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
private readonly IRunningEnvironment runningEnvironment;
/// <inheritdoc cref="IBedService" />
public DietGuidLinesService(IUnitOfWork unitOfWork, IRunningEnvironment runningEnvironment)
{
this.unitOfWork = unitOfWork;
this.runningEnvironment = runningEnvironment;
}
public async Task<DietGuidLinesModel> GetDietDocumentOnIdAsync(int id)
{
var query = $@"select * FROM ""DietGuidLines"" where ""DietGuidLinesId"" = {id}";
return await this.unitOfWork.Current.QueryFirstOrDefaultAsync<DietGuidLinesModel>(query);
}
public async Task<IEnumerable<int>> AddAsync(IEnumerable<DietGuidLinesModel> model)
{
var Documents = model.Select(item => new DietGuidLines
{
Active = true,
CreatedBy = item.CreatedBy,
ContentType = item.ContentType,
Size = item.Size,
DietGuidLinesName = item.DietGuidLinesName,
PdfLink = item.PdfLink,
CreatedDate = DateTime.UtcNow,
DocumentUrl = item.DocumentUrl,
DietTypeId = item.DietTypeId
});
var responseIds = new List<int>();
foreach (var file in Documents)
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"select count(*) from ""DietGuidLines"" where lower (""DietGuidLinesName"") = '{file.DietGuidLinesName.ToLower()}' and ""DietGuidLinesId"" <> {file.DietGuidLinesId}");
if (checkIf > 0)
{
responseIds.Count();
responseIds.Count();
if (responseIds.Count <= 0)
{
return Enumerable.Empty<int>();
}
}
var response = await this.unitOfWork.DietGuidLines.InsertAsync(file);
responseIds.Add(response);
}
return responseIds;
}
public Task<int> DeleteAsync(DietGuidLinesModel model)
{
var query = $@"Delete from ""DietGuidLines"" where ""DietGuidLinesId"" = {model.DietGuidLinesId}";
return this.unitOfWork.Current.ExecuteAsync(query);
}
public async Task<IEnumerable<DietGuidLinesModel>> FetchAsync(DietGuidLinesModel model)
{
var where = $@"";
if (model.DietGuidLinesId > 0)
{
where = $@"";
}
var query = $@"select COUNT(*) OVER () AS ""TotalItems"",dt.""Name"" as ""DietTypeName"",dgl.""Active"",(CASE WHEN dgl.""DocumentUrl"" IS NOT NULL THEN CONCAT('{this.runningEnvironment.CurrentEnvironment}', '/',dgl.""DietGuidLinesName"",'/', dgl.""DocumentUrl"") ELSE NULL END) as ""DocumentUrl"",dgl.""ContentType"",dgl.""Size"",dgl.""DietGuidLinesId"",dgl.""DietGuidLinesName"",act.""FullName"" as ""CreatedByName"",ac.""FullName"" as ""ModifiedByName"",dgl.""CreatedDate"",dgl.""ModifiedDate"" from ""DietGuidLines"" dgl
JOIN ""Account"" act ON act.""AccountId"" = dgl.""CreatedBy""
left join ""DietType"" dt on dt.""DietTypeId"" = dgl.""DietTypeId""
left join ""Account"" ac on ac.""AccountId""=dgl.""ModifiedBy""
{where}ORDER BY dgl.""DietGuidLinesId"" DESC ";
if (model.PageIndex <= 0)
{
return await this.unitOfWork.Current.QueryAsync<DietGuidLinesModel>(query);
}
model.PageIndex -= 1;
query += " LIMIT " + model.PageSize + " offset " + (model.PageIndex * model.PageSize);
return await this.unitOfWork.Current.QueryAsync<DietGuidLinesModel>(query);
}
public async Task<int> ModifyStatusAsync(DietGuidLinesModel model)
{
var query = $@"UPDATE ""DietGuidLines""
SET ""ModifiedBy""={model.ModifiedBy}, ""ModifiedDate""=now(), ""Active""= {model.Active}
WHERE ""DietGuidLinesId""= {model.DietGuidLinesId}";
return await this.unitOfWork.Current.ExecuteAsync(query);
}
public async Task<int> UpdateAsync(DietGuidLinesModel model)
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"select count(*) from ""DietGuidLines"" where lower (""DietGuidLinesName"") = '{model.DietGuidLinesName.ToLower()}' and ""DietGuidLinesId"" <> {model.DietGuidLinesId}");
if (checkIf > 0)
{
return -1;
}
var record = await this.unitOfWork.DietGuidLines.FindAsync(m => m.DietGuidLinesId == model.DietGuidLinesId);
if (record == null)
{
return -2;
}
record.ModifiedBy = model.CreatedBy;
record.ModifiedDate = DateTime.Now;
record.DietGuidLinesName = model.DietGuidLinesName;
record.PdfLink = model.PdfLink;
return await this.unitOfWork.DietGuidLines.UpdateAsync(record);
}
}
}
\ No newline at end of file
using Dapper;
using Hims.Domain.Entities;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Services;
using Hims.Shared.EntityModels;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Hims.Infrastructure.Services
{
public class DietItemsServices : IDietItemsService
{
// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IDietSlotsMasterService" />
public DietItemsServices(IUnitOfWork unitOfWork
)
{
this.unitOfWork = unitOfWork;
}
public async Task<IEnumerable<DietItemsModel>> FetchItemsAsync(DietItemsModel model)
{
var where = $@" where 1=1 ";
if (model.Active == true)
{
where += $@" and di.""Active"" = true";
}
var query = $@"select di.""DietItemsId"",di.""DietItemsName"",di.""CreatedBy"",di.""CreatedDate"",di.""ModifiedBy"",di.""ModifiedDate"",
di.""MeasureId"",qm.""MeasureName"",a.""FullName"" as ""CreatedByName"", di.""Active"",b.""FullName"" as ""ModifiedByName""
from ""DietItems"" di
join ""QuantityMeasure"" qm on qm.""MeasureId""=di.""MeasureId""
join ""Account"" a on a.""AccountId"" = di.""CreatedBy""
left join ""Account"" b on b.""AccountId"" = di.""ModifiedBy"" {where}";
return await this.unitOfWork.Current.QueryAsync<DietItemsModel>(query);
}
public async Task<IEnumerable<DietItemsModel>> FetchMeasureAsync(DietItemsModel model)
{
var query = $@"select * from ""QuantityMeasure"" ";
return await this.unitOfWork.Current.QueryAsync<DietItemsModel>(query);
}
public async Task<int> InsertItemsAsync(DietItemsModel model)
{
var isExists = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"SELECT ""DietItemsId"" from ""DietItems"" WHERE UPPER(TRIM(""DietItemsName"")) = UPPER(TRIM('{model.DietItemsName}'))");
if (isExists > 0)
{
return -1;
}
var slot = new DietItems
{
DietItemsName = model.DietItemsName,
Active = true,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
MeasureId = model.MeasureId
};
return await this.unitOfWork.DietItems.InsertAsync(slot);
}
public async Task<int> UpdateAsync(DietItemsModel model)
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"select count(*) from ""DietItems"" where lower (""DietItemsName"") = '{model.DietItemsName.ToLower()}' and ""DietItemsId"" <> {model.DietItemsId}");
if (checkIf > 0)
{
return -1;
}
var record = await this.unitOfWork.DietItems.FindAsync(m => m.DietItemsId == model.DietItemsId);
if (record == null)
{
return -2;
}
record.ModifiedBy = model.CreatedBy;
record.ModifiedDate = DateTime.Now;
record.DietItemsName = model.DietItemsName;
record.Active = model.Active;
record.MeasureId = model.MeasureId;
return await this.unitOfWork.DietItems.UpdateAsync(record);
}
public async Task<int> ModifyStatusAsync(DietItemsModel model)
{
var query = $@"UPDATE ""DietItems"" SET ""ModifiedBy""={model.CreatedBy}, ""ModifiedDate""=now(), ""Active""= {model.Active}
WHERE ""DietItemsId""= {model.DietItemsId}";
return await this.unitOfWork.Current.ExecuteAsync(query);
}
}
}
using Dapper;
using Hims.Domain.Entities;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Services;
using Hims.Shared.EntityModels;
using Hims.Shared.UserModels.Common;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Hims.Infrastructure.Services
{
public class DietSlotsMastersServices : IDietSlotsMasterService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IDietSlotsMasterService" />
public DietSlotsMastersServices(IUnitOfWork unitOfWork
)
{
this.unitOfWork = unitOfWork;
}
public async Task<int> InsertSlotsAsync(DietSlotsModel model)
{
var isExists = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"SELECT ""DietSlotId"" from ""DietSlots"" WHERE UPPER(TRIM(""Name"")) = UPPER(TRIM('{model.Name}'))");
if (isExists > 0)
{
return -1;
}
var slot = new DietSlots
{
Name = model.Name,
StartTime = TimeSpan.Parse(model.StartTime),
EndTime = TimeSpan.Parse(model.EndTime),
Active = true,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
LocationId = (int)model.LocationId
};
try
{
return await this.unitOfWork.DietSlots.InsertAsync(slot);
}
catch (Exception e)
{
e.Message.ToString();
}
return 0;
}
public Task<IEnumerable<DietSlotsModel>> FetchSlotsAsync(DietSlotsModel model)
{
var where = $@" where 1=1 ";
if (model.Active == true)
{
where += $@" and ds.""Active"" = true";
}
var query = $@"select count(ds.""DietSlotId"") over() as ""TotalItems"", ds.""DietSlotId"", ds.""Name"", ds.""Active"", ds.""CreatedBy"", ds.""CreatedDate"",
ds.""StartTime""::text,ds.""EndTime""::text,ds.""ModifiedBy"", ds.""ModifiedDate"",
C.""FullName"" as ""CreatedByName"", CR.""RoleName"" as ""CreatedByRole"",M.""FullName"" as ""ModifiedByName"", MR.""RoleName"" as ""ModifiedByRole""
FROM ""DietSlots"" ds
join ""Account"" C on C.""AccountId"" = ds.""CreatedBy""
join ""Role"" CR on CR.""RoleId"" = C.""RoleId""
left join ""Account"" M on M.""AccountId"" = ds.""ModifiedBy""
left join ""Role"" MR on MR.""RoleId"" = M.""RoleId""
{where}
order by ds.""CreatedDate"" desc; ";
return this.unitOfWork.Current.QueryAsync<DietSlotsModel>(query);
}
public async Task<int> UpdateAsync(DietSlotsModel model)
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"select count(*) from ""DietSlots"" where lower (""Name"") = '{model.Name.ToLower()}' and ""DietSlotId"" <> {model.DietSlotId}");
if (checkIf > 0)
{
return -1;
}
var record = await this.unitOfWork.DietSlots.FindAsync(m => m.DietSlotId == model.DietSlotId);
if (record == null)
{
return -2;
}
record.ModifiedBy = model.CreatedBy;
record.ModifiedDate = DateTime.Now;
record.Name = model.Name;
record.Active = model.Active;
record.StartTime = TimeSpan.Parse(model.StartTime);
record.EndTime = TimeSpan.Parse(model.EndTime);
record.LocationId = (int)model.LocationId;
return await this.unitOfWork.DietSlots.UpdateAsync(record);
}
public async Task<int> ModifyStatusAsync(DietSlotsModel model)
{
var query = $@"UPDATE ""DietSlots"" SET ""ModifiedBy""={model.CreatedBy}, ""ModifiedDate""=now(), ""Active""= {model.Active}
WHERE ""DietSlotId""= {model.DietSlotId}";
return await this.unitOfWork.Current.ExecuteAsync(query);
}
}
}
namespace Hims.Infrastructure.Services
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;
using Domain.Entities;
using Domain.Repositories.UnitOfWork;
using Domain.Services;
using Shared.EntityModels;
using Shared.UserModels.Filters;
/// <inheritdoc />
public class DischargeInstructionService : IDischargeInstructionService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IRoleService" />
public DischargeInstructionService(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
/// <inheritdoc />
public Task<IEnumerable<DischargeModel>> FetchAsync(DischargeFilterModel model)
{
var where = " WHERE 1 = 1 ";
if (!string.IsNullOrEmpty(model.DischargeInstructionName))
{
where += $@" AND TRIM(UPPER(""DischargeInstructionName"")) = '{model.DischargeInstructionName.Trim().ToUpper()}'";
}
if (model.Active != null)
{
where += $@" AND ""Active"" IS {((bool)model.Active ? "TRUE" : "FALSE")}";
}
var query = $@"SELECT COUNT(*) OVER () AS ""TotalItems"", DI.""DischargeInstructionId"",DI.""DischargeInstructionName"",DI.""Active"",DI.""CreatedDate"",DI.""ModifiedDate""
, C.""FullName"" ""CreatedByName"",CR.""RoleName"" ""CreatedByRole"",
M.""FullName"" ""ModifiedByName"",MR.""RoleName"" ""ModifiedByRole""
FROM ""DischargeInstruction"" DI
JOIN ""Account"" C on C.""AccountId"" = DI.""CreatedBy""
JOIN ""Role"" CR on CR.""RoleId"" = C.""RoleId""
LEFT JOIN ""Account"" M on M.""AccountId"" = DI.""ModifiedBy""
LEFT JOIN ""Role"" MR on MR.""RoleId"" = M.""RoleId""
{where} Order by ""DischargeInstructionId"" DESC";
if (model.PageIndex <= 0)
{
return this.unitOfWork.Current.QueryAsync <DischargeModel>(query);
}
model.PageIndex -= 1;
query += " LIMIT " + model.PageSize + " offset " + (model.PageIndex * model.PageSize);
return this.unitOfWork.Current.QueryAsync<DischargeModel>(query);
}
/// <inheritdoc />
public async Task<int> AddAsync(DischargeModel model)
{
try
{
var checkIf = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>(
$@"SELECT COUNT(""DischargeInstructionId"") FROM ""DischargeInstruction"" WHERE TRIM(UPPER(""DischargeInstructionName"")) = '{model.DischargeInstructionName.ToUpper().Trim()}'");
if (checkIf > 0)
{
return -1;
}
var discharge = new DischargeInstruction
{
Active = true,
DischargeInstructionName = model.DischargeInstructionName,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
};
return await this.unitOfWork.DischargeInstructions.InsertAsync(discharge);
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
return 0;
}
/// <inheritdoc />
public async Task<int> UpdateAsync(DischargeModel model)
{
var checkIf = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"SELECT COUNT(""DischargeInstructionId"") FROM ""DischargeInstruction"" WHERE TRIM(UPPER(""DischargeInstructionName"")) = '{model.DischargeInstructionName.ToUpper().Trim()}' AND ""DischargeInstructionId"" <> {model.DischargeInstructionId}");
if (checkIf > 0)
{
return -1;
}
var discharge = await this.unitOfWork.DischargeInstructions.FindAsync(m => m.DischargeInstructionId == model.DischargeInstructionId);
discharge.DischargeInstructionName = model.DischargeInstructionName;
discharge.Active = true;
discharge.ModifiedBy = model.ModifiedBy;
discharge.ModifiedDate = DateTime.Now;
return await this.unitOfWork.DischargeInstructions.UpdateAsync(discharge);
}
/// <inheritdoc />
public Task<int> DeleteAsync(int dischargeInstructionId)
{
var query = $@"Update ""DischargeInstruction"" set ""Active"" = false WHERE ""DischargeInstructionsId""= {dischargeInstructionId}";
return this.unitOfWork.Current.ExecuteAsync(query);
}
/// <inheritdoc />
public async Task<int> ModifyStatusAsync(DischargeModel model)
{
var query = $@"UPDATE ""DischargeInstruction""
SET ""ModifiedBy""={model.CreatedBy}, ""ModifiedDate""=now(), ""Active""= {model.Active}
WHERE ""DischargeInstructionId""= {model.DischargeInstructionId}";
return await this.unitOfWork.Current.ExecuteAsync(query);
}
}
}
\ No newline at end of file
namespace Hims.Infrastructure.Services
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;
using Domain.Entities;
using Domain.Repositories.UnitOfWork;
using Domain.Services;
using Shared.EntityModels;
using Hims.Shared.UserModels.DiscountManagement;
using System.Linq;
/// <inheritdoc />
public class DiscountManagementServices : IDiscountManagementService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IDiscountManagementService" />
public DiscountManagementServices(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
/// <inheritdoc/>
public async Task<int> AddDiscountModule(DiscountModuleModel model)
{
var checkIfQuery = $@"Select count(*) FROM ""DiscountModule"" where lower(""ModuleName"") = '{model.ModuleName.ToLower()}'";
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>(checkIfQuery);
if (checkIf > 0)
{
return -1;
}
var module = new DiscountModule
{
Icon = model.Icon,
ModuleName = model.ModuleName,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
Roles = model.Roles
};
return await this.unitOfWork.DiscountModules.InsertAsync(module);
}
/// <inheritdoc/>
public async Task<int> UpdateDiscountModule(DiscountModuleModel model)
{
var findExisting = await this.unitOfWork.DiscountModules.FindAsync(m => m.DiscountModuleId == model.DiscountModuleId);
if (findExisting == null)
{
return 0;
}
findExisting.Icon = model.Icon;
findExisting.ModifiedBy = model.CreatedBy;
findExisting.ModifiedDate = DateTime.Now;
try
{
var role = model.Roles.Split(",");
var oldRoles = findExisting.Roles.Split(",");
var newRoles = role.Except(oldRoles).ToArray().Concat(oldRoles.Except(role).ToArray()).ToArray();
if (newRoles.Length > 0)
{
var query = $@"DELETE FROM ""DiscountsPerModule"" WHERE ""DiscountModuleId"" = {findExisting.DiscountModuleId} and ""RoleId"" in ({string.Join(",", newRoles.Select(m => m))})";
var res = await this.unitOfWork.Current.ExecuteAsync(query);
}
findExisting.Roles = model.Roles;
}
catch (Exception)
{
return -2;
}
return await this.unitOfWork.DiscountModules.UpdateAsync(findExisting);
}
/// <inheritdoc/>
public async Task<IEnumerable<DiscountModuleModel>> FetchAllDiscountModulesAsync(DiscountModuleModel model)
{
var query = $@"SELECT DM.""DiscountModuleId"", DM.""ModuleName"", DM.""Icon"", DM.""Roles"", DM.""CreatedBy"", DM.""CreatedDate"", DM.""Active"",
DM.""ModifiedBy"", DM.""ModifiedDate"",C.""FullName"" as ""CreatedByName"",CR.""RoleName"" as ""CreatedByRole"",
M.""FullName"" as ""ModifiedByName"",MR.""RoleName"" as ""ModifiedByRole""
FROM ""DiscountModule"" DM
join ""Account"" C on C.""AccountId"" = DM.""CreatedBy""
join ""Role"" CR on CR.""RoleId"" = C.""RoleId""
left join ""Account"" M on M.""AccountId"" = DM.""ModifiedBy""
left join ""Role"" MR on MR.""RoleId"" = M.""RoleId"" order by 1 desc";
var modules = (await this.unitOfWork.Current.QueryAsync<DiscountModuleModel>(query)).AsList();
if (modules.Count > 0)
{
foreach (var module in modules)
{
module.RoleDiscounts = new List<DiscountsPerModuleModel>();
var data = await this.unitOfWork.DiscountsPerModules.FindAllAsync(d => d.DiscountModuleId == module.DiscountModuleId);
var list = data?.ToList().Select(m => new DiscountsPerModuleModel
{
DiscountModuleId = m.DiscountModuleId,
AllowedPercentage = m.AllowedPercentage,
CreatedBy = m.CreatedBy,
DiscountsPerModuleId = m.DiscountsPerModuleId,
RoleId = m.RoleId
});
module.RoleDiscounts = list.ToList();
}
}
return modules;
}
/// <inheritdoc/>
public async Task<int> AddDiscountsPerModuleAsync(DiscountsPerModuleModel model)
{
var discounts = new DiscountsPerModule
{
AllowedPercentage = model.AllowedPercentage,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.UtcNow.AddMinutes(330),
DiscountModuleId = model.DiscountModuleId,
RoleId = model.RoleId
};
return await this.unitOfWork.DiscountsPerModules.InsertAsync(discounts);
}
/// <inheritdoc/>
public async Task<int> UpdateDiscountsPerModuleAsync(DiscountsPerModuleModel model)
{
var findExisting = await this.unitOfWork.DiscountsPerModules.FindAsync(d => d.DiscountsPerModuleId == model.DiscountsPerModuleId);
if (findExisting == null)
{
return 0;
}
findExisting.AllowedPercentage = model.AllowedPercentage;
findExisting.ModifiedBy = model.CreatedBy;
findExisting.ModifiedDate = DateTime.UtcNow.AddMinutes(330);
return await this.unitOfWork.DiscountsPerModules.UpdateAsync(findExisting);
}
/// <inheritdoc/>
public async Task<DiscountModuleModel> GetModuleDetailsAsync(string moduleName)
{
var query = $@"SELECT ""DiscountModuleId"", ""ModuleName"", ""Icon"" FROM ""DiscountModule"" where lower(""ModuleName"") = '{moduleName.ToLower()}'";
return await this.unitOfWork.Current.QueryFirstOrDefaultAsync<DiscountModuleModel>(query);
}
/// <inheritdoc/>
public async Task<DiscountsPerModuleModel> GetRoleBasedDisocuntOnModule(DiscountsPerModuleModel model)
{
var query = $@"SELECT ""DiscountsPerModuleId"", ""DiscountModuleId"", ""RoleId"", ""AllowedPercentage"" FROM ""DiscountsPerModule""
where ""DiscountModuleId"" = {model.DiscountModuleId} and ""RoleId"" = {model.RoleId}";
return await this.unitOfWork.Current.QueryFirstOrDefaultAsync<DiscountsPerModuleModel>(query);
}
/// <inheritdoc />
public async Task<int> ActivateOrDeactivate(DiscountModuleModel model)
{
var query = $@"UPDATE ""DiscountModule"" SET ""ModifiedBy""={model.ModifiedBy}, ""ModifiedDate""=now(), ""Active""= {(bool)model.Active}
WHERE ""DiscountModuleId""= {model.DiscountModuleId}";
return await this.unitOfWork.Current.ExecuteAsync(query);
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Text;
using Dapper;
using System.Threading.Tasks;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Services;
using Hims.Shared.UserModels;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Entities;
namespace Hims.Infrastructure.Services
{
public class DoctorAppointmentNoticeService : IDoctorAppointmentNoticeService
{
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IDoctorAppointmentNoticeService" />
public DoctorAppointmentNoticeService(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
public async Task<int> DeleteAsync(int doctorAppointmentNoticeId)
{
var query = $@"DELETE FROM ""DoctorAppointmentNotice"" WHERE ""DoctorAppointmentNoticeId""= {doctorAppointmentNoticeId}";
return await this.unitOfWork.Current.ExecuteAsync(query);
}
/// <inheritdoc />
public async Task<int> ModifyStatusAsync(DoctorAppointmentNoticeModel model)
{
var query = $@"UPDATE ""DoctorAppointmentNotice""
SET ""ModifiedBy""={model.CreatedBy}, ""ModifiedDate""=now(), ""Active""= {model.Active}
WHERE ""DoctorAppointmentNoticeId""= {model.DoctorAppointmentNoticeId}";
return await this.unitOfWork.Current.ExecuteAsync(query);
}
public async Task<IEnumerable<DoctorAppointmentNoticeModel>> FetchAsync(DoctorAppointmentNoticeModel model)
{
var where = " WHERE 1 = 1 ";
//if (model.Active != null)
//{
// where += $@" AND Da.""Active"" IS {((bool)model.Active ? "TRUE" : "FALSE")}";
//}
if (model.CreatedBy != null)
{
where += $@" AND Da.""CreatedBy"" = {model.CreatedBy}";
}
if (!string.IsNullOrEmpty(model.FromDate) && (!string.IsNullOrEmpty(model.ToDate)))
{
where += $@" And (Da.""FromDate""::Date between '{model.FromDate}'::DATE and '{model.ToDate}'::DATE
or Da.""ToDate""::Date between '{model.FromDate}'::DATE and '{model.ToDate}'::DATE
or Da.""FromDate""::Date between '{model.FromDate}'::DATE and '{model.ToDate}'::DATE
or '{model.FromDate}'::DATE >= Da.""FromDate""::Date and '{model.ToDate}'::DATE <= Da.""ToDate""::Date)";
}
if (model.LocationId > 0)
{
where += $@" and Da.""LocationId"" ={model.LocationId} ";
}
if (model.ProviderId > 0)
{
where += $@" and Pr.""ProviderId"" ={model.ProviderId} ";
}
var query = $@"SELECT COUNT(*) OVER () AS ""TotalItems"", Da.*, Pr.""FullName"" ""ProviderName"", L.""Name"" ""LocationName"",CA.""FullName"" AS ""CreatedByName"" , MA.""FullName"" AS ""ModifiedByName""
FROM ""DoctorAppointmentNotice"" Da
LEFT JOIN ""Provider"" Pr ON Pr.""ProviderId"" = Da.""ProviderId""
LEFT JOIN ""Location"" L ON L.""LocationId"" = Da.""LocationId""
LEFT JOIN ""Account"" CA ON CA.""AccountId"" = Da.""CreatedBy""
LEFT JOIN ""Account"" MA ON MA.""AccountId"" = Da.""ModifiedBy""
{where} Order by Da.""DoctorAppointmentNoticeId"" DESC";
if (model.PageIndex <= 0 || model.PageIndex == null)
{
return await this.unitOfWork.Current.QueryAsync<DoctorAppointmentNoticeModel>(query);
}
model.PageIndex -= 1;
query += " LIMIT " + model.PageSize + " offset " + (model.PageIndex * model.PageSize);
return await this.unitOfWork.Current.QueryAsync<DoctorAppointmentNoticeModel>(query);
}
public async Task<int> InsertAsync(DoctorAppointmentNoticeModel model)
{
//var checkIf = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"SELECT COUNT(""DoctorAppointmentNoticeId"") FROM ""DoctorAppointmentNotice"" WHERE TRIM(UPPER(""ChargeName"")) = '{model.ChargeName.ToUpper().Trim()}'");
var checkIf = await this.unitOfWork.DoctorAppointmentNotices.FindAllAsync(m => m.ProviderId == model.ProviderId && m.LocationId == model.LocationId
&& m.FromDate >= Convert.ToDateTime(model.FromDate) && m.ToDate <= Convert.ToDateTime(model.ToDate));
if (checkIf.AsList().Count > 0)
{
return -1;
}
var doctorAppointmentNotice = new DoctorAppointmentNotice
{
Description = model.Description,
LocationId = model.LocationId,
ProviderId = (int)model.ProviderId,
FromDate = Convert.ToDateTime(model.FromDate),
ToDate = Convert.ToDateTime(model.ToDate),
Active = true,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
};
return await this.unitOfWork.DoctorAppointmentNotices.InsertAsync(doctorAppointmentNotice);
}
public async Task<int> UpdateAsync(DoctorAppointmentNoticeModel model)
{
var checkIf = await this.unitOfWork.DoctorAppointmentNotices.FindAllAsync(m => m.ProviderId == model.ProviderId && m.DoctorAppointmentNoticeId != model.DoctorAppointmentNoticeId && m.LocationId == model.LocationId
&& m.FromDate >= Convert.ToDateTime(model.FromDate) && m.ToDate <= Convert.ToDateTime(model.ToDate));
if (checkIf.AsList().Count > 0)
{
return -1;
}
var doctorAppointmentNotices = await this.unitOfWork.DoctorAppointmentNotices.FindAsync(m => m.DoctorAppointmentNoticeId == model.DoctorAppointmentNoticeId);
doctorAppointmentNotices.Description = model.Description;
doctorAppointmentNotices.ProviderId = (int)model.ProviderId;
doctorAppointmentNotices.LocationId = model.LocationId;
doctorAppointmentNotices.FromDate = Convert.ToDateTime(model.FromDate);
doctorAppointmentNotices.ToDate = Convert.ToDateTime(model.ToDate);
doctorAppointmentNotices.Active = true;
doctorAppointmentNotices.ModifiedBy = model.ModifiedBy;
doctorAppointmentNotices.ModifiedDate = DateTime.Now;
return await this.unitOfWork.DoctorAppointmentNotices.UpdateAsync(doctorAppointmentNotices);
}
}
}
namespace Hims.Infrastructure.Services
{
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;
using Domain.Entities;
using Domain.Repositories.UnitOfWork;
using Domain.Services;
using Shared.EntityModels;
/// <inheritdoc />
public class DoctorDeviceDetailsServices : IDoctorDeviceDetailsService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <summary>
/// Initializes a new instance of the <see cref="DoctorDeviceDetailsServices"/> class.
/// </summary>
/// <param name="unitOfWork">
/// The unit of work.
/// </param>
public DoctorDeviceDetailsServices(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
/// <inheritdoc />
public async Task<IEnumerable<DoctorDeviceDetailsModel>> FetchAsync(int appointmentId)
{
var where = $@"WHERE 1 = 1";
if (appointmentId > 0)
{
where = $@"WHERE a.""AppointmentId"" = {appointmentId}";
}
var query = $@"SELECT
v.*,
a.""AppointmentDate"",
a.""AppointmentTime"",
p.""FullName"" AS ""DoctorFullName"",
pa.""FullName"" AS ""PatientFullName""
FROM
""VideoCallHistory"" v
LEFT JOIN ""Appointment"" A ON A.""AppointmentId"" = v.""AppointmentId""
LEFT JOIN ""Provider"" P ON P.""ProviderId"" = A.""ProviderId""
LEFT JOIN ""Patient"" pa ON pa.""PatientId"" = A.""PatientId""
{where} ORDER BY v.""VideoCallHistoryId"" desc LIMIT 10";
var records = await this.unitOfWork.Current.QueryAsync<DoctorDeviceDetailsModel>(query);
return records;
}
/// <inheritdoc />
public Task<int> InsertAsync(DoctorDeviceDetailsModel model)
{
var doctorDeviceDetails = new DoctorDeviceDetails
{
AppointmentId = model.AppointmentId ?? 0,
Duration = model.Duration,
Reason = model.Reason,
CallEndedAt = model.CallEndedAt,
CallLiftedAt = model.CallLiftedAt,
CallStartedAt = model.CallStartedAt,
CallerId = model.CallerId,
IsWebcamOn = model.IsWebcamOn ?? false,
IsMicOn = model.IsMicOn ?? false,
RingedAt = model.RingedAt,
Status = model.Status
};
return this.unitOfWork.DoctorDeviceDetails.InsertAsync(doctorDeviceDetails);
}
}
}
\ No newline at end of file

namespace Hims.Infrastructure.Services
{
using Dapper;
using Domain.Services;
using Hims.Domain.Configurations;
using Hims.Domain.Entities;
using Hims.Domain.Helpers;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Shared.UserModels;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
internal class DoctorUnitService : IDoctorUnitService
{
/// <summary>
/// the unit of work
/// </summary>
private readonly IUnitOfWork unitOfWork;
public DoctorUnitService(IUnitOfWork unitOfWork)
{
this.unitOfWork = unitOfWork;
}
public async Task<int> ActivateOrDeactivateTest(DoctorUnitMasterModel model)
{
var query = $@"UPDATE ""DoctorUnitMaster""
SET ""ModifiedBy""={model.ModifiedBy}, ""ModifiedDate""=now(), ""Active""= {model.Active}
WHERE ""DoctorUnitMasterId""= {model.DoctorUnitMasterId}";
return await this.unitOfWork.Current.ExecuteAsync(query);
}
public async Task<IEnumerable<DoctorUnitMasterModel>> FetchAllAsync(DoctorUnitMasterModel model)
{
var where = "where 1=1";
if (model.Active != null)
{
where += (bool)model.Active ? $@" and DM.""Active"" is true " : $@" and DM.""Active"" is false ";
}
if (model.LocationId != null)
{
where += $@" and DM.""LocationId"" = {model.LocationId}";
}
if (!string.IsNullOrEmpty(model.UnitName))
{
where += $@" and DM.""UnitName"" ilike '%{model.UnitName}%' ";
}
if (!string.IsNullOrEmpty(model.Code))
{
where += $@" and DM.""Code"" ilike '%{model.Code}%' ";
}
if (!string.IsNullOrEmpty(model.Term))
{
where += $@" and DM.""UnitName"" ilike '%{model.Term}%' or DM.""Code"" ilike '%{model.Term}%'";
}
if (model.DoctorUnitMasterId != null)
{
where += $@" and DM.""DoctorUnitMasterId"" = {model.DoctorUnitMasterId} ";
}
var query = $@"select COUNT(*) OVER () AS ""TotalItems"", DM.""DoctorUnitMasterId"", DM.""UnitName"", DM.""Code"", DM.""CreatedDate"", DM.""ModifiedDate"", L.""Name"" as ""Location"",L.""LocationId"",
AC.""FullName"" as ""CreatedByName"", AN.""FullName"" as ""ModifiedByName"", DM.""Active""
from ""DoctorUnitMaster"" DM
left join ""Location"" L ON L.""LocationId""=DM.""LocationId""
left join ""Account"" AC ON AC.""AccountId""=DM.""CreatedBy""
left join ""Account"" AN ON AN.""AccountId""=DM.""ModifiedBy"" {where} order by DM.""CreatedDate"" DESC";
if (model.PageIndex != null && model.PageSize != null)
{
model.PageIndex = model.PageIndex > 0 ? model.PageIndex - 1 : model.PageIndex;
query += $@" limit {model.PageSize} offset {model.PageIndex * model.PageSize}";
}
var records= await this.unitOfWork.Current.QueryAsync<DoctorUnitMasterModel>(query);
foreach (var item in records)
{
var subQuery = $@"SELECT TD.""TagDoctorId"",TD.""ProviderId"",TD.""Designation"",TD.""DoctorUnitMasterId"", Pr.""FullName"" as ""ProviderName""
FROM ""TagDoctor"" TD
JOIN ""Provider"" Pr ON Pr.""ProviderId""=TD.""ProviderId""
where ""DoctorUnitMasterId"" = {item.DoctorUnitMasterId} order by 1 asc";
item.TagDoctor = (await this.unitOfWork.Current.QueryAsync<TagDoctorModel>(subQuery)).ToList();
}
return records;
}
public async Task<int> InsertAsync(DoctorUnitMasterModel model)
{
using (var transaction = this.unitOfWork.BeginTransaction())
{
var check = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"select count (""DoctorUnitMasterId"") from ""DoctorUnitMaster"" where ""UnitName""='{model.UnitName}'");
if (check > 0)
{
return -1;
}
var doctorUnitMaster = new DoctorUnitMaster
{
UnitName = model.UnitName,
Code = model.Code,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
LocationId = model.LocationId,
Active = model.Active,
};
doctorUnitMaster.DoctorUnitMasterId = await this.unitOfWork.DoctorUnitMatser.InsertAsync(doctorUnitMaster, transaction);
if (doctorUnitMaster.DoctorUnitMasterId == 0)
{
transaction.Rollback();
return 0;
}
var count = 0;
foreach (TagDoctorModel eachTagDoctor in model.TagDoctor)
{
var tagDotctor = new TagDoctor
{
ProviderId = eachTagDoctor.ProviderId,
Designation = eachTagDoctor.Designation,
DoctorUnitMasterId = doctorUnitMaster.DoctorUnitMasterId,
};
var response = await this.unitOfWork.TagDoctor.InsertAsync(tagDotctor, transaction);
if (response != 0)
{
count++;
}
}
if (count != model.TagDoctor.Count)
{
transaction.Rollback();
return 0;
}
transaction.Commit();
return doctorUnitMaster.DoctorUnitMasterId;
}
}
public async Task<int> UpdateAsync(DoctorUnitMasterModel model)
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"select count(*) from ""DoctorUnitMaster"" where lower (""UnitName"") = '{model.UnitName.ToLower()}' and ""DoctorUnitMasterId"" <> {model.DoctorUnitMasterId}");
if (checkIf > 0)
{
return -1;
}
var record = await this.unitOfWork.DoctorUnitMatser.FindAsync(m => m.DoctorUnitMasterId == model.DoctorUnitMasterId);
if (record == null)
{
return -2;
}
record.ModifiedBy = model.CreatedBy;
record.ModifiedDate = DateTime.Now;
record.UnitName = model.UnitName;
record.Code = model.Code;
//record.DepartmentId = model.DepartmentId;
record.LocationId = model.LocationId;
var num= await this.unitOfWork.DoctorUnitMatser.UpdateAsync(record);
foreach (TagDoctorModel eachTagDoctor in model.TagDoctor)
{
var tagDotctor = new TagDoctor
{
ProviderId = eachTagDoctor.ProviderId,
Designation = eachTagDoctor.Designation,
DoctorUnitMasterId = record.DoctorUnitMasterId,
};
if (eachTagDoctor.TagDoctorId != 0)
{
var response = await this.unitOfWork.TagDoctor.UpdateAsync(tagDotctor);
}
else
{
var response = await this.unitOfWork.TagDoctor.InsertAsync(tagDotctor);
}
}
return num;
}
}
}
using Dapper;
using Hims.Domain.Entities;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Services;
using Hims.Shared.EntityModels;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Hims.Infrastructure.Services
{
public class DriverDetailService : IDriverDetailService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IDriverDetailService" />
public DriverDetailService(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
public async Task<int> InsertAsync(DriverDetailModel model)
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"select count(*) from ""DriverDetail"" where lower(""DriverDetailName"") = '{model.DriverDetailName.ToLower()}'");
if (checkIf > 0)
{
return -1;
}
var driverDetail = new DriverDetail
{
DriverDetailName = model.DriverDetailName,
MobileNo = model.MobileNo,
AadharNo = model.AadharNo,
Active = true,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
FromTime=model.FromTime,
ToTime=model.ToTime,
Address=model.Address
};
return await this.unitOfWork.DriverDetail.InsertAsync(driverDetail);
}
/// <inheritdoc/>
public async Task<int> UpdateAsync(DriverDetailModel model)
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"select count(*) from ""DriverDetail"" where lower (""DriverDetailName"") = '{model.DriverDetailName.ToLower()}' and ""DriverDetailId"" <> {model.DriverDetailId}");
if (checkIf > 0)
{
return -1;
}
var record = await this.unitOfWork.DriverDetail.FindAsync(m => m.DriverDetailId == model.DriverDetailId);
if (record == null)
{
return -2;
}
record.DriverDetailName = model.DriverDetailName;
record.MobileNo = model.MobileNo;
record.AadharNo = model.AadharNo;
record.Active = true;
record.ModifiedBy = model.CreatedBy;
record.ModifiedDate = DateTime.Now;
record.FromTime = model.FromTime;
record.ToTime = model.ToTime;
record.Address = model.Address;
return await this.unitOfWork.DriverDetail.UpdateAsync(record);
}
public async Task<IEnumerable<DriverDetailModel>> FetchAllAsync(DriverDetailModel model)
{
var where = "where 1=1";
if (model.DriverDetailId > 0)
{
where += $@" and cs.""DriverDetailId"" = {model.DriverDetailId} ";
}
var query = $@"select count(dd.""DriverDetailId"") over() as ""TotalItems"",dd.*,
C.""FullName"" as ""CreatedByName"", CR.""RoleName"" as ""CreatedByRole"",M.""FullName"" as ""ModifiedByName"", MR.""RoleName"" as ""ModifiedByRole""
FROM ""DriverDetail"" dd
join ""Account"" C on C.""AccountId"" = dd.""CreatedBy""
join ""Role"" CR on CR.""RoleId"" = C.""RoleId""
left join ""Account"" M on M.""AccountId"" = dd.""ModifiedBy""
left join ""Role"" MR on MR.""RoleId"" = M.""RoleId""
{where}
order by dd.""CreatedDate"" desc";
return await this.unitOfWork.Current.QueryAsync<DriverDetailModel>(query);
}
//public Task<int> DeleteAsync(int driverDetailId)
//{
// var query = $@"DELETE FROM ""DriverDetail"" WHERE ""DriverDetailId""= {driverDetailId}";
// return this.unitOfWork.Current.ExecuteAsync(query);
//}
public Task<int> ModifyStatusAsync(int driverDetailId, int modifiedBy, bool status)
{
var query = $@"UPDATE ""DriverDetail"" SET ""Active"" = {!status}, ""ModifiedBy"" = {modifiedBy}, ""ModifiedDate"" = NOW() AT TIME ZONE 'UTC' WHERE ""DriverDetailId""= {driverDetailId}";
return this.unitOfWork.Current.ExecuteAsync(query);
}
}
}
namespace Hims.Infrastructure.Services
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Domain.Entities;
using Domain.Repositories.UnitOfWork;
using Domain.Services;
using Hims.Shared.UserModels.Common;
using Hims.Shared.UserModels.DynamicDashboard;
using Hims.Shared.UserModels.DynamicDashboard.Config;
using Shared.EntityModels;
/// <inheritdoc />
public class DynamicDashboardService : IDynamicDashboardService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IDynamicDashboardService" />
public DynamicDashboardService(IUnitOfWork unitOfWork)
{
this.unitOfWork = unitOfWork;
}
/// <inheritdoc />
public async Task<IEnumerable<DashboardConfigModel>> FetchAsync(FetchFilterModel model)
{
try
{
var checkQuery = $@"SELECT COUNT(""DashboardConfigId"") FROM ""DashboardConfig"" c
JOIN ""DashboardConfigMaster"" m on m.""DashboardConfigMasterId"" = c.""DashboardConfigMasterId""
WHERE m.""AccountId"" = {model.AccountId} ";
var count = model.AccountId > 0
? await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>(checkQuery)
: 0;
var where = count > 0
? $@" mm.""AccountId"" = {model.AccountId ?? 0} "
: $@" mm.""RoleId"" = {model.RoleId ?? 0} ";
var query = $@"SELECT
d.""DashboardConfigId"",
mm.""DashboardConfigMasterId"",
d.""DashboardWidgetId"",
dw.""DashboardWidgetTypeId"",
dw.""Icon"",
dw.""DashboardWidgetCountTypeId"",
dw.""Name"" ""WidgetName"",
dwc.""Name"" ""CountTypeName"",
dw.""StoredProcedureName"",
d.""RowNumber"",
d.""Size"",
d.""SequenceNumber"",
d.""CreatedBy"",
a.""FullName"" ""CreatedByName"",
m.""FullName"" ""ModifiedByName"",
d.""CreatedDate"",
d.""ModifiedDate"",
d.""DefaultValues""
FROM
""DashboardConfigMaster"" mm
JOIN ""DashboardConfig"" d on d.""DashboardConfigMasterId"" = mm.""DashboardConfigMasterId""
JOIN ""DashboardWidget"" dw on dw.""DashboardWidgetId"" = d.""DashboardWidgetId""
JOIN ""DashboardWidgetCountType"" dwc on dwc.""DashboardWidgetCountTypeId"" = dw.""DashboardWidgetCountTypeId""
JOIN ""Account"" a on a.""AccountId"" = d.""CreatedBy""
LEFT JOIN ""Account"" m on m.""AccountId"" = d.""ModifiedBy""
where {where}
order by d.""DashboardConfigId"" desc";
var result = await this.unitOfWork.Current.QueryAsync<DashboardConfigModel>(query);
if (result.Any() && count == 0)
{
result.First().IsRoleDashboard = true;
}
return result;
}
catch (Exception ex)
{
return null;
}
}
/// <inheritdoc />
public async Task<GenericResponse> InsertAsync(InsertModel model)
{
var transaction = this.unitOfWork.BeginTransaction();
var configMaster = new DashboardConfigMaster
{
RoleId = model.RoleId,
AccountId = model.AccountId
};
var existingMaster = await this.unitOfWork.DashboardConfigMaster.FindAsync(x => x.RoleId == model.RoleId && x.AccountId == model.AccountId);
if (existingMaster != null && model.DashboardConfigMasterId == null)
{
model.DashboardConfigMasterId = existingMaster.DashboardConfigMasterId;
};
var configMasterId = model.DashboardConfigMasterId != null
? model.DashboardConfigMasterId
: await this.unitOfWork.DashboardConfigMaster.InsertAsync(configMaster, transaction);
var configs = model.Rows.Select(x => new DashboardConfig
{
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
DashboardWidgetId = x.DashboardWidgetId,
RowNumber = x.RowNumber,
Size = x.Size,
SequenceNumber = x.SequenceNumber,
DashboardConfigMasterId = configMasterId ?? 0,
DefaultValues = x.DefaultValues
});
var result = 0;
foreach (var config in configs)
{
var existingCount = await this.unitOfWork.DashboardConfig.CountAsync(x => x.DashboardWidgetId == config.DashboardWidgetId && x.DashboardConfigMasterId == config.DashboardConfigMasterId);
if (existingCount <= 0)
{
result = await this.unitOfWork.DashboardConfig.InsertAsync(config, transaction);
if (result <= 0)
{
transaction.Rollback();
result = -1;
break;
}
}
}
if (result > 0)
{
transaction.Commit();
}
return new GenericResponse
{
Status = result >= 0
? GenericStatus.Success
: GenericStatus.Error
};
}
//public async Task<int> UpdateAsync(DashboardConfigModel model)
//{
// var transaction = this.unitOfWork.BeginTransaction();
// var query = $@"SELECT ""DashboardConfigId"" from ""DashboardConfig"" WHERE ""DashboardConfigId"" = {model.DashboardConfigId}";
// var isExists = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>(query, transaction);
// var result = 0;
// if (isExists > 0)
// {
// var config = await this.unitOfWork.DashboardConfig.FindAsync(x => x.DashboardConfigId == model.DashboardConfigId, transaction);
// config.ModifiedBy = model.ModifiedBy;
// config.ModifiedDate = DateTime.Now;
// config.DashboardWidgetId = model.DashboardWidgetId;
// config.RowNumber = model.RowNumber;
// config.Size = model.Size;
// config.SequenceNumber = model.SequenceNumber;
// result = await this.unitOfWork.DashboardConfig.UpdateAsync(config, transaction);
// }
// if (result <= 0)
// {
// transaction.Rollback();
// return -1;
// }
// transaction.Commit();
// return result;
//}
/// <inheritdoc />
public async Task<bool> DeleteAsync(int id)
{
return await this.unitOfWork.DashboardConfig.DeleteAsync(x => x.DashboardConfigId == id);
}
}
}
\ No newline at end of file
using Hims.Shared.UserModels.Common;
namespace Hims.Infrastructure.Services
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;
using Domain.Entities;
using Domain.Repositories.UnitOfWork;
using Domain.Services;
//using Hims.Shared.UserModels.Common;
using Shared.EntityModels;
using Shared.UserModels.Filters;
/// <inheritdoc />
public class DynamicReportServices : IDynamicReportService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <summary>
/// Initializes a new instance of the <see cref="DynamicReportServices"/> class.
/// </summary>
/// <param name="unitOfWork">
/// The unit of work.
/// </param>
public DynamicReportServices(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
/// <inheritdoc/>
//public async Task<IEnumerable<object>> ExecuteQueryAsync(DynamicReportModel model)
//{
// return await this.unitOfWork.Current.QueryAsync<object>(model.Query);
//}
/// <inheritdoc/>
public async Task<int> InsertAsync(DynamicReportModel model)
{
var query = $@"SELECT ""DynamicReportId"" from ""DynamicReport"" WHERE lower(""Name"") = '{model.Name.ToLower()}' AND ""Active"" IS TRUE";
var isExists = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>(query);
if (isExists > 0)
{
return -2;
}
var record = new DynamicReport
{
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
Active = true,
Name = model.Name,
Data = model.Data
};
var result = await this.unitOfWork.DynamicReports.InsertAsync(record);
if (result <= 0)
{
return -1;
}
return result;
}
/// <inheritdoc/>
public Task<IEnumerable<DynamicReportModel>> FetchAsync(DynamicReportFilterModel model)
{
try
{
var query = $@"SELECT COUNT(D.""DynamicReportId"") OVER() ""TotalItems"", D.""DynamicReportId"",
D.""Name"", D.""Data"", D.""Active"", D.""CreatedBy"", D.""ModifiedBy"",
A.""FullName"" ""CreatedByName"", AA.""FullName"" ""ModifiedByName""
FROM
""DynamicReport"" D
left join ""Account"" A on A.""AccountId"" = D.""CreatedBy""
left join ""Account"" AA on AA.""AccountId"" = D.""ModifiedBy""
order by D.""DynamicReportId"" desc ";
model.PageIndex -= 1;
query += " LIMIT " + model.PageSize + " offset " + (model.PageIndex * model.PageSize);
var result = this.unitOfWork.Current.QueryAsync<DynamicReportModel>(query);
return result;
}
catch (Exception ex)
{
return null;
}
}
/// <inheritdoc />
public async Task<int> DeactivateAsync(int? id, int? modifiedBy)
{
var record = await this.unitOfWork.DynamicReports.FindAsync(x => x.DynamicReportId == id);
if (record == null)
{
return -1;
}
record.ModifiedBy = modifiedBy;
record.ModifiedDate = DateTime.Now;
record.Active = false;
return await this.unitOfWork.DynamicReports.UpdateAsync(record);
}
//<inheritdoc/>
public async Task<int> UpdateAsync(DynamicReportModel model)
{
var query = $@"SELECT ""DynamicReportId"" from ""DynamicReport"" WHERE lower(""Name"") = '{model.Name.ToLower()}' AND ""DynamicReportId""!={model.DynamicReportId} AND ""Active"" IS TRUE";
var isExists = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>(query);
if (isExists > 0)
{
return -2;
}
var record = await this.unitOfWork.DynamicReports.FindAsync(x => x.DynamicReportId == model.DynamicReportId);
if (record == null)
{
return -1;
}
record.Name = model.Name;
record.Data = model.Data;
record.ModifiedBy = model.ModifiedBy;
record.ModifiedDate = DateTime.Now;
return await this.unitOfWork.DynamicReports.UpdateAsync(record);
}
/// <inheritdoc />
public Task<IEnumerable<DynamicReportModel>> GetReportMenuAsync()
{
try
{
var query = $@"SELECT COUNT(D.""DynamicReportId"") OVER() ""TotalItems"", D.""DynamicReportId"",
D.""Name"", D.""Data"", D.""Active"", D.""CreatedBy"", D.""ModifiedBy"",
A.""FullName"" ""CreatedByName"", AA.""FullName"" ""ModifiedByName""
FROM
""DynamicReport"" D
left join ""Account"" A on A.""AccountId"" = D.""CreatedBy""
left join ""Account"" AA on AA.""AccountId"" = D.""ModifiedBy""
where D.""Status""='Verified' and D.""Active"" is true
order by D.""DynamicReportId"" desc ";
return this.unitOfWork.Current.QueryAsync<DynamicReportModel>(query);
}
catch (Exception ex)
{
return null;
}
}
public async Task<IEnumerable<FetchModuleTemplatesModel>> FetchModuleTemplatesAsync()
{
var query = $@"SELECT ""LabTemplateHeaderId"",""TemplateName"", ""TemplateId"" FROM ""LabTemplateHeader"" WHERE ""Active""=true order by ""CreatedDate"" desc";
return await this.unitOfWork.Current.QueryAsync<FetchModuleTemplatesModel>(query);
}
public Task<DynamicReportModel> FetchReportAsync(int reportId)
{
try
{
var query = $@"SELECT ""DynamicReportId"",""Name"",""Data"" FROM ""DynamicReport"" where ""DynamicReportId"" ={reportId}";
var result = this.unitOfWork.Current.QueryFirstOrDefaultAsync<DynamicReportModel>(query);
return result;
}
catch (Exception ex)
{
return null;
}
}
public async Task<int> InsertImages(DynamicReportImagesModel model)
{
var record = new DynamicReportImages
{
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
Guid = Guid.NewGuid()
};
return await this.unitOfWork.DynamicReportImages.InsertAsync(record); ;
}
public Task<int> UpdateImages(string path, int id)
{
var query = $@"update ""DynamicReportImages"" set ""ImagePath""='{path}' where ""DynamicReportImagesId""={id}";
return this.unitOfWork.Current.ExecuteAsync(query);
}
public async Task<IEnumerable<DynamicReportImagesModel>> FetchImagePath()
{
var query = $@"select ""ImagePath"" from ""DynamicReportImages"" where ""ImagePath"" is not null";
var result = await this.unitOfWork.Current.QueryAsync<DynamicReportImagesModel>(query);
return result;
}
}
}
\ No newline at end of file

namespace Hims.Infrastructure.Services
{
using Dapper;
using Hims.Domain.Entities;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Services;
using Hims.Shared.Library;
using Hims.Shared.UserModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
public class DynamicTemplateConfigService : IDynamicTemplateConfigService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IIdProofService" />
public DynamicTemplateConfigService(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
public async Task<int> ActivateOrDeactivateTest(DynamicTemplateConfigModel model)
{
var query = $@"UPDATE ""DynamicTemplateConfig""
SET ""ModifiedBy""={model.CreatedBy}, ""ModifiedDate""=now(), ""Active""= {model.Active}
WHERE ""DynamicTemplateConfigId""= {model.DynamicTemplateConfigId}";
return await this.unitOfWork.Current.ExecuteAsync(query);
}
public async Task<IEnumerable<DynamicTemplateConfigModel>> FetchAllAsync(DynamicTemplateConfigModel model)
{
var query = $@"select count(ID.""DynamicTemplateConfigId"") over() as ""TotalItems"", ID.""DynamicTemplateConfigId"", ID.""ReportName"", ID.""Active"", ID.""CreatedBy"", ID.""CreatedDate"",
ID.""ModifiedBy"", ID.""ModifiedDate"", DR.""Name"" as ""TemplateName"", DR.""DynamicReportId"",
C.""FullName"" as ""CreatedByName"", CR.""RoleName"" as ""CreatedByRole"",M.""FullName"" as ""ModifiedByName"", MR.""RoleName"" as ""ModifiedByRole""
FROM ""DynamicTemplateConfig"" ID
join ""DynamicReport"" DR on DR.""DynamicReportId""=ID.""DynamicReportId""
join ""Account"" C on C.""AccountId"" = ID.""CreatedBy""
join ""Role"" CR on CR.""RoleId"" = C.""RoleId""
left join ""Account"" M on M.""AccountId"" = ID.""ModifiedBy""
left join ""Role"" MR on MR.""RoleId"" = M.""RoleId""
order by ID.""CreatedDate"" desc";
return await this.unitOfWork.Current.QueryAsync<DynamicTemplateConfigModel>(query);
}
public async Task<IEnumerable<Resource>> FetchDynamicTemplate()
{
var query = $@"select ""DynamicReportId"" as ""Id"", ""Name"" from ""DynamicReport"" ";
return await this.unitOfWork.Current.QueryAsync<Resource>(query);
}
public async Task<IEnumerable<Resource>> FetchTemplateConfigs(GetTemplateConfigs model)
{
var names = string.Join(",", model.ReportNames.Select(x => "'" + x + "'"));
var query = $@"select ""DynamicReportId"" as ""Id"", ""Name"" from ""DynamicReport"" WHERE ""Name"" IN({names}) ";
return await this.unitOfWork.Current.QueryAsync<Resource>(query);
}
public async Task<int> InsertAsync(DynamicTemplateConfigModel model)
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"select count(*) from ""DynamicTemplateConfig"" where lower(""ReportName"") = '{model.ReportName.ToLower()}'");
if (checkIf > 0)
{
return -1;
}
var dynamicTemplate = new DynamicTemplateConfig
{
ReportName = model.ReportName,
DynamicReportId = model.DynamicReportId,
CreatedBy = model.CreatedBy,
Active = true,
CreatedDate = DateTime.Now,
};
return await this.unitOfWork.DynamicTemplateConfig.InsertAsync(dynamicTemplate);
}
public async Task<int> UpdateAsync(DynamicTemplateConfigModel model)
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"select count(*) from ""DynamicTemplateConfig"" where lower (""ReportName"") = '{model.ReportName.ToLower()}' and ""DynamicTemplateConfigId"" <> {model.DynamicTemplateConfigId}");
if (checkIf > 0)
{
return -1;
}
var record = await this.unitOfWork.DynamicTemplateConfig.FindAsync(m => m.DynamicTemplateConfigId == model.DynamicTemplateConfigId);
if (record == null)
{
return -2;
}
record.ModifiedBy = model.CreatedBy;
record.ModifiedDate = DateTime.Now;
record.ReportName = model.ReportName;
record.DynamicReportId = model.DynamicReportId;
return await this.unitOfWork.DynamicTemplateConfig.UpdateAsync(record);
}
}
}
namespace Hims.Infrastructure.Services
{
using Dapper;
using Hims.Domain.Entities;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Services;
using Hims.Shared.UserModels;
using Hims.Shared.UserModels.DynamicTemplate;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
public class DynamicTemplateService : IDynamicTemplateService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
public DynamicTemplateService(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
public async Task<int> DeleteAsync(InsertModel model)
{
var query = $@"Delete from ""DynamicTemplate"" where ""DynamicTemplateId"" = {model.DynamicTemplateId}";
return await this.unitOfWork.Current.ExecuteAsync(query);
}
public async Task<IEnumerable<FetchModel>> FetchAsync(FetchModel model)
{
var query = $@"Select dt.""DynamicTemplateId"",dt.""TemplateName"",dt.""Value"",dt.""CreatedDate"",dt.""ModifiedDate"",ac.""FullName"" as ""CreatedByName"",cc.""FullName"" as ""ModifiedByName"" from ""DynamicTemplate"" dt
left join ""Account"" ac on ac.""AccountId"" = dt.""CreatedBy""
left join ""Account"" cc on cc.""AccountId"" = dt.""ModifiedBy""";
return await this.unitOfWork.Current.QueryAsync<FetchModel>(query);
}
public async Task<int> InsertAsync(InsertModel model)
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"Select count(*) from ""DynamicTemplate"" where lower(""TemplateName"") = '{model.TemplateName.ToLower()}'");
if (checkIf > 0)
{
return -1;
}
var dynamicTemplate = new DynamicTemplate
{
TemplateName = model.TemplateName,
Value = model.Value,
Active = true,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now
};
return await this.unitOfWork.DynamicTemplates.InsertAsync(dynamicTemplate);
}
public async Task<int> UpdateAsync(InsertModel model)
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>($@"Select count(*) from ""DynamicTemplate"" where ""TemplateName"" ='{model.TemplateName}' and ""DynamicTemplateId"" <> {model.DynamicTemplateId}");
if (checkIf > 0)
{
return -1;
}
var record = await this.unitOfWork.DynamicTemplates.FindAsync(x => x.DynamicTemplateId == model.DynamicTemplateId);
record.Active = true;
record.TemplateName = model.TemplateName;
record.Value = model.Value;
record.ModifiedBy = model.ModifiedBy;
record.ModifiedDate = DateTime.Now;
return await this.unitOfWork.DynamicTemplates.UpdateAsync(record);
}
}
}
namespace Hims.Infrastructure.Services
{
using Dapper;
using Domain.Configurations;
using Domain.Repositories.UnitOfWork;
using Domain.Services;
using Hims.Domain.Entities;
using Hims.Shared.EntityModels;
using Hims.Shared.Library;
using Hims.Shared.Library.Enums;
using Hims.Shared.Library.Helpers;
using Hims.Shared.UserModels;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
/// <inheritdoc />
public class EmergencyEncounterServices : IEmergencyEncounterService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <summary>
/// The timeline service.
/// </summary>
private readonly ITimelineService timelineService;
/// <inheritdoc cref="IEmergencyEncounterService"/>
public EmergencyEncounterServices(ITimelineService timelineService, IUnitOfWork unitOfWork)
{
this.unitOfWork = unitOfWork;
this.timelineService = timelineService;
}
public async Task<CommonResponse> AddAsync(EmergencyEncounterModifyModel model)
{
var commonResponse = new CommonResponse { Status = 1 };
var checkIf = model.IsAdmission
? await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"SELECT COUNT(""EmergencyEncounterId"") FROM ""EmergencyEncounter"" WHERE ""AdmissionId"" = {model.AppointmentId}")
: await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"SELECT COUNT(""EmergencyEncounterId"") FROM ""EmergencyEncounter"" WHERE ""AppointmentId"" = {model.AppointmentId}");
if (checkIf > 0)
{
commonResponse.Response = -1;
return commonResponse;
}
var values = this.unitOfWork.Appointments.Find(s => s.AppointmentId == model.AppointmentId);
var encounter = new EmergencyEncounter
{
Active = true,
AppointmentId = model.AppointmentId,
CreatedBy = (int)model.ModifiedBy,
CreatedDate = DateTime.UtcNow,
PatientId = values.PatientId,
};
switch (model.Type)
{
case EmergencyEncounterType.EmergencyTriage:
encounter.EmergencyTriage = model.JsonString;
break;
case EmergencyEncounterType.NursingERForm:
encounter.NursingERForm = model.JsonString;
break;
}
try
{
var response = await this.unitOfWork.EmergencyEncounter.InsertAsync(encounter);
commonResponse.Response = response;
return commonResponse;
}
catch (Exception ex)
{
throw ex;
}
}
public Task<EmergencyEncounterModel> FindAsync(int appointmentId, bool isAdmission)
{
var query = isAdmission ? $@"SELECT A.""AdmissionId"" as ""AppointmentId"",e.""EmergencyEncounterId"",e.""EmergencyTriage"",e.""NursingERForm"",e.""Active"",e.""PatientId"" from ""Admission""a
left join ""EmergencyEncounter"" e on e.""AdmissionId""=a.""AdmissionId""
where A.""AdmissionId""='{appointmentId}' and A.""Active"" Is true"
: $@"select a.""AppointmentId"",e.""EmergencyEncounterId"",e.""EmergencyTriage"",e.""NursingERForm"",e.""Active"",e.""PatientId"" from ""Appointment""a
left join ""EmergencyEncounter"" e on e.""AppointmentId""=a.""AppointmentId""
where A.""AppointmentId""='{appointmentId}' and A.""Active"" Is true";
return this.unitOfWork.Current.QueryFirstOrDefaultAsync<EmergencyEncounterModel>(query);
}
public Task<IEnumerable<EmergencyEncounterModel>> FindAllAsync(int ProviderId)
{
var where = @" WHERE 1=1 ";
if (ProviderId != 0)
{
where += $@" AND A.""ProviderId"" ={ProviderId}";
}
//var query = $@"select * from ""EmergencyEncounter""";
//var qry = $@"select EE.* from ""EmergencyEncounter"" EE join ""Appointment"" A on A.""AppointmentId""=EE.""AppointmentId"" {where}";
var query = $@" select EE.*,A.""ProviderId"",P.""UMRNo"", TO_CHAR(A.""AppointmentTime"", 'hh12:mi AM') as ""AppointmentTime"",P.""FullName"" as ""PatientName""
from ""EmergencyEncounter"" EE
join ""Appointment"" A on A.""AppointmentId""=EE.""AppointmentId""
join ""Patient"" P on P.""PatientId""=A.""PatientId""{where}";
return this.unitOfWork.Current.QueryAsync<EmergencyEncounterModel>(query);
}
public async Task<EmergencyEncounterResource> FindDashboardAsync(int appointmentId, EmergencyEncounterType type, bool isAdmission)
{
var emergencyEncounter =
await this.unitOfWork.EmergencyEncounter.FindAsync(m => m.AppointmentId == appointmentId);
var emergencyEncounterResource = new EmergencyEncounterResource
{
AppointmentId = appointmentId,
EmergencyEncounterId = null,
JsonString = null
};
if (emergencyEncounter != null)
{
emergencyEncounterResource.EmergencyEncounterId = emergencyEncounter.EmergencyEncounterId;
switch (type)
{
case EmergencyEncounterType.EmergencyTriage:
emergencyEncounterResource.JsonString = emergencyEncounter.EmergencyTriage;
break;
case EmergencyEncounterType.NursingERForm:
emergencyEncounterResource.JsonString = emergencyEncounter.NursingERForm;
break;
}
}
return emergencyEncounterResource;
}
public async Task<CommonResponse> UpdateAsync(EmergencyEncounterModifyModel model)
{
var commonResponse = new CommonResponse { Status = 1 };
var encounter = await this.unitOfWork.EmergencyEncounter.FindAsync(m => m.EmergencyEncounterId == model.EmergencyEncounterId);
var checkIf = model.IsAdmission
? await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"SELECT COUNT(""EmergencyEncounterId"") FROM ""EmergencyEncounter"" WHERE ""AdmissionId"" = '{model.AppointmentId}' AND ""EmergencyEncounterId"" <> '{model.EmergencyEncounterId}'")
: await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"SELECT COUNT(""EmergencyEncounterId"") FROM ""EmergencyEncounter"" WHERE ""AppointmentId"" = '{model.AppointmentId}' AND ""EmergencyEncounterId"" <> '{model.EmergencyEncounterId}'");
if (checkIf > 0)
{
commonResponse.Response = -1;
return commonResponse;
}
encounter.ModifiedBy = model.ModifiedBy;
encounter.ModifiedDate = DateTime.UtcNow;
switch (model.Type)
{
case EmergencyEncounterType.EmergencyTriage:
encounter.EmergencyTriage = model.JsonString;
break;
case EmergencyEncounterType.NursingERForm:
encounter.NursingERForm = model.JsonString;
break;
}
var updated = await this.unitOfWork.EmergencyEncounter.UpdateAsync(encounter);
commonResponse.Response = updated > 0 ? encounter.EmergencyEncounterId : 0;
return commonResponse;
}
}
}
using Dapper;
using Hims.Domain.Entities;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Services;
using Hims.Shared.EntityModels;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Hims.Infrastructure.Services
{
public class EmployeeShiftServices : IEmployeeShiftService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
public EmployeeShiftServices(IUnitOfWork unitOfWork)
{
this.unitOfWork = unitOfWork;
}
public async Task<int> AddAsync(EmployeeShiftModel model)
{
var shift = await this.unitOfWork.EmployeeShifts.FindAsync(m => m.LocationId == model.LocationId && m.EmployeeShiftName == model.EmployeeShiftName && m.StartTime == TimeSpan.Parse(model.StartTime) && m.EndTime == TimeSpan.Parse(model.EndTime));
if (shift != null)
{
return -1;
}
var employeeShift = new EmployeeShift
{
EmployeeShiftName = model.EmployeeShiftName,
LocationId = model.LocationId,
StartTime = TimeSpan.Parse(model.StartTime),
EndTime = TimeSpan.Parse(model.EndTime),
Note = model.Note,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.UtcNow,
Active = true
};
return await this.unitOfWork.EmployeeShifts.InsertAsync(employeeShift);
}
public async Task<int> UpdateAsync(EmployeeShiftModel model)
{
var shift = await this.unitOfWork.EmployeeShifts.FindAsync(m => m.LocationId == model.LocationId && m.EmployeeShiftName == model.EmployeeShiftName && m.StartTime == TimeSpan.Parse(model.StartTime) && m.EndTime == TimeSpan.Parse(model.EndTime) && m.EmployeeShiftId != model.EmployeeShiftId);
if (shift != null)
{
return -1;
}
var employeeShift = await this.unitOfWork.EmployeeShifts.FindAsync(m => m.EmployeeShiftId == model.EmployeeShiftId);
employeeShift.EmployeeShiftName = model.EmployeeShiftName;
employeeShift.LocationId = model.LocationId;
employeeShift.StartTime = TimeSpan.Parse(model.StartTime);
employeeShift.EndTime = TimeSpan.Parse(model.EndTime);
employeeShift.Note = model.Note;
employeeShift.ModifiedBy = model.ModifiedBy;
employeeShift.ModifiedDate = DateTime.UtcNow;
return await this.unitOfWork.EmployeeShifts.UpdateAsync(employeeShift);
}
public async Task<int> ChangeStatusAsync(EmployeeShiftModel model)
{
var employeeShift = await this.unitOfWork.EmployeeShifts.FindAsync(m => m.EmployeeShiftId == model.EmployeeShiftId);
employeeShift.Active = model.Active;
employeeShift.ModifiedBy = model.ModifiedBy;
employeeShift.ModifiedDate = DateTime.UtcNow;
return await this.unitOfWork.EmployeeShifts.UpdateAsync(employeeShift);
}
public async Task<IEnumerable<EmployeeShiftModel>> FetchAsync(EmployeeShiftFilterModel model)
{
var where = $@" WHERE 1=1 ";
var query = $@"SELECT COUNT(*) OVER() AS ""TotalItems"", A.* FROM (SELECT L.""Name"" AS ""LocationName"", ES.""EmployeeShiftName"",
""Note"", ""EmployeeShiftId"", ES.""CreatedDate"", ES.""CreatedBy"", ES.""Active"", ES.""LocationId"",
TO_CHAR(""StartTime"" ,'hh12:mi AM')::text ""StartTime"",
TO_CHAR(""EndTime"" ,'hh12:mi AM')::text ""EndTime""
FROM ""EmployeeShift"" ES
JOIN ""Location"" L ON L.""LocationId"" = ES.""LocationId"" {where} ) A ";
if (model.PageIndex <= 0)
{
return await this.unitOfWork.Current.QueryAsync<EmployeeShiftModel>(query);
}
model.PageIndex -= 1;
query += " LIMIT " + model.PageSize + " offset " + (model.PageIndex * model.PageSize);
var res = await this.unitOfWork.Current.QueryAsync<EmployeeShiftModel>(query);
return res;
}
}
}
namespace Hims.Infrastructure.Services
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;
using Hims.Domain.Entities.EncounterTemplates;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Services;
using Hims.Shared.UserModels.EncounterTemplates;
/// <summary>
/// The enocunter template service.
/// </summary>
public class EncounterTemplateServices : IEncounterTemplateService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IEncounterTemplateService"/>
public EncounterTemplateServices(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
/// <inheritdoc/>
public async Task<int> InsertOrEditTemplateAsync(EncounterTemplateModel model)
{
var checkIfQuery = $@"select count(*) from ""TemplateHeader"" where lower(""TemplateName"") = lower('{model.TemplateName}') and ""ModulesMasterId"" = {model.ModulesMasterId} ";
var templateHeader = new TemplateHeader
{
Active = true,
CreatedBy = (int)model.CreatedBy,
CreatedDate = DateTime.Now,
ModulesMasterId = (int)model.ModulesMasterId,
TemplateName = model.TemplateName,
};
if (model.TemplateHeaderId != null && model.TemplateHeaderId > 0)
{
checkIfQuery += $@" and ""TemplateHeaderId"" <> {model.TemplateHeaderId}";
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>(checkIfQuery);
if (checkIf > 0)
{
return -1;
}
var getOldOne = await this.unitOfWork.TemplateHeaders.FindAsync(t => t.TemplateHeaderId == model.TemplateHeaderId);
getOldOne.TemplateName = model.TemplateName;
getOldOne.ModifiedBy = templateHeader.CreatedBy;
getOldOne.ModifiedDate = DateTime.Now;
var updateRes = await this.unitOfWork.TemplateHeaders.UpdateAsync(getOldOne);
if (updateRes < 0)
{
return -2;
}
var findDet = await this.unitOfWork.TemplateDetails.FindAsync(x => x.TemplateHeaderId == model.TemplateHeaderId);
findDet.JSONValue = model.JSONValue;
return await this.unitOfWork.TemplateDetails.UpdateAsync(findDet);
}
else
{
var checkIf = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<int>(checkIfQuery);
if (checkIf > 0)
{
return -1;
}
templateHeader.TemplateHeaderId = await this.unitOfWork.TemplateHeaders.InsertAsync(templateHeader);
var detail = new TemplateDetail
{
TemplateHeaderId = templateHeader.TemplateHeaderId,
JSONValue = model.JSONValue
};
return await this.unitOfWork.TemplateDetails.InsertAsync(detail);
}
}
/// <inheritdoc/>
public async Task<IEnumerable<EncounterTemplateModel>> FetchTemplatesAsync(EncounterTemplateModel model)
{
var where = "where 1=1";
if(model.Active != null)
{
where += $@" and th.""Active"" is {model.Active}";
}
if(model.ModulesMasterId != null)
{
where += $@" and th.""ModulesMasterId"" = {model.ModulesMasterId}";
}
if (!string.IsNullOrEmpty(model.ModuleName))
{
where += $@" and lower(mm.""ModuleName"") ilike '%{model.ModuleName.ToLower()}%'";
}
if (model.TemplateHeaderId!=null)
{
where += $@" and th.""TemplateHeaderId"" = {model.TemplateHeaderId}";
}
var query = $@"SELECT count(th.*) over() as ""TotalItems"", th.""TemplateHeaderId"", th.""ModulesMasterId"", th.""TemplateName"", th.""CreatedBy"", th.""CreatedDate"", th.""ModifiedBy"", th.""ModifiedDate"", th.""Active"" ,
td.""TemplateDetailId"" ,td.""JSONValue"" , c.""FullName"" as ""CreatedByName"", m.""FullName"" as ""ModifiedByName"", mm.""ModuleName"" ,mm.""ModuleIcon""
FROM ""TemplateHeader"" th
join ""TemplateDetail"" td on td.""TemplateHeaderId"" = th.""TemplateHeaderId""
join ""ModulesMaster"" mm ON mm.""ModulesMasterId"" = th.""ModulesMasterId""
join ""Account"" c on c.""AccountId"" = th.""CreatedBy""
left join ""Account"" m on m.""AccountId"" = th.""ModifiedBy""
{where}
order by th.""CreatedDate"" desc";
if (model.PageIndex != null && model.PageSize != null)
{
model.PageIndex = model.PageIndex > 0 ? model.PageIndex - 1 : model.PageIndex;
query += $@" limit {model.PageSize} offset {model.PageSize * model.PageIndex}";
}
return await this.unitOfWork.Current.QueryAsync<EncounterTemplateModel>(query);
}
}
}
namespace Hims.Infrastructure.Services
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;
using Domain.Entities;
using Domain.Repositories.UnitOfWork;
using Domain.Services;
using Shared.EntityModels;
using Shared.UserModels.Filters;
/// <inheritdoc />
public class EncounterTypeService : IEncounterTypeService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IEncounterTypeService" />
public EncounterTypeService(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
/// <inheritdoc />
public Task<IEnumerable<EncounterTypeModel>> FetchAsync(EncounterTypeFilterModel model)
{
var where = " WHERE 1 = 1 ";
if (!string.IsNullOrEmpty(model.EncounterName))
{
where += $@" AND TRIM(UPPER(""EncounterName"")) = '{model.EncounterName.Trim().ToUpper()}'";
}
if (model.Active != null)
{
where += $@" AND ""Active"" IS {((bool)model.Active ? "TRUE" : "FALSE")}";
}
var query = $@"SELECT COUNT(*) OVER () AS ""TotalItems"", * FROM ""EncounterType"" {where} Order by ""EncounterTypeId"" DESC";
if (model.PageIndex <= 0)
{
return this.unitOfWork.Current.QueryAsync<EncounterTypeModel>(query);
}
model.PageIndex -= 1;
query += " LIMIT " + model.PageSize + " offset " + (model.PageIndex * model.PageSize);
return this.unitOfWork.Current.QueryAsync<EncounterTypeModel>(query);
}
/// <inheritdoc />
public async Task<int> AddAsync(EncounterTypeModel model)
{
try
{
var checkIf = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"SELECT COUNT(""EncounterTypeId"") FROM ""EncounterType"" WHERE TRIM(UPPER(""EncounterName"")) = '{model.EncounterName.ToUpper().Trim()}'");
if (checkIf > 0)
{
return -1;
}
var encounterType = new EncounterType
{
Active = true,
EncounterName = model.EncounterName,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
};
return await this.unitOfWork.EncounterType.InsertAsync(encounterType);
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
return 0;
}
/// <inheritdoc />
public async Task<int> UpdateAsync(EncounterTypeModel model)
{
var checkIf = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"SELECT COUNT(""EncounterTypeId"") FROM ""EncounterType"" WHERE TRIM(UPPER(""EncounterName"")) = '{model.EncounterName.ToUpper().Trim()}' AND ""EncounterTypeId"" <> {model.EncounterTypeId}");
if (checkIf > 0)
{
return -1;
}
var encounterType = await this.unitOfWork.EncounterType.FindAsync(m => m.EncounterTypeId == model.EncounterTypeId);
encounterType.EncounterName = model.EncounterName;
encounterType.Active = true;
encounterType.ModifiedBy = model.ModifiedBy;
encounterType.ModifiedDate = DateTime.Now;
return await this.unitOfWork.EncounterType.UpdateAsync(encounterType);
}
/// <inheritdoc />
public Task<int> DeleteAsync(int chargeTypesId)
{
var query = $@"DELETE FROM ""EncounterType"" WHERE ""EncounterTypeId""= {chargeTypesId}";
return this.unitOfWork.Current.ExecuteAsync(query);
}
public async Task<string> FindNameByEncounterTypeId(int chargeTypesId)
{
var query = $@"SELECT ""EncounterName"" FROM ""EncounterType"" WHERE ""EncounterTypeId"" = {chargeTypesId}";
var response = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<string>(query);
return response;
}
}
}
\ No newline at end of file
using Dapper;
using Hims.Domain.Entities;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Services;
using Hims.Shared.EntityModels;
using Hims.Shared.UserModels;
using Hims.Shared.UserModels.Filters;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Hims.Infrastructure.Services
{
public class EncountersLogServices : IEncountersLogService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <summary>
/// Initializes a new instance of the <see cref="EncountersLogServices"/> class.
/// </summary>
/// <param name="unitOfWork">
/// The unit of work.
/// </param>
public EncountersLogServices(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
/// <inheritdoc />
public Task<IEnumerable<EncountersLogModel>> FetchAsync(EncountersLogModel model)
{
var where = $@" WHERE 1 = 1 ";
if (model.EncounterTypeId != 0)
{
where += $@" AND log.""EncounterTypeId"" = '{model.EncounterTypeId}'";
}
if (model.AccountId != null)
{
where += $@" AND log.""AccountId"" = '{model.AccountId}'";
}
if (!string.IsNullOrEmpty(model.Section))
{
where += $@" AND log.""Section"" ILIKE '%{model.Section}%'";
}
if (!string.IsNullOrEmpty(model.FromDate) && !string.IsNullOrEmpty(model.ToDate))
{
where += $@" AND (""LogDate"" at time zone 'UTC' at time zone 'Asia/Kolkata')::DATE >= '{model.FromDate}'::DATE";
where += $@" AND (""LogDate"" at time zone 'UTC' at time zone 'Asia/Kolkata')::DATE <= '{model.ToDate}'::DATE";
}
var query = $@"SELECT COUNT(*) OVER() AS ""TotalItems"", log.*, acc.""FullName"", rl.""RoleName"",rl.""RoleId"" , ET.""EncounterName"" as EncounterTypeName FROM ""EncountersLog"" log
LEFT JOIN ""Account"" acc ON acc.""AccountId"" = log.""AccountId"" AND acc.""Active"" IS TRUE
LEFT JOIN ""Role"" rl ON rl.""RoleId"" = acc.""RoleId"" AND rl.""Active"" IS TRUE
LEFT JOIN ""EncounterType"" ET ON ET.""EncounterTypeId"" = log.""EncounterTypeId""
{where} Order by log.""EncounterLogId"" DESC";
if (model.PageIndex <= 0)
{
return this.unitOfWork.Current.QueryAsync<EncountersLogModel>(query);
}
model.PageIndex -= 1;
query += " LIMIT " + model.PageSize + " offset " + (model.PageIndex * model.PageSize);
return this.unitOfWork.Current.QueryAsync<EncountersLogModel>(query);
}
/// <inheritdoc />
public Task LogAsync(EncountersLogModel model)
{
var encountersLog = new EncountersLog
{
LogDate = DateTime.UtcNow,
AccountId = model.AccountId,
LogFrom = model.LogFrom,
EncounterTypeId = model.EncounterTypeId,
LogDescription = model.LogDescription,
LocationId = model.LocationId,
Section=model.Section,
};
return this.unitOfWork.EncountersLogs.InsertAsync(encountersLog);
}
public async Task<PatientModel> GetPatientDetails(int appointmentId)
{
var Query = $@"select * From ""Patient"" PT Join ""Appointment"" APT on APT.""PatientId"" = PT.""PatientId"" where APT.""AppointmentId"" = {appointmentId}";
return await this.unitOfWork.Current.QueryFirstOrDefaultAsync<PatientModel>(Query);
}
}
}
\ No newline at end of file
namespace Hims.Infrastructure.Services
{
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Domain.Entities;
using Domain.Repositories.UnitOfWork;
using Domain.Services;
using Shared.EntityModels;
using Dapper;
/// <inheritdoc />
public class ExcelUploadHistoryServices : IExcelUploadHistoryService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IExcelUploadHistoryService" />
public ExcelUploadHistoryServices(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
/// <inheritdoc />
public async Task<int> ModifyExcelUploadAsync(ExcelUploadHistoryModel model)
{
var upload = new ExcelUploadHistory
{
AddedProducts = model.AddedProducts,
CreatedDate = DateTime.UtcNow.AddMinutes(330),
SheetName = model.SheetName,
SheetType = model.SheetType,
TypeOf = model.TypeOf,
UploadedBy = model.UploadedBy,
ProductStatus = model.ProductStatus,
LocationId = model.LocationId
};
if (model.ExcelUploadHistoryId == 0)
{
return await this.unitOfWork.ExcelUploadHistory.InsertAsync(upload);
}
else
{
var previousRecord = await this.unitOfWork.ExcelUploadHistory.FindAsync(m => m.ExcelUploadHistoryId == model.ExcelUploadHistoryId);
var completeProductList = previousRecord.AddedProducts + "," + upload.AddedProducts;
var completeProductStatus = previousRecord.ProductStatus + "," + upload.ProductStatus;
previousRecord.AddedProducts = completeProductList;
previousRecord.ProductStatus = completeProductStatus;
await this.unitOfWork.ExcelUploadHistory.UpdateAsync(previousRecord);
return previousRecord.ExcelUploadHistoryId;
}
}
/// <inheritdoc />
public async Task<IEnumerable<ExcelUploadHistoryModel>> FetchAllAsync(ExcelUploadHistoryModel model)
{
var where = "where 1=1 ";
if (!string.IsNullOrEmpty(model.TypeOf))
{
where += $@" and EUH.""TypeOf"" ='{model.TypeOf}'";
}
var query = $@" Select count(EUH.*) over() as ""TotalItems"",EUH.*, A.""FullName"" as ""UploadedByName"", l.""Name"" as ""LocationName"" from ""ExcelUploadHistory"" EUH
join ""Account"" A on A.""AccountId"" = EUH.""UploadedBy""
left join ""Location"" l on l.""LocationId"" = EUH.""LocationId""
{where}
order by ""CreatedDate"" desc";
if (model.PageIndex != null && model.PageSize != null)
{
model.PageIndex = model.PageIndex > 0 ? model.PageIndex - 1 : model.PageIndex;
query += $@" limit {model.PageSize} offset {model.PageSize * model.PageIndex}";
}
return await this.unitOfWork.Current.QueryAsync<ExcelUploadHistoryModel>(query);
}
/// <inheritdoc />
public async Task<ExcelUploadHistoryModel> GetSingleExcelHistory(int excelUploadHistoryId)
{
var data = await this.unitOfWork.ExcelUploadHistory.FindAsync(m => m.ExcelUploadHistoryId == excelUploadHistoryId);
return new ExcelUploadHistoryModel
{
AddedProducts = data.AddedProducts,
CreatedDate = data.CreatedDate,
ExcelUploadHistoryId = data.ExcelUploadHistoryId,
ProductStatus = data.ProductStatus,
SheetName = data.SheetName,
SheetType = data.SheetType,
TypeOf = data.TypeOf,
UploadedBy = data.UploadedBy
};
}
}
}
\ No newline at end of file
using System.Data;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Hims.Shared.EntityModels;
using Hims.Shared.UserModels.Filters;
namespace Hims.Infrastructure.Services
{
using Hims.Domain.Services;
using System;
using Dapper;
using Hims.Domain.Repositories.UnitOfWork;
using System.Collections.Generic;
using Npgsql;
/// <inheritdoc />
public class ExceptionLogServices : IExceptionLogService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <summary>
/// The connection name.
/// </summary>
private readonly string Connection;
/// <inheritdoc />
public ExceptionLogServices(IUnitOfWork unitOfWork, IConfiguration configuration)
{
this.unitOfWork = unitOfWork;
if (configuration.GetConnectionString($"Connection") != null)
{
this.Connection = configuration.GetConnectionString($"Connection");
}
}
/// <inheritdoc />
public void Invoke(string logFrom, string logRoute, string errorMessage, string errorDescription)
{
try
{
using (NpgsqlConnection connection = new NpgsqlConnection(Connection))
{
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
string query = $@"INSERT INTO ""ExceptionLog"" (""LogFrom"", ""LogRoute"", ""Message"", ""Description"", ""LogDate"", ""LogTime"", ""LogTimestamp"", ""Active"" ) VALUES ('{logFrom}', '{logRoute}', '{errorMessage}','{errorDescription}','{DateTime.UtcNow}'::date,'{DateTime.UtcNow}'::time,'{DateTime.UtcNow}', true);";
NpgsqlCommand command = new NpgsqlCommand(query, connection);
command.ExecuteNonQuery();
}
}
catch (Exception)
{
//ignore
}
}
/// <inheritdoc />
public async Task<IEnumerable<ExceptionLogModel>> FetchAsync(ExceptionLogFilterModel model)
{
var where = $@" WHERE 1 = 1 ";
if (model.LogPath!=null)
{
where += $@" AND split_part(""LogRoute"", '/', 2) = '{model.LogPath}'";
}
if (model.LogPathMethod != null)
{
where += $@" AND split_part(""LogRoute"", '/', 3) = '{model.LogPathMethod}'";
}
if (!string.IsNullOrEmpty(model.FromDate) && !string.IsNullOrEmpty(model.ToDate))
{
where += $@" AND (""LogDate"" at time zone 'UTC' at time zone 'Asia/Kolkata')::DATE >= '{model.FromDate}'::DATE";
where += $@" AND (""LogDate"" at time zone 'UTC' at time zone 'Asia/Kolkata')::DATE <= '{model.ToDate}'::DATE";
}
var query = $@"SELECT COUNT(*) OVER() AS ""TotalItems"", ""ExceptionLogId"", ""LogFrom"", ""LogRoute"", ""LogDate"", ""LogTime"", ""LogTimestamp"", ""Message"", ""Description"", ""Active"" FROM ""ExceptionLog""
{where} Order by ""ExceptionLogId"" DESC";
if (model.PageIndex <= 0)
{
return await this.unitOfWork.Current.QueryAsync<ExceptionLogModel>(query);
}
model.PageIndex -= 1;
query += " LIMIT " + model.PageSize + " offset " + (model.PageIndex * model.PageSize);
return await this.unitOfWork.Current.QueryAsync<ExceptionLogModel>(query);
}
/// <inheritdoc />
public async Task<int> ResolveAsync(int exceptionLogId)
{
string query = $@"UPDATE ""ExceptionLog"" SET ""Active""= false WHERE ""ExceptionLogId"" = {exceptionLogId} ";
return await this.unitOfWork.Current.ExecuteAsync(query);
}
/// <inheritdoc />GetMethodAsync
public async Task<IEnumerable<ExceptionLogModel>> GetMethodAsync(string model)
{
//'api/appointments%
string query = $@"select distinct split_part(""LogRoute"", '/', 3) AS ""LogPathMethod"" from ""ExceptionLog"" where ""LogRoute"" ILike 'api/{model}%'";
return await this.unitOfWork.Current.QueryAsync<ExceptionLogModel>(query);
}
///// <inheritdoc />
public async Task<IEnumerable<ExceptionLogModel>> GetLogRouteAsync()
{
string query = $@"select distinct split_part(""LogRoute"", '/', 2) AS ""LogPath"" from ""ExceptionLog""";
return await this.unitOfWork.Current.QueryAsync<ExceptionLogModel>(query);
}
}
}
\ No newline at end of file
#nullable enable
namespace Hims.Infrastructure.Services
{
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;
using Domain.Repositories.UnitOfWork;
using Domain.Services;
using Shared.UserModels.Exports;
/// <inheritdoc />
public class ExportServices : IExportService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IExportService" />
public ExportServices(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
/// <inheritdoc />
public Task<IEnumerable<PaymentExportModel>> FetchPaymentsAsync(
string? fromDate,
string? toDate,
int? providerId,
int pageIndex,
int pageSize)
{
fromDate = fromDate == null ? "null" : "'" + fromDate + "'";
toDate = toDate == null ? "null" : "'" + toDate + "'";
var query = $@"SELECT * FROM ""udf_AppointmentsTransByProvider""({providerId}, null,null,null,null,null,null,{fromDate}, {toDate},null,null)";
return this.unitOfWork.Current.QueryAsync<PaymentExportModel>(query);
}
}
}
\ No newline at end of file
using Dapper;
using Hims.Domain.Entities;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Services;
using Hims.Shared.UserModels;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Hims.Infrastructure.Services
{
public class FeedbackDetailsServices : IFeedbackDetailsService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IBedService" />
public FeedbackDetailsServices(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
public async Task<int> AddAsync(FeedbackDetails model)
{
var checkIf = await this.unitOfWork.Current.QueryFirstOrDefaultAsync<int>($@"SELECT COUNT(""PatientName"") FROM ""FeedbackDetails"" WHERE ""MobileNumber"" = '{model.MobileNumber}'");
if (checkIf > 0)
{
return -1;
}
if(model.MobileNumber == "" )
{
return-1;
}
var problem = new FeedbackDetails
{
IsActive = true,
MobileNumber = model.MobileNumber,
PatientName = model.PatientName,
Rating = model.Rating,
Comments = model.Comments,
Type = model.Type,
CreatedBy = model.CreatedBy,
CreatedDate = DateTime.Now,
};
return await this.unitOfWork.Feedbackdetails.InsertAsync(problem);
}
public Task<int> DeleteAsync(int Id)
{
var query = $@"DELETE FROM ""FeedbackDetails"" WHERE ""Id""= {Id}";
return this.unitOfWork.Current.ExecuteAsync(query);
}
public async Task<IEnumerable<FeedbackDetailsModel>> FetchAsync(FeedbackDetailsModel model)
{
var query = $@"Select Acc.""FullName"", FD.""MobileNumber"",FD.""PatientName"", FD.""Comments"", FD.""CreatedDate"", FD.""Rating"" From ""FeedbackDetails"" FD Join ""Account"" Acc On FD.""CreatedBy"" = Acc.""AccountId"" order by FD.""Id"" desc";
var response = await this.unitOfWork.Current.QueryAsync<FeedbackDetailsModel>(query);
return response;
}
public async Task<IEnumerable<FeedbackDetailsModel>> FindById(string Id)
{
//var query = $@"SELECT * FROM ""Patient"" WHERE ""Mobile""= '{Id}' and ""HowDidYouKnowId"" = 11 and ""TempPatient"" = false";
var query = $@"Select Acc.""FullName"", FD.""MobileNumber"",FD.""PatientName"", FD.""Comments"", FD.""CreatedDate"", FD.""Rating"" From ""FeedbackDetails"" FD Join ""Account"" Acc On FD.""CreatedBy"" = Acc.""AccountId"" WHERE FD.""MobileNumber""= '{Id}' order by FD.""Id"" desc ";
var response = await this.unitOfWork.Current.QueryAsync<FeedbackDetailsModel>(query);
return response;
}
public async Task<int> UpdateAsync(FeedbackDetails model)
{
var problems = await this.unitOfWork.Feedbackdetails.FindAsync(m => m.MobileNumber == model.MobileNumber);
if (model.MobileNumber != "") { problems.MobileNumber = model.MobileNumber; }
if (model.Rating != 0) { problems.Rating = model.Rating; }
if (model.Comments != null) { problems.Comments = model.Comments; }
problems.ModifiedBy = model.ModifiedBy;
problems.ModifiedDate = DateTime.Now;
return await this.unitOfWork.Feedbackdetails.UpdateAsync(problems);
}
}
}
This diff is collapsed.
using Dapper;
namespace Hims.Infrastructure.Services
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Hims.Domain.Entities;
using Hims.Domain.Repositories.UnitOfWork;
using Hims.Domain.Services;
using Hims.Domain.Entities.Enums;
using Hims.Shared.UserModels.GataPass;
using Hims.Shared.UserModels.Slots;
using Resource = Hims.Shared.UserModels.Discharge.Resource;
/// <summary> The chat service.</summary>
public class GatePassService : IGatePassService
{
/// <summary>
/// The unit of work.
/// </summary>
private readonly IUnitOfWork unitOfWork;
/// <inheritdoc cref="IChatService" />
public GatePassService(IUnitOfWork unitOfWork) => this.unitOfWork = unitOfWork;
public async Task<int> InsertAsync(InsertModel model)
{
var record = new GatePass
{
ValidUpto=model.ValidUpto,
Remark=model.Remark,
AdmissionId = model.AdmissionId,
CreatedBy = model.CreatedBy,
CreatedDate = model.CreatedDate,
TypeId= model.TypeId > 1 ?(int)GatePassType.Final:(int)GatePassType.Provisional
};
var response = await this.unitOfWork.GatePass.InsertAsync(record);
return response;
}
public async Task<int> UpdateAsync(InsertModel model)
{
var record = await this.unitOfWork.GatePass.FindAsync(x => x.GatePassId == Convert.ToInt32(model.Id));
record.ModifiedBy = model.ModifiedBy;
record.ModifiedDate = model.ModifiedDate;
record.ValidUpto= model.ValidUpto;
record.Remark = model.Remark;
var response = await this.unitOfWork.GatePass.UpdateAsync(record);
return response;
}
public async Task<InsertModel> FetchAsync(InsertModel model)
{
var where = $@"where AD.""AdmissionId"" = {Convert.ToInt32(model.Id)}";
if (model.TypeId != null)
{
where += $@" and GP.""TypeId"" = {model.TypeId} ";
}
var query = $@"Select GP.*, A.""FullName"" as ""CreatedByName"",P.""Zipcode"",P.""City"",P.""StreetAddress"" as ""Area"",CT.""CaseTypeName""
from ""GatePass"" GP
join ""Account"" A on A.""AccountId""=GP.""CreatedBy""
join ""Admission"" AD on AD.""AdmissionId""=GP.""AdmissionId""
join ""Patient"" P on P.""PatientId""=AD.""PatientId""
left join ""CaseType"" CT on CT.""CaseTypeId"" = AD.""CaseTypeId""
{where}";
var record = await this.unitOfWork.Current.QuerySingleOrDefaultAsync<InsertModel>(query);
return record;
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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