260 lines
7.5 KiB
TypeScript
260 lines
7.5 KiB
TypeScript
import { PermissionService } from '@abp/ng.core';
|
|
import { Confirmation, ConfirmationService, ToasterService } from '@abp/ng.theme.shared';
|
|
import { HttpClient, HttpEventType, HttpParams, HttpRequest } from '@angular/common/http';
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { NgForm } from '@angular/forms';
|
|
import { Router } from '@angular/router';
|
|
import { PagingSortResultDto } from '@proxy/dto';
|
|
import { Gender } from '@proxy/global-enum';
|
|
import { PatientService } from '@proxy/patients';
|
|
import { PatientDto, CreateUpdatePatientDto } from '@proxy/patients/dto';
|
|
import { environment } from 'src/environments/environment';
|
|
|
|
@Component({
|
|
selector: 'app-all-patients',
|
|
templateUrl: './all-patients.component.html',
|
|
styleUrl: './all-patients.component.scss',
|
|
providers: [PatientService, ConfirmationService, ToasterService, PermissionService],
|
|
})
|
|
export class AllPatientsComponent implements OnInit {
|
|
globalFilter: string = '';
|
|
patients: PatientDto[];
|
|
totalRecords: number = 0;
|
|
loading: boolean = false;
|
|
patientDialog: boolean = false;
|
|
selectedPatient: CreateUpdatePatientDto;
|
|
isEditMode: boolean = false;
|
|
patientDialogTitle: string = '';
|
|
params: PagingSortResultDto;
|
|
gender: any;
|
|
selectedgender: any = 0;
|
|
selectadmissionDate: Date = new Date();
|
|
selectdischargeDate: Date = new Date();
|
|
createpermission: boolean;
|
|
editpermission: boolean;
|
|
deletepermission: boolean;
|
|
imgpath: string = '';
|
|
guid: string = '00000000-0000-0000-0000-000000000000';
|
|
uploadProgress = 0;
|
|
|
|
constructor(
|
|
private patientService: PatientService,
|
|
private http: HttpClient,
|
|
private confirmation: ConfirmationService,
|
|
private toaster: ToasterService,
|
|
private permissionChecker: PermissionService,
|
|
private router: Router
|
|
) {}
|
|
|
|
ngOnInit() {
|
|
this.createpermission = this.permissionChecker.getGrantedPolicy(
|
|
'HospitalManagementSystem.Patient.Create'
|
|
);
|
|
this.editpermission = this.permissionChecker.getGrantedPolicy(
|
|
'HospitalManagementSystem.Patient.Edit'
|
|
);
|
|
this.deletepermission = this.permissionChecker.getGrantedPolicy(
|
|
'HospitalManagementSystem.Patient.Delete'
|
|
);
|
|
this.gender = Gender;
|
|
|
|
this.resetselectpatient();
|
|
this.loadPatient({
|
|
first: 0,
|
|
rows: 10,
|
|
sortField: 'id',
|
|
sortOrder: 1,
|
|
globalFilter: null,
|
|
});
|
|
}
|
|
resetselectpatient() {
|
|
this.selectedPatient = {
|
|
name: '',
|
|
gender: Gender.Male,
|
|
mobile: '',
|
|
email: '',
|
|
age: 0,
|
|
address: '',
|
|
bloodGroup: '',
|
|
};
|
|
this.imgpath = '';
|
|
this.selectedgender = 0;
|
|
this.uploadProgress = 0;
|
|
}
|
|
|
|
loadPatient(event: any) {
|
|
this.loading = true;
|
|
let order = event.sortOrder == 1 ? ' asc' : ' desc';
|
|
event.sortField = event.sortField == undefined ? 'id' : event.sortField;
|
|
this.params = {
|
|
skipCount: event.first,
|
|
maxResultCount: event.rows,
|
|
sorting: event.sortField + order,
|
|
search: event.globalFilter == null ? '' : event.globalFilter,
|
|
};
|
|
|
|
this.patientService.getPatientList(this.params).subscribe(data => {
|
|
this.patients = data.items;
|
|
this.totalRecords = data.totalCount;
|
|
this.loading = false;
|
|
});
|
|
}
|
|
|
|
exportPatient() {
|
|
this.patientService.getExportPatientData().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);
|
|
});
|
|
}
|
|
|
|
openNewPatientDialog() {
|
|
this.patientDialogTitle = 'New Patient';
|
|
this.resetselectpatient();
|
|
this.selectedgender = 0;
|
|
this.patientDialog = true;
|
|
this.isEditMode = false;
|
|
}
|
|
|
|
addnewrecord(id: any) {
|
|
this.router.navigate(['/patients/patient-record', id]);
|
|
}
|
|
|
|
profileimageupload(event: Event) {
|
|
const input = event.target as HTMLInputElement;
|
|
if (input.files.length > 0) {
|
|
const tag = 'Image';
|
|
const formdata = new FormData();
|
|
formdata.append('file', input.files[0]);
|
|
this.UploadFileData(tag, formdata);
|
|
} else {
|
|
this.uploadProgress = 0;
|
|
return;
|
|
}
|
|
}
|
|
|
|
UploadFileData(tag: string, formdata: FormData) {
|
|
const req = new HttpRequest(
|
|
'POST',
|
|
environment.apis.default.url + '/api/app/shared/upload-file',
|
|
formdata,
|
|
{
|
|
reportProgress: true,
|
|
responseType: 'text',
|
|
params: new HttpParams().set('tagName', tag),
|
|
}
|
|
);
|
|
this.http.request(req).subscribe(
|
|
event => {
|
|
if (event.type === HttpEventType.UploadProgress) {
|
|
this.uploadProgress = Math.round((event.loaded / event.total!) * 100);
|
|
} else if (event.type === HttpEventType.Response) {
|
|
this.uploadProgress = 100;
|
|
this.selectedPatient.imageID = event.body.toString();
|
|
}
|
|
},
|
|
error => {
|
|
this.uploadProgress = 0;
|
|
}
|
|
);
|
|
}
|
|
|
|
editPatient(Patient: any) {
|
|
this.resetselectpatient();
|
|
this.patientDialogTitle = 'Edit Patient';
|
|
this.patientService.getPatientById(Patient.id).subscribe(result => {
|
|
this.selectedPatient = result;
|
|
this.imgpath = result.imagepath != null ? result.imagepath.split('\\')[3] : '';
|
|
this.selectedgender = this.selectedPatient.gender;
|
|
});
|
|
this.patientDialog = true;
|
|
this.isEditMode = true;
|
|
}
|
|
|
|
deletePatient(id: any) {
|
|
this.confirmation
|
|
.warn('Do you really want to delete this patient?', {
|
|
key: '::AreYouSure',
|
|
defaultValue: 'Are you sure?',
|
|
})
|
|
.subscribe((status: Confirmation.Status) => {
|
|
// your code here
|
|
if (status == 'confirm') {
|
|
this.patientService.deletePatient(id).subscribe(() => {
|
|
this.toaster.success('Patient deleted successfully', 'Success');
|
|
this.loadPatient(this.params);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
savePatient(form: NgForm) {
|
|
if (form.invalid) {
|
|
Object.values(form.controls).forEach(control => control.markAsTouched());
|
|
return;
|
|
}
|
|
this.selectedPatient.gender = this.selectedgender;
|
|
this.selectedPatient.imageID = this.selectedPatient.imageID
|
|
? this.selectedPatient.imageID.replace('"', '').replace('"', '')
|
|
: this.guid;
|
|
|
|
if (this.isEditMode) {
|
|
this.patientService.updatePatient(this.selectedPatient.id, this.selectedPatient).subscribe(
|
|
() => {
|
|
this.toaster.success('Patient updated successfully', 'Success');
|
|
this.patientDialog = false;
|
|
this.loadPatient({
|
|
first: 0,
|
|
rows: 10,
|
|
sortField: 'id',
|
|
sortOrder: 1,
|
|
globalFilter: null,
|
|
});
|
|
},
|
|
error => {
|
|
this.closeDialog();
|
|
}
|
|
);
|
|
} else {
|
|
this.patientService.createPatient(this.selectedPatient).subscribe(
|
|
() => {
|
|
this.toaster.success('Patient created successfully', 'Success');
|
|
this.patientDialog = false;
|
|
this.loadPatient({
|
|
first: 0,
|
|
rows: 10,
|
|
sortField: 'id',
|
|
sortOrder: 1,
|
|
globalFilter: null,
|
|
});
|
|
},
|
|
error => {
|
|
this.closeDialog();
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
closeDialog() {
|
|
this.patientDialog = false;
|
|
}
|
|
}
|