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
85e98ac3
Commit
85e98ac3
authored
Aug 27, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add create visit command
parent
11a6100c
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
119 additions
and
7 deletions
+119
-7
Application.csproj
Clinics.Backend/Application/Application.csproj
+0
-1
ChangeStatusByUserIdHandler.cs
...mands/ChangeStatusByUserId/ChangeStatusByUserIdHandler.cs
+2
-0
CreateVisitCommand.cs
.../Application/Visits/Commands/Create/CreateVisitCommand.cs
+16
-0
CreateVisitCommandHandler.cs
...ation/Visits/Commands/Create/CreateVisitCommandHandler.cs
+59
-0
Visit.cs
Clinics.Backend/Domain/Entities/Visits/Visit.cs
+6
-6
IUserRepository.cs
Clinics.Backend/Domain/Repositories/IUserRepository.cs
+5
-0
UserRepository.cs
....Backend/Persistence/Repositories/Users/UserRepository.cs
+20
-0
VisitsController.cs
Clinics.Backend/Presentation/Controllers/VisitsController.cs
+11
-0
No files found.
Clinics.Backend/Application/Application.csproj
View file @
85e98ac3
...
...
@@ -17,6 +17,5 @@
<ItemGroup>
<Folder Include="Medicines\Commands\" />
<Folder Include="Visits\Commands\" />
</ItemGroup>
</Project>
Clinics.Backend/Application/Doctors/Commands/ChangeStatusByUserId/ChangeStatusByUserIdHandler.cs
View file @
85e98ac3
...
...
@@ -29,6 +29,8 @@ public class ChangeStatusByUserIdHandler : CommandHandlerBase<ChangeStatusByUser
#
endregion
#
region
2.
Change
status
if
(
request
.
Status
==
doctor
.
Status
.
Name
)
return
Result
.
Success
();
var
changeStatusResult
=
doctor
.
ChangeStatusTo
(
request
.
Status
);
if
(
changeStatusResult
.
IsFailure
)
return
Result
.
Failure
(
changeStatusResult
.
Error
);
...
...
Clinics.Backend/Application/Visits/Commands/Create/CreateVisitCommand.cs
0 → 100644
View file @
85e98ac3
using
Application.Abstractions.CQRS.Commands
;
namespace
Application.Visits.Commands.Create
;
public
class
CreateVisitCommand
:
ICommand
{
public
class
CreateVisitCommandItem
{
public
int
MedicineId
{
get
;
set
;
}
public
int
Number
{
get
;
set
;
}
}
public
int
DoctorUserId
{
get
;
set
;
}
public
int
PatientId
{
get
;
set
;
}
public
string
Diagnosis
{
get
;
set
;
}
=
null
!;
public
ICollection
<
CreateVisitCommandItem
>
Medicines
{
get
;
set
;
}
=
null
!;
}
Clinics.Backend/Application/Visits/Commands/Create/CreateVisitCommandHandler.cs
0 → 100644
View file @
85e98ac3
using
Application.Abstractions.CQRS.Commands
;
using
Domain.Entities.Visits
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
namespace
Application.Visits.Commands.Create
;
public
class
CreateVisitCommandHandler
:
CommandHandlerBase
<
CreateVisitCommand
>
{
#
region
CTOR
DI
private
readonly
IUserRepository
_userRepository
;
private
readonly
IVisitsRepository
_visitsRepository
;
public
CreateVisitCommandHandler
(
IUnitOfWork
unitOfWork
,
IUserRepository
userRepository
,
IVisitsRepository
visitsRepository
)
:
base
(
unitOfWork
)
{
_userRepository
=
userRepository
;
_visitsRepository
=
visitsRepository
;
}
#
endregion
public
override
async
Task
<
Result
>
HandleHelper
(
CreateVisitCommand
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
doctor
from
persistence
var
doctorFromPersistenceResult
=
await
_userRepository
.
GetDoctorByDoctorUserIdAsync
(
request
.
DoctorUserId
);
if
(
doctorFromPersistenceResult
.
IsFailure
)
return
Result
.
Failure
(
doctorFromPersistenceResult
.
Error
);
var
doctorId
=
doctorFromPersistenceResult
.
Value
.
Id
;
#
endregion
#
region
2.
Create
visit
var
createVisitResult
=
Visit
.
Create
(
request
.
PatientId
,
doctorId
,
DateOnly
.
FromDateTime
(
DateTime
.
Today
),
request
.
Diagnosis
);
if
(
createVisitResult
.
IsFailure
)
return
Result
.
Failure
(
createVisitResult
.
Error
);
var
saveVisitToPersistenceResult
=
await
_visitsRepository
.
CreateAsync
(
createVisitResult
.
Value
);
if
(
saveVisitToPersistenceResult
.
IsFailure
)
return
Result
.
Failure
(
saveVisitToPersistenceResult
.
Error
);
var
visit
=
saveVisitToPersistenceResult
.
Value
;
#
endregion
#
region
3.
Add
medicines
to
visit
foreach
(
var
medicine
in
request
.
Medicines
)
{
var
addResult
=
visit
.
AddMedicine
(
medicine
.
MedicineId
,
medicine
.
Number
);
if
(
addResult
.
IsFailure
)
return
Result
.
Failure
(
addResult
.
Error
);
}
#
endregion
#
region
4.
Save
visit
to
persistence
var
saveResult
=
await
_visitsRepository
.
UpdateAsync
(
visit
);
if
(
saveResult
.
IsFailure
)
return
Result
.
Failure
(
saveResult
.
Error
);
#
endregion
return
Result
.
Success
();
}
}
Clinics.Backend/Domain/Entities/Visits/Visit.cs
View file @
85e98ac3
...
...
@@ -140,18 +140,18 @@ public sealed class Visit : Entity
#
endregion
#
region
Add
medicine
public
Result
AddMedicine
(
Medicine
medicine
,
int
number
)
public
Result
AddMedicine
(
int
medicineId
,
int
number
)
{
#
region
Create
medicine
to
attach
Result
<
VisitMedicine
>
entry
=
VisitMedicine
.
Create
(
Id
,
medicine
.
Id
,
number
);
Result
<
VisitMedicine
>
entry
=
VisitMedicine
.
Create
(
Id
,
medicineId
,
number
);
if
(
entry
.
IsFailure
)
return
Result
.
Failure
(
entry
.
Error
);
#
endregion
#
region
Check
duplicate
if
(
Medicines
.
Where
(
m
=>
m
.
Medicine
==
medicine
).
ToList
().
Count
>
0
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
VisitAlreadyHasThisMedicine
);
#
endregion
//
#region Check duplicate
//if (Medicines.Where(m => m.Medicine.Id == medicineId
).ToList().Count > 0)
//
return Result.Failure(Errors.DomainErrors.VisitAlreadyHasThisMedicine);
//
#endregion
_medicines
.
Add
(
entry
.
Value
);
return
Result
.
Success
();
...
...
Clinics.Backend/Domain/Repositories/IUserRepository.cs
View file @
85e98ac3
using
Domain.Entities.Identity.Users
;
using
Domain.Entities.People.Doctors
;
using
Domain.Repositories.Base
;
using
Domain.Shared
;
...
...
@@ -48,6 +49,10 @@ public interface IUserRepository : IRepository<User>
public
Task
<
Result
>
UpdateDoctorUserAsync
(
DoctorUser
doctorUser
);
#
endregion
#
region
Get
Doctor
by
doctor
user
public
Task
<
Result
<
Doctor
>>
GetDoctorByDoctorUserIdAsync
(
int
doctorUserId
);
#
endregion
#
endregion
#
region
Receptionists
users
...
...
Clinics.Backend/Persistence/Repositories/Users/UserRepository.cs
View file @
85e98ac3
using
Domain.Entities.Identity.Users
;
using
Domain.Entities.People.Doctors
;
using
Domain.Errors
;
using
Domain.Repositories
;
using
Domain.Shared
;
...
...
@@ -215,6 +216,25 @@ public class UserRepository : Repositroy<User>, IUserRepository
}
#
endregion
#
region
Get
Doctor
by
doctor
user
public
async
Task
<
Result
<
Doctor
>>
GetDoctorByDoctorUserIdAsync
(
int
doctorUserId
)
{
try
{
var
query
=
_context
.
Set
<
DoctorUser
>()
.
Where
(
doctorUser
=>
doctorUser
.
Id
==
doctorUserId
)
.
Include
(
doctorUser
=>
doctorUser
.
Doctor
);
var
result
=
await
query
.
FirstAsync
();
return
result
.
Doctor
;
}
catch
(
Exception
)
{
return
Result
.
Failure
<
Doctor
>(
PersistenceErrors
.
NotFound
);
}
}
#
endregion
#
endregion
#
region
Receptionist
users
...
...
Clinics.Backend/Presentation/Controllers/VisitsController.cs
View file @
85e98ac3
...
...
@@ -2,6 +2,7 @@
using
Application.Doctors.Queries.GetAllDoctors
;
using
Application.Doctors.Queries.GetStatusByUserId
;
using
Application.Employees.Queries.GetAvailable
;
using
Application.Visits.Commands.Create
;
using
Application.Visits.Queries.GetAllByPatientId
;
using
Domain.Entities.Identity.UserRoles
;
using
MediatR
;
...
...
@@ -32,4 +33,14 @@ public class VisitsController : ApiController
return
Ok
(
result
.
Value
);
}
//[Authorize(Roles = Roles.DoctorName)]
[
HttpPost
]
public
async
Task
<
IActionResult
>
Create
([
FromBody
]
CreateVisitCommand
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