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
f09c96b8
Commit
f09c96b8
authored
Aug 26, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add get all visits by patient id
parent
f1c6c71b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
193 additions
and
0 deletions
+193
-0
Application.csproj
Clinics.Backend/Application/Application.csproj
+4
-0
GetAllVisitsByPatientIdHandler.cs
...eries/GetAllByPatientId/GetAllVisitsByPatientIdHandler.cs
+29
-0
GetAllVisitsByPatientIdQuery.cs
...Queries/GetAllByPatientId/GetAllVisitsByPatientIdQuery.cs
+8
-0
GetAllVisitsByPatientIdResponse.cs
...ries/GetAllByPatientId/GetAllVisitsByPatientIdResponse.cs
+60
-0
IVisitsRepository.cs
Clinics.Backend/Domain/Repositories/IVisitsRepository.cs
+14
-0
VisitsRepository.cs
...ckend/Persistence/Repositories/Visits/VisitsRepository.cs
+43
-0
VisitsController.cs
Clinics.Backend/Presentation/Controllers/VisitsController.cs
+35
-0
No files found.
Clinics.Backend/Application/Application.csproj
View file @
f09c96b8
...
@@ -14,4 +14,8 @@
...
@@ -14,4 +14,8 @@
<ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<Folder Include="Visits\Commands\" />
</ItemGroup>
</Project>
</Project>
Clinics.Backend/Application/Visits/Queries/GetAllByPatientId/GetAllVisitsByPatientIdHandler.cs
0 → 100644
View file @
f09c96b8
using
Application.Abstractions.CQRS.Queries
;
using
Domain.Repositories
;
using
Domain.Shared
;
namespace
Application.Visits.Queries.GetAllByPatientId
;
public
class
GetAllVisitsByPatientIdHandler
:
IQueryHandler
<
GetAllVisitsByPatientIdQuery
,
GetAllVisitsByPatientIdResponse
>
{
#
region
CTOR
DI
private
readonly
IVisitsRepository
_visitsRepository
;
public
GetAllVisitsByPatientIdHandler
(
IVisitsRepository
visitsRepository
)
{
_visitsRepository
=
visitsRepository
;
}
#
endregion
public
async
Task
<
Result
<
GetAllVisitsByPatientIdResponse
>>
Handle
(
GetAllVisitsByPatientIdQuery
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Fetch
data
from
persistence
var
visitsFromPersistenceResult
=
await
_visitsRepository
.
GetAllByPatientIdAsync
(
request
.
PatientId
);
if
(
visitsFromPersistenceResult
.
IsFailure
)
return
Result
.
Failure
<
GetAllVisitsByPatientIdResponse
>(
visitsFromPersistenceResult
.
Error
);
var
visits
=
visitsFromPersistenceResult
.
Value
;
#
endregion
return
GetAllVisitsByPatientIdResponse
.
GetResponse
(
visits
);
}
}
Clinics.Backend/Application/Visits/Queries/GetAllByPatientId/GetAllVisitsByPatientIdQuery.cs
0 → 100644
View file @
f09c96b8
using
Application.Abstractions.CQRS.Queries
;
namespace
Application.Visits.Queries.GetAllByPatientId
;
public
class
GetAllVisitsByPatientIdQuery
:
IQuery
<
GetAllVisitsByPatientIdResponse
>
{
public
int
PatientId
{
get
;
set
;
}
}
Clinics.Backend/Application/Visits/Queries/GetAllByPatientId/GetAllVisitsByPatientIdResponse.cs
0 → 100644
View file @
f09c96b8
using
Domain.Entities.Visits
;
using
Domain.Entities.Visits.Relations.VisitMedicines
;
namespace
Application.Visits.Queries.GetAllByPatientId
;
public
class
GetAllVisitsByPatientIdResponse
{
public
class
MedicineView
{
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Form
{
get
;
set
;
}
=
null
!;
public
int
Amount
{
get
;
set
;
}
public
decimal
Dosage
{
get
;
set
;
}
public
int
Number
{
get
;
set
;
}
// Number in visit
}
public
class
GetAllVisitsByPatientIdResponseItem
{
public
string
DoctorName
{
get
;
set
;
}
=
null
!;
public
string
Diagnosis
{
get
;
set
;
}
=
null
!;
public
DateOnly
Date
{
get
;
set
;
}
public
ICollection
<
MedicineView
>
Medicines
{
get
;
set
;
}
=
null
!;
}
public
ICollection
<
GetAllVisitsByPatientIdResponseItem
>
Visits
{
get
;
set
;
}
=
null
!;
public
static
GetAllVisitsByPatientIdResponse
GetResponse
(
ICollection
<
Visit
>
visits
)
{
List
<
GetAllVisitsByPatientIdResponseItem
>
result
=
new
();
foreach
(
Visit
visit
in
visits
)
{
List
<
MedicineView
>
medicinesItem
=
new
();
foreach
(
VisitMedicine
visitMedicine
in
visit
.
Medicines
)
{
medicinesItem
.
Add
(
new
MedicineView
{
Name
=
visitMedicine
.
Medicine
.
Name
,
Form
=
visitMedicine
.
Medicine
.
MedicineForm
.
Name
,
Amount
=
visitMedicine
.
Medicine
.
Amount
,
Dosage
=
visitMedicine
.
Medicine
.
Dosage
,
Number
=
visitMedicine
.
Number
});
}
result
.
Add
(
new
GetAllVisitsByPatientIdResponseItem
{
DoctorName
=
visit
.
Doctor
.
PersonalInfo
.
FullName
,
Diagnosis
=
visit
.
Diagnosis
,
Date
=
visit
.
Date
,
Medicines
=
medicinesItem
});
}
return
new
GetAllVisitsByPatientIdResponse
{
Visits
=
result
};
}
}
Clinics.Backend/Domain/Repositories/IVisitsRepository.cs
0 → 100644
View file @
f09c96b8
using
Domain.Entities.Visits
;
using
Domain.Repositories.Base
;
using
Domain.Shared
;
namespace
Domain.Repositories
;
public
interface
IVisitsRepository
:
IRepository
<
Visit
>
{
#
region
Get
all
by
patient
id
public
Task
<
Result
<
ICollection
<
Visit
>>>
GetAllByPatientIdAsync
(
int
patientId
);
#
endregion
}
Clinics.Backend/Persistence/Repositories/Visits/VisitsRepository.cs
0 → 100644
View file @
f09c96b8
using
Domain.Entities.Visits
;
using
Domain.Errors
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
using
Persistence.Repositories.Base
;
namespace
Persistence.Repositories.Visits
;
public
class
VisitsRepository
:
Repositroy
<
Visit
>,
IVisitsRepository
{
#
region
CTOR
DI
For
context
public
VisitsRepository
(
ClinicsDbContext
context
)
:
base
(
context
)
{
}
#
endregion
#
region
Get
all
by
patient
id
public
async
Task
<
Result
<
ICollection
<
Visit
>>>
GetAllByPatientIdAsync
(
int
patientId
)
{
try
{
var
query
=
_context
.
Set
<
Visit
>()
.
Where
(
visit
=>
visit
.
PatientId
==
patientId
)
.
OrderByDescending
(
visit
=>
visit
.
Date
)
.
Include
(
visit
=>
visit
.
Doctor
)
.
ThenInclude
(
doctor
=>
doctor
.
PersonalInfo
)
.
Include
(
visit
=>
visit
.
Medicines
)
.
ThenInclude
(
visitMedicine
=>
visitMedicine
.
Medicine
)
.
ThenInclude
(
medicine
=>
medicine
.
MedicineForm
);
var
results
=
await
query
.
ToListAsync
();
return
results
;
}
catch
(
Exception
)
{
return
Result
.
Failure
<
ICollection
<
Visit
>>(
PersistenceErrors
.
Unknown
);
}
}
#
endregion
}
Clinics.Backend/Presentation/Controllers/VisitsController.cs
0 → 100644
View file @
f09c96b8
using
Application.Doctors.Commands.ChangeStatusByUserId
;
using
Application.Doctors.Queries.GetAllDoctors
;
using
Application.Doctors.Queries.GetStatusByUserId
;
using
Application.Employees.Queries.GetAvailable
;
using
Application.Visits.Queries.GetAllByPatientId
;
using
Domain.Entities.Identity.UserRoles
;
using
MediatR
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Mvc
;
using
Presentation.Controllers.Base
;
namespace
Presentation.Controllers
;
[Route("api/Doctors")]
public
class
VisitsController
:
ApiController
{
#
region
DI
for
MeditR
sender
public
VisitsController
(
ISender
sender
)
:
base
(
sender
)
{
}
#
endregion
//[Authorize(Roles = Roles.DoctorName)]
[
HttpGet
(
"{id:int}"
)]
public
async
Task
<
IActionResult
>
GetAllByPatientId
([
FromRoute
(
Name
=
"id"
)]
int
patientId
)
{
GetAllVisitsByPatientIdQuery
query
=
new
GetAllVisitsByPatientIdQuery
{
PatientId
=
patientId
};
var
result
=
await
_sender
.
Send
(
query
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
(
result
.
Value
);
}
}
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