-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
75 changed files
with
1,208 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
apps/hcdc-access-service/src/domain/entity/diagnosis/auth.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import '@casl/mongoose' | ||
|
||
export enum DiagnosisAction { | ||
Create = 'Create', | ||
Read = 'Read', | ||
Update = 'Update', | ||
Delete = 'Delete', | ||
} | ||
|
||
declare module '@casl/mongoose' { | ||
interface RecordTypes { | ||
Diagnosis: true | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
apps/hcdc-access-service/src/domain/entity/diagnosis/entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BaseEntity } from '../base-entity' | ||
import { Branch } from '../branch' | ||
|
||
export type Diagnosis = BaseEntity & { | ||
displayIndex: number | ||
name: string | ||
|
||
branchId: string | ||
branch?: Branch | null | ||
} |
17 changes: 17 additions & 0 deletions
17
apps/hcdc-access-service/src/domain/entity/diagnosis/example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { exampleMongoObjectId } from '@diut/nest-core' | ||
|
||
import { EntityDataExample } from '../base-entity' | ||
import { Diagnosis } from './entity' | ||
|
||
export const exampleDiagnosis = { | ||
displayIndex: { | ||
example: 1, | ||
}, | ||
name: { | ||
example: 'CHIV Advia centaur', | ||
}, | ||
branchId: exampleMongoObjectId, | ||
branch: { | ||
required: false, | ||
}, | ||
} satisfies EntityDataExample<Diagnosis> |
3 changes: 3 additions & 0 deletions
3
apps/hcdc-access-service/src/domain/entity/diagnosis/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './entity' | ||
export * from './example' | ||
export * from './auth' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
apps/hcdc-access-service/src/domain/entity/patient-type/auth.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import '@casl/mongoose' | ||
|
||
export enum PatientTypeAction { | ||
Create = 'Create', | ||
Read = 'Read', | ||
Update = 'Update', | ||
Delete = 'Delete', | ||
} | ||
|
||
declare module '@casl/mongoose' { | ||
interface RecordTypes { | ||
PatientType: true | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
apps/hcdc-access-service/src/domain/entity/patient-type/entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BaseEntity } from '../base-entity' | ||
import { Branch } from '../branch' | ||
|
||
export type PatientType = BaseEntity & { | ||
displayIndex: number | ||
name: string | ||
|
||
branchId: string | ||
branch?: Branch | null | ||
} |
17 changes: 17 additions & 0 deletions
17
apps/hcdc-access-service/src/domain/entity/patient-type/example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { exampleMongoObjectId } from '@diut/nest-core' | ||
|
||
import { EntityDataExample } from '../base-entity' | ||
import { PatientType } from './entity' | ||
|
||
export const examplePatientType = { | ||
displayIndex: { | ||
example: 1, | ||
}, | ||
name: { | ||
example: 'CHIV Advia centaur', | ||
}, | ||
branchId: exampleMongoObjectId, | ||
branch: { | ||
required: false, | ||
}, | ||
} satisfies EntityDataExample<PatientType> |
3 changes: 3 additions & 0 deletions
3
apps/hcdc-access-service/src/domain/entity/patient-type/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './entity' | ||
export * from './example' | ||
export * from './auth' |
6 changes: 6 additions & 0 deletions
6
apps/hcdc-access-service/src/domain/interface/repository/diagnosis.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Diagnosis } from 'src/domain/entity' | ||
import { IRepository } from './interface' | ||
|
||
export const DiagnosisRepositoryToken = Symbol('DiagnosisRepository') | ||
|
||
export interface IDiagnosisRepository extends IRepository<Diagnosis> {} |
2 changes: 2 additions & 0 deletions
2
apps/hcdc-access-service/src/domain/interface/repository/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
apps/hcdc-access-service/src/domain/interface/repository/patient-type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { PatientType } from 'src/domain/entity' | ||
import { IRepository } from './interface' | ||
|
||
export const PatientTypeRepositoryToken = Symbol('PatientTypeRepository') | ||
|
||
export interface IPatientTypeRepository extends IRepository<PatientType> {} |
27 changes: 27 additions & 0 deletions
27
apps/hcdc-access-service/src/domain/use-case/diagnosis/assert-exists.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Inject, Injectable } from '@nestjs/common' | ||
|
||
import { Diagnosis } from 'src/domain/entity' | ||
import { EEntityNotFound } from 'src/domain/exception' | ||
import { | ||
DiagnosisRepositoryToken, | ||
EntityFindOneOptions, | ||
IDiagnosisRepository, | ||
} from 'src/domain/interface' | ||
|
||
@Injectable() | ||
export class DiagnosisAssertExistsUseCase { | ||
constructor( | ||
@Inject(DiagnosisRepositoryToken) | ||
private readonly diagnosisRepository: IDiagnosisRepository, | ||
) {} | ||
|
||
async execute(input: EntityFindOneOptions<Diagnosis>['filter']) { | ||
const rv = await this.diagnosisRepository.findOne({ filter: input }) | ||
|
||
if (rv === null) { | ||
throw new EEntityNotFound(`Diagnosis ${JSON.stringify(input)}`) | ||
} | ||
|
||
return rv | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
apps/hcdc-access-service/src/domain/use-case/diagnosis/authorize-populates.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Inject, Injectable } from '@nestjs/common' | ||
|
||
import { AuthSubject, authorizePopulates } from 'src/domain/auth' | ||
import { BranchAction, Diagnosis } from 'src/domain/entity' | ||
import { EEntityPopulatePathUnknown } from 'src/domain/exception' | ||
import { | ||
AuthContextToken, | ||
EntityFindOneOptions, | ||
IAuthContext, | ||
} from 'src/domain/interface' | ||
|
||
@Injectable() | ||
export class DiagnosisAuthorizePopulatesUseCase { | ||
constructor( | ||
@Inject(AuthContextToken) | ||
private readonly authContext: IAuthContext, | ||
) {} | ||
execute(input: EntityFindOneOptions<Diagnosis>['populates']) { | ||
const { ability } = this.authContext.getData() | ||
|
||
return authorizePopulates(ability, input, (path) => { | ||
switch (path) { | ||
case 'branch': | ||
return { subject: AuthSubject.Branch, action: BranchAction.Read } | ||
default: | ||
throw new EEntityPopulatePathUnknown(path) | ||
} | ||
}) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
apps/hcdc-access-service/src/domain/use-case/diagnosis/create.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Inject, Injectable } from '@nestjs/common' | ||
|
||
import { | ||
AuthContextToken, | ||
DiagnosisRepositoryToken, | ||
IAuthContext, | ||
IDiagnosisRepository, | ||
} from 'src/domain/interface' | ||
import { Diagnosis, DiagnosisAction, EntityData } from 'src/domain/entity' | ||
import { AuthSubject, assertPermission } from 'src/domain/auth' | ||
import { DiagnosisValidateUseCase } from './validate' | ||
|
||
@Injectable() | ||
export class DiagnosisCreateUseCase { | ||
constructor( | ||
@Inject(AuthContextToken) | ||
private readonly authContext: IAuthContext, | ||
@Inject(DiagnosisRepositoryToken) | ||
private readonly diagnosisRepository: IDiagnosisRepository, | ||
private readonly diagnosisValidateUseCase: DiagnosisValidateUseCase, | ||
) {} | ||
|
||
async execute(input: EntityData<Diagnosis>) { | ||
const { ability } = this.authContext.getData() | ||
assertPermission( | ||
ability, | ||
AuthSubject.Diagnosis, | ||
DiagnosisAction.Create, | ||
input, | ||
) | ||
await this.diagnosisValidateUseCase.execute(input) | ||
|
||
const entity = await this.diagnosisRepository.create(input) | ||
|
||
return entity | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
apps/hcdc-access-service/src/domain/use-case/diagnosis/delete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Inject, Injectable } from '@nestjs/common' | ||
|
||
import { DiagnosisAction } from 'src/domain/entity' | ||
import { AuthSubject, assertPermission } from 'src/domain/auth' | ||
import { | ||
AuthContextToken, | ||
DiagnosisRepositoryToken, | ||
IAuthContext, | ||
IDiagnosisRepository, | ||
} from 'src/domain/interface' | ||
import { DiagnosisAssertExistsUseCase } from './assert-exists' | ||
|
||
@Injectable() | ||
export class DiagnosisDeleteUseCase { | ||
constructor( | ||
@Inject(AuthContextToken) | ||
private readonly authContext: IAuthContext, | ||
@Inject(DiagnosisRepositoryToken) | ||
private readonly diagnosisRepository: IDiagnosisRepository, | ||
private readonly diagnosisAssertExistsUseCase: DiagnosisAssertExistsUseCase, | ||
) {} | ||
|
||
async execute(input: { id: string }) { | ||
const entity = await this.diagnosisAssertExistsUseCase.execute({ | ||
_id: input.id, | ||
}) | ||
const { ability } = this.authContext.getData() | ||
assertPermission( | ||
ability, | ||
AuthSubject.Diagnosis, | ||
DiagnosisAction.Delete, | ||
entity, | ||
) | ||
|
||
await this.diagnosisRepository.deleteById(input.id) | ||
|
||
return entity | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
apps/hcdc-access-service/src/domain/use-case/diagnosis/find-one.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Inject, Injectable } from '@nestjs/common' | ||
|
||
import { Diagnosis, DiagnosisAction } from 'src/domain/entity' | ||
import { AuthSubject, assertPermission } from 'src/domain/auth' | ||
import { | ||
AuthContextToken, | ||
DiagnosisRepositoryToken, | ||
EntityFindOneOptions, | ||
IAuthContext, | ||
IDiagnosisRepository, | ||
} from 'src/domain/interface' | ||
import { DiagnosisAuthorizePopulatesUseCase } from './authorize-populates' | ||
|
||
@Injectable() | ||
export class DiagnosisFindOneUseCase { | ||
constructor( | ||
@Inject(DiagnosisRepositoryToken) | ||
private readonly diagnosisRepository: IDiagnosisRepository, | ||
@Inject(AuthContextToken) | ||
private readonly authContext: IAuthContext, | ||
private readonly diagnosisAuthorizePopulatesUseCase: DiagnosisAuthorizePopulatesUseCase, | ||
) {} | ||
|
||
async execute(input: EntityFindOneOptions<Diagnosis>) { | ||
input.populates = this.diagnosisAuthorizePopulatesUseCase.execute( | ||
input.populates, | ||
) | ||
const entity = await this.diagnosisRepository.findOne(input) | ||
const { ability } = this.authContext.getData() | ||
assertPermission( | ||
ability, | ||
AuthSubject.Diagnosis, | ||
DiagnosisAction.Read, | ||
entity, | ||
) | ||
|
||
return entity | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
apps/hcdc-access-service/src/domain/use-case/diagnosis/search.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Inject, Injectable } from '@nestjs/common' | ||
import { accessibleBy } from '@casl/mongoose' | ||
|
||
import { | ||
AuthContextToken, | ||
DiagnosisRepositoryToken, | ||
IAuthContext, | ||
IDiagnosisRepository, | ||
EntitySearchOptions, | ||
} from 'src/domain/interface' | ||
import { Diagnosis, DiagnosisAction } from 'src/domain/entity' | ||
import { AuthSubject, assertPermission } from 'src/domain/auth' | ||
import { DiagnosisAuthorizePopulatesUseCase } from './authorize-populates' | ||
|
||
@Injectable() | ||
export class DiagnosisSearchUseCase { | ||
constructor( | ||
@Inject(DiagnosisRepositoryToken) | ||
private readonly diagnosisRepository: IDiagnosisRepository, | ||
@Inject(AuthContextToken) | ||
private readonly authContext: IAuthContext, | ||
private readonly diagnosisAuthorizePopulatesUseCase: DiagnosisAuthorizePopulatesUseCase, | ||
) {} | ||
|
||
async execute(input: EntitySearchOptions<Diagnosis>) { | ||
const { ability } = this.authContext.getData() | ||
assertPermission(ability, AuthSubject.Diagnosis, DiagnosisAction.Read) | ||
input.populates = this.diagnosisAuthorizePopulatesUseCase.execute( | ||
input.populates, | ||
) | ||
|
||
const paginationResult = await this.diagnosisRepository.search({ | ||
...input, | ||
filter: { | ||
$and: [ | ||
input.filter ?? {}, | ||
accessibleBy(ability, DiagnosisAction.Read).Diagnosis, | ||
], | ||
}, | ||
}) | ||
|
||
return paginationResult | ||
} | ||
} |
Oops, something went wrong.