From 48768068600be759596ee4a1028d857a6f80742a Mon Sep 17 00:00:00 2001 From: Sk Shaifat Murshed Date: Thu, 6 Feb 2025 18:42:32 +0530 Subject: [PATCH] Modified Appointment Module --- .../view-appointment.component.html | 28 +- .../view-appointment.component.ts | 40 +- .../all-patients/all-patients.component.html | 2 +- .../patient-record.component.html | 4 +- .../src/app/proxy/appoinments/dto/models.ts | 2 + .../proxy/appointments/appointment.service.ts | 14 +- angular/src/app/proxy/appointments/index.ts | 1 + angular/src/app/proxy/appointments/models.ts | 25 + angular/src/app/proxy/departments/index.ts | 1 + angular/src/app/proxy/departments/models.ts | 10 + angular/src/app/proxy/doctors/index.ts | 1 + angular/src/app/proxy/doctors/models.ts | 19 + angular/src/app/proxy/generate-proxy.json | 482 +++++++++++++++++- .../Appoinments/Dto/AppointmentDto.cs | 5 +- ...agementSystem.Application.Contracts.csproj | 1 + .../Appointments/AppointmentAppService.cs | 97 +++- 16 files changed, 691 insertions(+), 41 deletions(-) create mode 100644 angular/src/app/proxy/appointments/models.ts create mode 100644 angular/src/app/proxy/departments/models.ts create mode 100644 angular/src/app/proxy/doctors/models.ts diff --git a/angular/src/app/appointment/view-appointment/view-appointment.component.html b/angular/src/app/appointment/view-appointment/view-appointment.component.html index 9530584..ada818f 100644 --- a/angular/src/app/appointment/view-appointment/view-appointment.component.html +++ b/angular/src/app/appointment/view-appointment/view-appointment.component.html @@ -51,7 +51,7 @@ > - @@ -132,7 +132,7 @@
- + @@ -141,7 +141,7 @@
- + @@ -149,7 +149,7 @@
- +
- + @@ -186,7 +186,7 @@ >
- +
- + @@ -214,13 +214,14 @@
- +
- +
- +
- + !isNaN(Number(key))) .map(key => ({ @@ -141,10 +144,33 @@ export class ViewAppointmentComponent { }; } - exportAppointments() { - console.log('Exporting appointment data'); - } + exportAppointments() { + debugger + this.AppointmentService.getExportAppointmentRecord().subscribe(result => { + const binary = atob(result.fileContent); + const len = binary.length; + const bytes = new Uint8Array(len); + + for (let i = 0; i < len; i++) { + bytes[i] = binary.charCodeAt(i); + } + + const blob = new Blob([bytes], { type: 'application/xlsx' }); + + const url = window.URL.createObjectURL(blob); + + const link = document.createElement('a'); + link.href = url; + link.download = result.fileName; + + document.body.appendChild(link); + link.click(); + + document.body.removeChild(link); + window.URL.revokeObjectURL(url); + }); + } editAppointment(appointment: any) { debugger; this.isEditMode = true; @@ -153,8 +179,8 @@ export class ViewAppointmentComponent { this.AppointmentService.getAppointmentById(appointment.id).subscribe(result => { debugger; this.appointment = result; - this.appointment.dateOfAppointment = new Date(result.dateOfAppointment).toISOString().split('T')[0];; - this.appointment.dob = new Date(result.dob).toISOString().split('T')[0];; + this.AppointmentDate = new Date(result.dateOfAppointment); + this.Dateofbirth = new Date(result.dob); }); } @@ -181,6 +207,8 @@ export class ViewAppointmentComponent { Object.values(form.controls).forEach(control => control.markAsTouched()); return; } + this.appointment.dob = this.Dateofbirth.toDateString(); + this.appointment.dateOfAppointment = this.AppointmentDate.toDateString(); if (this.isEditMode) { this.AppointmentService.updateAppointment(this.appointment).subscribe( () => { @@ -197,7 +225,7 @@ export class ViewAppointmentComponent { }, error => { console.log(error); - this.toaster.error(error.error.error.message, 'Error'); + this.toaster.error(error, 'Error'); } ); } else { diff --git a/angular/src/app/patients/all-patients/all-patients.component.html b/angular/src/app/patients/all-patients/all-patients.component.html index 3aadf3e..3dc1de2 100644 --- a/angular/src/app/patients/all-patients/all-patients.component.html +++ b/angular/src/app/patients/all-patients/all-patients.component.html @@ -226,7 +226,7 @@
- Admission Date is required diff --git a/angular/src/app/patients/patient-record/patient-record.component.html b/angular/src/app/patients/patient-record/patient-record.component.html index 1640b18..46a9ad0 100644 --- a/angular/src/app/patients/patient-record/patient-record.component.html +++ b/angular/src/app/patients/patient-record/patient-record.component.html @@ -141,7 +141,7 @@
- Admission Date is required. @@ -153,7 +153,7 @@
- Next Follow-Up Date is required. diff --git a/angular/src/app/proxy/appoinments/dto/models.ts b/angular/src/app/proxy/appoinments/dto/models.ts index 22b4491..fdf8af5 100644 --- a/angular/src/app/proxy/appoinments/dto/models.ts +++ b/angular/src/app/proxy/appoinments/dto/models.ts @@ -2,6 +2,7 @@ import type { Gender } from '../../global-enum/gender.enum'; import type { appointmentStatus } from '../../global-enum/appointment-status.enum'; import type { visitType } from '../../global-enum/visit-type.enum'; import type { paymentStatus } from '../../global-enum/payment-status.enum'; +import type { Doctor } from '../../doctors/models'; export interface AppointmentDto { id?: string; @@ -21,6 +22,7 @@ export interface AppointmentDto { appointmentStatus: appointmentStatus; visitType: visitType; paymentStatus: paymentStatus; + doctor: Doctor; } export interface CreateOrUpdateAppointmentDto { diff --git a/angular/src/app/proxy/appointments/appointment.service.ts b/angular/src/app/proxy/appointments/appointment.service.ts index 16b9417..4ad7fb0 100644 --- a/angular/src/app/proxy/appointments/appointment.service.ts +++ b/angular/src/app/proxy/appointments/appointment.service.ts @@ -2,7 +2,7 @@ import { RestService, Rest } from '@abp/ng.core'; import { Injectable } from '@angular/core'; import type { PagedResultDto } from '../abp/application/services/dto/models'; import type { AppointmentDto, CreateOrUpdateAppointmentDto } from '../appoinments/dto/models'; -import type { PagingSortResultDto } from '../dto/models'; +import type { FileDownloadDto, PagingSortResultDto } from '../dto/models'; @Injectable({ providedIn: 'root', @@ -12,7 +12,7 @@ export class AppointmentService { createAppointment = (input: CreateOrUpdateAppointmentDto, config?: Partial) => - this.restService.request({ + this.restService.request({ method: 'POST', url: '/api/app/appointment/appointment', body: input, @@ -54,8 +54,16 @@ export class AppointmentService { { apiName: this.apiName,...config }); + getExportAppointmentRecord = (config?: Partial) => + this.restService.request({ + method: 'GET', + url: '/api/app/appointment/export-appointment-record', + }, + { apiName: this.apiName,...config }); + + updateAppointment = (input: CreateOrUpdateAppointmentDto, config?: Partial) => - this.restService.request({ + this.restService.request({ method: 'PUT', url: '/api/app/appointment/appointment', body: input, diff --git a/angular/src/app/proxy/appointments/index.ts b/angular/src/app/proxy/appointments/index.ts index 63c6d7e..39b7171 100644 --- a/angular/src/app/proxy/appointments/index.ts +++ b/angular/src/app/proxy/appointments/index.ts @@ -1 +1,2 @@ export * from './appointment.service'; +export * from './models'; diff --git a/angular/src/app/proxy/appointments/models.ts b/angular/src/app/proxy/appointments/models.ts new file mode 100644 index 0000000..53dbb11 --- /dev/null +++ b/angular/src/app/proxy/appointments/models.ts @@ -0,0 +1,25 @@ +import type { FullAuditedEntity } from '../volo/abp/domain/entities/auditing/models'; +import type { Gender } from '../global-enum/gender.enum'; +import type { Doctor } from '../doctors/models'; +import type { appointmentStatus } from '../global-enum/appointment-status.enum'; +import type { visitType } from '../global-enum/visit-type.enum'; +import type { paymentStatus } from '../global-enum/payment-status.enum'; + +export interface Appointment extends FullAuditedEntity { + firstName?: string; + lastName?: string; + gender: Gender; + mobile?: string; + address?: string; + email?: string; + dob?: string; + doctor: Doctor; + dateOfAppointment?: string; + timeOfAppointment?: string; + injuryORContion?: string; + note?: string; + insuranceProvider?: string; + appointmentStatus: appointmentStatus; + visitType: visitType; + paymentStatus: paymentStatus; +} diff --git a/angular/src/app/proxy/departments/index.ts b/angular/src/app/proxy/departments/index.ts index 47a1528..7924191 100644 --- a/angular/src/app/proxy/departments/index.ts +++ b/angular/src/app/proxy/departments/index.ts @@ -1 +1,2 @@ export * from './department.service'; +export * from './models'; diff --git a/angular/src/app/proxy/departments/models.ts b/angular/src/app/proxy/departments/models.ts new file mode 100644 index 0000000..588cf48 --- /dev/null +++ b/angular/src/app/proxy/departments/models.ts @@ -0,0 +1,10 @@ +import type { FullAuditedEntity } from '../volo/abp/domain/entities/auditing/models'; + +export interface Department extends FullAuditedEntity { + departmentNo?: string; + departmentName?: string; + departmentDate?: string; + departmentHead?: string; + status?: string; + description?: string; +} diff --git a/angular/src/app/proxy/doctors/index.ts b/angular/src/app/proxy/doctors/index.ts index 534e60f..ebbba4a 100644 --- a/angular/src/app/proxy/doctors/index.ts +++ b/angular/src/app/proxy/doctors/index.ts @@ -1 +1,2 @@ export * from './doctor.service'; +export * from './models'; diff --git a/angular/src/app/proxy/doctors/models.ts b/angular/src/app/proxy/doctors/models.ts new file mode 100644 index 0000000..6c1201f --- /dev/null +++ b/angular/src/app/proxy/doctors/models.ts @@ -0,0 +1,19 @@ +import type { FullAuditedEntity } from '../volo/abp/domain/entities/auditing/models'; +import type { Department } from '../departments/models'; +import type { Appointment } from '../appointments/models'; + +export interface Doctor extends FullAuditedEntity { + firstName?: string; + lastName?: string; + gender?: string; + mobile?: string; + password?: string; + designation?: string; + departmentId?: string; + department: Department; + address?: string; + email?: string; + dob?: string; + education?: string; + appointments: Appointment[]; +} diff --git a/angular/src/app/proxy/generate-proxy.json b/angular/src/app/proxy/generate-proxy.json index 504c97d..e2aa626 100644 --- a/angular/src/app/proxy/generate-proxy.json +++ b/angular/src/app/proxy/generate-proxy.json @@ -1053,8 +1053,8 @@ } ], "returnValue": { - "type": "HospitalManagementSystem.Appoinments.Dto.AppointmentDto", - "typeSimple": "HospitalManagementSystem.Appoinments.Dto.AppointmentDto" + "type": "System.Void", + "typeSimple": "System.Void" }, "allowAnonymous": null, "implementFrom": "HospitalManagementSystem.Appointments.AppointmentAppService" @@ -1090,8 +1090,8 @@ } ], "returnValue": { - "type": "HospitalManagementSystem.Appoinments.Dto.AppointmentDto", - "typeSimple": "HospitalManagementSystem.Appoinments.Dto.AppointmentDto" + "type": "System.Void", + "typeSimple": "System.Void" }, "allowAnonymous": null, "implementFrom": "HospitalManagementSystem.Appointments.AppointmentAppService" @@ -1132,6 +1132,21 @@ }, "allowAnonymous": false, "implementFrom": "HospitalManagementSystem.Appointments.AppointmentAppService" + }, + "GetExportAppointmentRecordAsync": { + "uniqueName": "GetExportAppointmentRecordAsync", + "name": "GetExportAppointmentRecordAsync", + "httpMethod": "GET", + "url": "api/app/appointment/export-appointment-record", + "supportedVersions": [], + "parametersOnMethod": [], + "parameters": [], + "returnValue": { + "type": "HospitalManagementSystem.Dto.FileDownloadDto", + "typeSimple": "HospitalManagementSystem.Dto.FileDownloadDto" + }, + "allowAnonymous": null, + "implementFrom": "HospitalManagementSystem.Appointments.AppointmentAppService" } } }, @@ -4901,6 +4916,18 @@ "minimum": null, "maximum": null, "regex": null + }, + { + "name": "Doctor", + "jsonName": null, + "type": "HospitalManagementSystem.Doctors.Doctor", + "typeSimple": "HospitalManagementSystem.Doctors.Doctor", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null } ] }, @@ -5117,6 +5144,453 @@ } ] }, + "HospitalManagementSystem.Appointments.Appointment": { + "baseType": "Volo.Abp.Domain.Entities.Auditing.FullAuditedEntity", + "isEnum": false, + "enumNames": null, + "enumValues": null, + "genericArguments": null, + "properties": [ + { + "name": "FirstName", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "LastName", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Gender", + "jsonName": null, + "type": "HospitalManagementSystem.GlobalEnum.Gender", + "typeSimple": "HospitalManagementSystem.GlobalEnum.Gender", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Mobile", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Address", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Email", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "DOB", + "jsonName": null, + "type": "System.DateTime?", + "typeSimple": "string?", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Doctor", + "jsonName": null, + "type": "HospitalManagementSystem.Doctors.Doctor", + "typeSimple": "HospitalManagementSystem.Doctors.Doctor", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "DateOfAppointment", + "jsonName": null, + "type": "System.DateTime?", + "typeSimple": "string?", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "TimeOfAppointment", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "InjuryORContion", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Note", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "InsuranceProvider", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "AppointmentStatus", + "jsonName": null, + "type": "HospitalManagementSystem.GlobalEnum.appointmentStatus", + "typeSimple": "HospitalManagementSystem.GlobalEnum.appointmentStatus", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "VisitType", + "jsonName": null, + "type": "HospitalManagementSystem.GlobalEnum.visitType", + "typeSimple": "HospitalManagementSystem.GlobalEnum.visitType", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "PaymentStatus", + "jsonName": null, + "type": "HospitalManagementSystem.GlobalEnum.paymentStatus", + "typeSimple": "HospitalManagementSystem.GlobalEnum.paymentStatus", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + } + ] + }, + "HospitalManagementSystem.Departments.Department": { + "baseType": "Volo.Abp.Domain.Entities.Auditing.FullAuditedEntity", + "isEnum": false, + "enumNames": null, + "enumValues": null, + "genericArguments": null, + "properties": [ + { + "name": "DepartmentNo", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "DepartmentName", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "DepartmentDate", + "jsonName": null, + "type": "System.DateTime?", + "typeSimple": "string?", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "DepartmentHead", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Status", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Description", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + } + ] + }, + "HospitalManagementSystem.Doctors.Doctor": { + "baseType": "Volo.Abp.Domain.Entities.Auditing.FullAuditedEntity", + "isEnum": false, + "enumNames": null, + "enumValues": null, + "genericArguments": null, + "properties": [ + { + "name": "FirstName", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "LastName", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Gender", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Mobile", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Password", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Designation", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "DepartmentId", + "jsonName": null, + "type": "System.Guid?", + "typeSimple": "string?", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Department", + "jsonName": null, + "type": "HospitalManagementSystem.Departments.Department", + "typeSimple": "HospitalManagementSystem.Departments.Department", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Address", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Email", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "DOB", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Education", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + }, + { + "name": "Appointments", + "jsonName": null, + "type": "[HospitalManagementSystem.Appointments.Appointment]", + "typeSimple": "[HospitalManagementSystem.Appointments.Appointment]", + "isRequired": false, + "minLength": null, + "maxLength": null, + "minimum": null, + "maximum": null, + "regex": null + } + ] + }, "HospitalManagementSystem.Documents.EntityDocument": { "baseType": "Volo.Abp.Domain.Entities.Auditing.AuditedAggregateRoot", "isEnum": false, diff --git a/aspnet-core/src/HospitalManagementSystem.Application.Contracts/Appoinments/Dto/AppointmentDto.cs b/aspnet-core/src/HospitalManagementSystem.Application.Contracts/Appoinments/Dto/AppointmentDto.cs index 1456cbf..61f6ad9 100644 --- a/aspnet-core/src/HospitalManagementSystem.Application.Contracts/Appoinments/Dto/AppointmentDto.cs +++ b/aspnet-core/src/HospitalManagementSystem.Application.Contracts/Appoinments/Dto/AppointmentDto.cs @@ -1,4 +1,5 @@ -using HospitalManagementSystem.GlobalEnum; +using HospitalManagementSystem.Doctors; +using HospitalManagementSystem.GlobalEnum; using System; using System.Collections.Generic; using System.Linq; @@ -26,5 +27,7 @@ namespace HospitalManagementSystem.Appoinments.Dto public appointmentStatus AppointmentStatus { get; set; } public visitType VisitType { get; set; } public paymentStatus PaymentStatus { get; set; } + public Doctor? Doctor { get; set; } + } } diff --git a/aspnet-core/src/HospitalManagementSystem.Application.Contracts/HospitalManagementSystem.Application.Contracts.csproj b/aspnet-core/src/HospitalManagementSystem.Application.Contracts/HospitalManagementSystem.Application.Contracts.csproj index 421e6d0..fd3383a 100644 --- a/aspnet-core/src/HospitalManagementSystem.Application.Contracts/HospitalManagementSystem.Application.Contracts.csproj +++ b/aspnet-core/src/HospitalManagementSystem.Application.Contracts/HospitalManagementSystem.Application.Contracts.csproj @@ -10,6 +10,7 @@ + diff --git a/aspnet-core/src/HospitalManagementSystem.Application/Appointments/AppointmentAppService.cs b/aspnet-core/src/HospitalManagementSystem.Application/Appointments/AppointmentAppService.cs index 20278c1..56978f5 100644 --- a/aspnet-core/src/HospitalManagementSystem.Application/Appointments/AppointmentAppService.cs +++ b/aspnet-core/src/HospitalManagementSystem.Application/Appointments/AppointmentAppService.cs @@ -20,6 +20,9 @@ using Microsoft.EntityFrameworkCore; using System.Linq.Dynamic.Core; using Abp.UI; using HospitalManagementSystem.Doctors; +using ClosedXML.Excel; +using System.IO; +using Microsoft.AspNetCore.Hosting; namespace HospitalManagementSystem.Appointments { @@ -29,6 +32,7 @@ namespace HospitalManagementSystem.Appointments private readonly ICurrentTenant _currentTenant; private IRepository _appointmentsRepository; private readonly IRepository _doctorRepository; + private readonly IWebHostEnvironment _env; public AppointmentAppService(ICurrentUser currentUser, ICurrentTenant currentTenant, IRepository appointmentsRepository, IRepository doctorRepository) { @@ -62,6 +66,7 @@ namespace HospitalManagementSystem.Appointments .Take(input.MaxResultCount) .ToListAsync(); var appoinmentdto = ObjectMapper.Map, List>(pagedQuery); + return new PagedResultDto( totalCount, appoinmentdto @@ -84,26 +89,34 @@ namespace HospitalManagementSystem.Appointments #endregion #region Create Appointment - public async Task CreateAppointmentAsync(CreateOrUpdateAppointmentDto input) + public async Task CreateAppointmentAsync(CreateOrUpdateAppointmentDto input) { - var appointment = ObjectMapper.Map(input); + Appointment appointment = new Appointment(); + var newdata = ObjectMapper.Map(input); + newdata.Doctor = await _doctorRepository.GetAsync(input.DoctorId.Value); + appointment = newdata; appointment = await _appointmentsRepository.InsertAsync(appointment); - return ObjectMapper.Map(appointment); } #endregion #region Update Appointment - public async Task UpdateAppointmentAsync(CreateOrUpdateAppointmentDto input) + public async Task UpdateAppointmentAsync(CreateOrUpdateAppointmentDto input) { - //var appointment = await _appointmentsRepository.GetAsync(input.Id); - Appointment appointment = new Appointment(); - var newdata = ObjectMapper.Map(input); - newdata.Doctor = await _doctorRepository.GetAsync(input.DoctorId.Value); - appointment = newdata; - appointment = await _appointmentsRepository.UpdateAsync(appointment); - return ObjectMapper.Map(appointment); + try + { + //var appointment = await _appointmentsRepository.GetAsync(input.Id); + Appointment appointment = new Appointment(); + var newdata = ObjectMapper.Map(input); + newdata.Doctor = await _doctorRepository.GetAsync(input.DoctorId.Value); + appointment = newdata; + appointment = await _appointmentsRepository.UpdateAsync(appointment); + } + catch (Exception ex) + { + throw new Exception(ex.Message); + } } #endregion @@ -114,5 +127,67 @@ namespace HospitalManagementSystem.Appointments await _appointmentsRepository.DeleteAsync(id); } #endregion + #region Export Appointment Data to Excel + public async Task GetExportAppointmentRecordAsync() + { + var Appointmentrecord = await _appointmentsRepository.GetQueryableAsync().Result.ToListAsync(); + + var folderPath = Path.Combine(_env.WebRootPath, "temp"); + if (!Directory.Exists(folderPath)) + { + Directory.CreateDirectory(folderPath); // Ensure the folder exists + } + + var filename = "Appointments_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx"; + var filePath = Path.Combine(folderPath, filename); + + // Create a workbook and worksheet + using (var workbook = new XLWorkbook()) + { + var worksheet = workbook.Worksheets.Add("Appointment"); + + // Add headers + worksheet.Cell(1, 1).Value = "Name"; + worksheet.Cell(1, 2).Value = "Email"; + worksheet.Cell(1, 3).Value = "Gender"; + worksheet.Cell(1, 4).Value = "Date"; + worksheet.Cell(1, 5).Value = "Time"; + worksheet.Cell(1, 6).Value = "Mobile"; + worksheet.Cell(1, 7).Value = "Doctor"; + worksheet.Cell(1, 8).Value = "Injury"; + worksheet.Cell(1, 9).Value = "Appointment Status"; + worksheet.Cell(1, 10).Value = "Visit Type"; + worksheet.Cell(1, 11).Value = "Payment Status"; + worksheet.Cell(1, 12).Value = "Insurance Provider"; + worksheet.Cell(1, 13).Value = "Notes"; + + for (int i = 0; i < Appointmentrecord.Count; i++) + { + //worksheet.Cell(i + 2, 1).Value = Appointmentrecord[i].Patients.Name; + //worksheet.Cell(i + 2, 2).Value = Appointmentrecord[i].Patients.Gender.ToString(); + //worksheet.Cell(i + 2, 3).Value = Appointmentrecord[i].DateOfAdmission.ToShortDateString(); + //worksheet.Cell(i + 2, 4).Value = Appointmentrecord[i].Diagnosis; + //worksheet.Cell(i + 2, 5).Value = Appointmentrecord[i].NextFollowUp?.ToShortDateString(); + //worksheet.Cell(i + 2, 6).Value = Appointmentrecord[i].InsuranceProvider; + //worksheet.Cell(i + 2, 7).Value = Appointmentrecord[i].InsuranceProvider; + //worksheet.Cell(i + 2, 8).Value = Appointmentrecord[i].InsuranceProvider; + //worksheet.Cell(i + 2, 9).Value = Appointmentrecord[i].Status.ToString(); + } + + worksheet.Columns().AdjustToContents(); + workbook.SaveAs(filePath); + } + + byte[] fileBytes = await File.ReadAllBytesAsync(filePath); + File.Delete(filePath); + + return new FileDownloadDto + { + FileName = filename, + FileContent = Convert.ToBase64String(fileBytes) // Use Base64 encoding for file content + }; + } + + #endregion } }