Commit 5446ed83 authored by Almouhannad's avatar Almouhannad

(F) add send to doctor

parent 71900f50
......@@ -11,7 +11,7 @@
<!-- #region Name-->
<div class="custom-user-full-name">
<h3 style="border:none;">{{doctor.fullName}}</h3>
<h3 style="border:none;">د. {{doctor.fullName}}</h3>
</div>
<!-- #endregion -->
......
......@@ -31,7 +31,7 @@
<div class="d-grid gap-3 custom-edit-button">
<a>
<button class="btn btn-outline-secondary" style="width: 100%;"
(click)="openModal(SendToDoctorModal)">
(click)="onClickSend(); openModal(SendToDoctorModal)">
إرسال إلى طبيب<i class="fas fa-arrow-left"></i>
</button>
</a>
......@@ -88,7 +88,7 @@
<select class="text-center mb-3 form-control"
[(ngModel)]="selectedDoctorId">
<option value="-1" disabled>يرجى اختيار الطبيب</option>
<option *ngFor="let doctor of doctors" [ngValue]="doctor.id">{{doctor.name}}</option>
<option *ngFor="let doctor of doctors" [ngValue]="doctor.id">د. {{doctor.name}}</option>
</select>
</div>
......
......@@ -3,6 +3,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { WaitingListRecord } from '../../../classes/waitingList/waiting-list-record';
import { WaitingListService } from '../../../services/waitingList/waiting-list.service';
import { ToastrService } from 'ngx-toastr';
import { DoctorsService } from '../../../services/doctors/doctors.service';
@Component({
selector: 'app-waiting-list-item',
......@@ -13,7 +14,8 @@ export class WaitingListItemComponent {
constructor(private modalService: NgbModal,
private waitingListService: WaitingListService,
private toastrService: ToastrService
private toastrService: ToastrService,
private doctorsService: DoctorsService
) {}
@Input("model") model: WaitingListRecord = new WaitingListRecord(0,0,'',true, new Date(Date.now()));
......@@ -49,15 +51,31 @@ export class WaitingListItemComponent {
})
}
selectedDoctorId: number = -1;
doctors: {id: number, name:string}[] = [
{id: 1, name: 'A'},
{id: 2, name: 'B'},
{id: 3, name: 'C'},
{id: 4, name: 'D'},
{id: 5, name: 'E'},
]
doctors: {id: number, name:string}[] = []
onClickSend(): void {
this.doctorsService.getAvailable()
.subscribe(result => {
if (result === null) {
this.toastrService.error('حدثت مشكلة، يرجى إعادة المحاولة');
}
else {
this.doctors = result;
}
})
}
onSendToDoctor(): void {
console.log(this.selectedDoctorId);
this.waitingListService.SendToDoctor(this.model.id, this.model.patientId, this.selectedDoctorId)
.subscribe(result => {
if (result.status === true) {
this.toastrService.success('تم الإرسال بنجاح ✔');
this.deleted.emit();
}
else {
this.toastrService.error('حدثت مشكلة، يرجى اعادة المحاولة');
}
})
}
}
......@@ -25,4 +25,17 @@ export class DoctorsService {
})
)
}
getAvailable(): Observable< {id: number, name: string}[] | null > {
return this.http.get<{availableDoctors: {id: number, name: string}[] }>(`${this.DOCTORS_ENDPOINT}/Available`)
.pipe(
map((result) => {
return result.availableDoctors;
}),
catchError((error: HttpErrorResponse) => {
console.error(error.error.detail);
return of (null);
})
);
}
}
......@@ -51,4 +51,23 @@ export class WaitingListService {
);
}
public SendToDoctor(waitingListRecordId: number,
patientId: number, doctorId: number) : Observable<{ status: boolean, errorMessage: string | null }> {
var body: any = {
waitingListRecordId: waitingListRecordId,
patientId: patientId,
doctorId: doctorId
}
return this.http.post(`${this.WAITINGLIST_ENDPOINT}/SendToDoctor`, body)
.pipe(
map(_ => {
return {status: true, errorMessage: null};
}),
catchError((error: HttpErrorResponse) => {
console.error(error.error.detail);
return of({status: false, errorMessage: error.error.detail})
})
);
}
}
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