Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
HIAST-Clinics
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
almohanad.hafez
HIAST-Clinics
Commits
71900f50
Commit
71900f50
authored
Aug 25, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add send to doctor command
parent
a741124b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
128 additions
and
2 deletions
+128
-2
SendWaitingListRecordToDoctorCommand.cs
...istRecordToDoctor/SendWaitingListRecordToDoctorCommand.cs
+10
-0
SendWaitingListRecordToDoctorHandler.cs
...istRecordToDoctor/SendWaitingListRecordToDoctorHandler.cs
+72
-0
IDoctorsRepository.cs
Clinics.Backend/Domain/Repositories/IDoctorsRepository.cs
+6
-1
DoctorsRepository.cs
...end/Persistence/Repositories/Doctors/DoctorsRepository.cs
+30
-1
WaitingListController.cs
...Backend/Presentation/Controllers/WaitingListController.cs
+10
-0
No files found.
Clinics.Backend/Application/WaitingList/Commands/SendWaitingListRecordToDoctor/SendWaitingListRecordToDoctorCommand.cs
0 → 100644
View file @
71900f50
using
Application.Abstractions.CQRS.Commands
;
namespace
Application.WaitingList.Commands.SendWaitingListRecordToDoctor
;
public
class
SendWaitingListRecordToDoctorCommand
:
ICommand
{
public
int
WaitingListRecordId
{
get
;
set
;
}
public
int
PatientId
{
get
;
set
;
}
public
int
DoctorId
{
get
;
set
;
}
}
Clinics.Backend/Application/WaitingList/Commands/SendWaitingListRecordToDoctor/SendWaitingListRecordToDoctorHandler.cs
0 → 100644
View file @
71900f50
using
Application.Abstractions.CQRS.Commands
;
using
Application.Abstractions.Notifications.Doctors
;
using
Application.Abstractions.Notifications.Doctors.NewVisitNotifications
;
using
Domain.Entities.People.Doctors.Shared.DoctorStatusValues
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
namespace
Application.WaitingList.Commands.SendWaitingListRecordToDoctor
;
public
class
SendWaitingListRecordToDoctorHandler
:
CommandHandlerBase
<
SendWaitingListRecordToDoctorCommand
>
{
#
region
CTOR
DI
private
readonly
IPatientsRepository
_patientsRepository
;
private
readonly
IUserRepository
_userRepository
;
private
readonly
IDoctorsRepository
_doctorsRepository
;
private
readonly
IWaitingListRepository
_waitingListRepository
;
private
readonly
IDoctorsNotificationService
_doctorsNotificationService
;
public
SendWaitingListRecordToDoctorHandler
(
IUnitOfWork
unitOfWork
,
IPatientsRepository
patientsRepository
,
IUserRepository
userRepository
,
IDoctorsRepository
doctorsRepository
,
IWaitingListRepository
waitingListRepository
,
IDoctorsNotificationService
doctorsNotificationService
)
:
base
(
unitOfWork
)
{
_patientsRepository
=
patientsRepository
;
_userRepository
=
userRepository
;
_doctorsRepository
=
doctorsRepository
;
_waitingListRepository
=
waitingListRepository
;
_doctorsNotificationService
=
doctorsNotificationService
;
}
#
endregion
public
override
async
Task
<
Result
>
HandleHelper
(
SendWaitingListRecordToDoctorCommand
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Delete
record
var
recordFromPersistence
=
await
_waitingListRepository
.
GetByIdAsync
(
request
.
WaitingListRecordId
);
if
(
recordFromPersistence
.
IsFailure
)
return
Result
.
Failure
(
recordFromPersistence
.
Error
);
var
record
=
recordFromPersistence
.
Value
;
await
_waitingListRepository
.
DeleteAsync
(
record
);
#
endregion
#
region
2.
Set
doctor
status
to
working
var
doctorFromPersistence
=
await
_doctorsRepository
.
GetByIdAsync
(
request
.
DoctorId
);
if
(
doctorFromPersistence
.
IsFailure
)
return
Result
.
Failure
(
doctorFromPersistence
.
Error
);
var
doctor
=
doctorFromPersistence
.
Value
;
doctor
.
ChangeStatusTo
(
DoctorStatuses
.
Working
);
var
changeStatusResult
=
await
_doctorsRepository
.
UpdateAsync
(
doctor
);
if
(
changeStatusResult
.
IsFailure
)
return
Result
.
Failure
(
changeStatusResult
.
Error
);
#
endregion
#
region
3.
Get
doctor
user
var
doctorUserFromPersistence
=
await
_doctorsRepository
.
GetUserByIdAsync
(
request
.
DoctorId
);
if
(
doctorUserFromPersistence
.
IsFailure
)
return
Result
.
Failure
(
doctorUserFromPersistence
.
Error
);
var
doctorUser
=
doctorUserFromPersistence
.
Value
;
#
endregion
#
region
4.
Get
patient
var
patientFromPersistence
=
await
_patientsRepository
.
GetByIdFullAsync
(
request
.
PatientId
);
if
(
patientFromPersistence
.
IsFailure
)
return
Result
.
Failure
(
patientFromPersistence
.
Error
);
var
patient
=
patientFromPersistence
.
Value
;
#
endregion
#
region
5.
Send
notification
var
notification
=
NewVisitNotification
.
Create
(
request
.
PatientId
,
patient
.
PersonalInfo
.
FirstName
,
request
.
DoctorId
,
doctorUser
.
Id
);
await
_doctorsNotificationService
.
SendNewVisitNotification
(
notification
);
#
endregion
return
Result
.
Success
();
}
}
Clinics.Backend/Domain/Repositories/IDoctorsRepository.cs
View file @
71900f50
using
Domain.Entities.People.Doctors
;
using
Domain.Entities.Identity.Users
;
using
Domain.Entities.People.Doctors
;
using
Domain.Repositories.Base
;
using
Domain.Shared
;
...
...
@@ -9,4 +10,8 @@ public interface IDoctorsRepository : IRepository<Doctor>
#
region
Get
available
public
Task
<
Result
<
ICollection
<
Doctor
>>>
GetAvailableDoctors
();
#
endregion
#
region
Get
user
public
Task
<
Result
<
DoctorUser
>>
GetUserByIdAsync
(
int
id
);
#
endregion
}
Clinics.Backend/Persistence/Repositories/Doctors/DoctorsRepository.cs
View file @
71900f50
using
Domain.Entities.People.Doctors
;
using
Domain.Entities.Identity.Users
;
using
Domain.Entities.People.Doctors
;
using
Domain.Entities.People.Doctors.Shared.DoctorStatusValues
;
using
Domain.Errors
;
using
Domain.Repositories
;
...
...
@@ -34,6 +35,14 @@ public class DoctorsRepository : Repositroy<Doctor>, IDoctorsRepository
}
#
endregion
#
region
Update
method
public
override
Task
<
Result
>
UpdateAsync
(
Doctor
entity
)
{
_context
.
Entry
(
entity
.
Status
).
State
=
EntityState
.
Unchanged
;
return
base
.
UpdateAsync
(
entity
);
}
#
endregion
#
region
Get
available
public
async
Task
<
Result
<
ICollection
<
Doctor
>>>
GetAvailableDoctors
()
{
...
...
@@ -52,4 +61,24 @@ public class DoctorsRepository : Repositroy<Doctor>, IDoctorsRepository
}
}
#
endregion
#
region
Get
user
public
async
Task
<
Result
<
DoctorUser
>>
GetUserByIdAsync
(
int
id
)
{
try
{
var
query
=
_context
.
Set
<
DoctorUser
>()
.
Include
(
doctorUser
=>
doctorUser
.
Doctor
)
.
Where
(
doctorUser
=>
doctorUser
.
Doctor
.
Id
==
id
)
.
Include
(
doctorUser
=>
doctorUser
.
User
);
var
result
=
await
query
.
FirstAsync
();
return
result
;
}
catch
(
Exception
)
{
return
Result
.
Failure
<
DoctorUser
>(
PersistenceErrors
.
NotFound
);
}
}
#
endregion
}
Clinics.Backend/Presentation/Controllers/WaitingListController.cs
View file @
71900f50
...
...
@@ -2,6 +2,7 @@
using
Application.Employees.Commands.CreateEmployee
;
using
Application.WaitingList.Commands.CreateWaitingListRecord
;
using
Application.WaitingList.Commands.DeleteWaitingListRecord
;
using
Application.WaitingList.Commands.SendWaitingListRecordToDoctor
;
using
Application.WaitingList.Queries
;
using
Domain.Entities.Identity.UserRoles
;
using
MediatR
;
...
...
@@ -56,4 +57,13 @@ public class WaitingListController : ApiController
return
Ok
();
}
[
HttpPost
(
"SendToDoctor"
)]
public
async
Task
<
IActionResult
>
SendToDoctor
([
FromBody
]
SendWaitingListRecordToDoctorCommand
command
)
{
var
result
=
await
_sender
.
Send
(
command
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment