diff --git a/apps/hcdc-access-service/src/domain/auth/action.ts b/apps/hcdc-access-service/src/domain/auth/action.ts index 204e1a8f..5c620cb8 100644 --- a/apps/hcdc-access-service/src/domain/auth/action.ts +++ b/apps/hcdc-access-service/src/domain/auth/action.ts @@ -8,8 +8,10 @@ import { DoctorAction, InstrumentAction, PatientTypeAction, + PrintFormAction, RoleAction, SampleTypeAction, + TestAction, TestCategoryAction, UserAction, } from '../entity' @@ -26,6 +28,8 @@ export const AuthAction = { Doctor: stringEnumValues(DoctorAction), PatientType: stringEnumValues(PatientTypeAction), Diagnosis: stringEnumValues(DiagnosisAction), + PrintForm: stringEnumValues(PrintFormAction), + Test: stringEnumValues(TestAction), } satisfies Record export const AuthActionValues = [ diff --git a/apps/hcdc-access-service/src/domain/auth/subject.ts b/apps/hcdc-access-service/src/domain/auth/subject.ts index 1a7b2d60..d8f9773b 100644 --- a/apps/hcdc-access-service/src/domain/auth/subject.ts +++ b/apps/hcdc-access-service/src/domain/auth/subject.ts @@ -7,8 +7,10 @@ import { Doctor, Instrument, PatientType, + PrintForm, Role, SampleType, + Test, TestCategory, User, } from '../entity' @@ -26,6 +28,8 @@ export const AuthSubject = { Doctor: 'Doctor', PatientType: 'PatientType', Diagnosis: 'Diagnosis', + PrintForm: 'PrintForm', + Test: 'Test', } satisfies Record export type AuthSubjectUnionType = keyof typeof AuthSubject @@ -46,4 +50,6 @@ export type SubjectEntityMapping = { Doctor: Doctor PatientType: PatientType Diagnosis: Diagnosis + PrintForm: PrintForm + Test: Test } diff --git a/apps/hcdc-access-service/src/domain/entity/branch/entity.ts b/apps/hcdc-access-service/src/domain/entity/branch/entity.ts index e4681dc7..d3bd21f1 100644 --- a/apps/hcdc-access-service/src/domain/entity/branch/entity.ts +++ b/apps/hcdc-access-service/src/domain/entity/branch/entity.ts @@ -1,5 +1,3 @@ -import { stringEnumValues } from '@diut/common' - import { BaseEntity } from '../base-entity' export enum BranchType { @@ -7,8 +5,6 @@ export enum BranchType { External = 'External', } -export const BranchTypeValues = stringEnumValues(BranchType) - export type Branch = BaseEntity & { displayIndex: number name: string diff --git a/apps/hcdc-access-service/src/domain/entity/index.ts b/apps/hcdc-access-service/src/domain/entity/index.ts index 311b76b0..452d42c5 100644 --- a/apps/hcdc-access-service/src/domain/entity/index.ts +++ b/apps/hcdc-access-service/src/domain/entity/index.ts @@ -11,3 +11,5 @@ export * from './role' export * from './user' export * from './branch' export * from './permission-rule' +export * from './print-form' +export * from './test' diff --git a/apps/hcdc-access-service/src/domain/entity/print-form/auth.ts b/apps/hcdc-access-service/src/domain/entity/print-form/auth.ts new file mode 100644 index 00000000..63d73e05 --- /dev/null +++ b/apps/hcdc-access-service/src/domain/entity/print-form/auth.ts @@ -0,0 +1,14 @@ +import '@casl/mongoose' + +export enum PrintFormAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} + +declare module '@casl/mongoose' { + interface RecordTypes { + PrintForm: true + } +} diff --git a/apps/hcdc-access-service/src/domain/entity/print-form/entity.ts b/apps/hcdc-access-service/src/domain/entity/print-form/entity.ts new file mode 100644 index 00000000..54f33a01 --- /dev/null +++ b/apps/hcdc-access-service/src/domain/entity/print-form/entity.ts @@ -0,0 +1,25 @@ +import { BaseEntity } from '../base-entity' +import { Branch } from '../branch' + +export enum PrintTemplate { + FormChung = 'FormChung', + FormHIV = 'FormHIV', + FormPap = 'FormPap', + FormSoiNhuom = 'FormSoiNhuom', + FormTD = 'FormTD', +} + +export type PrintForm = BaseEntity & { + displayIndex: number + name: string + isA4: boolean + isAuthorLocked: boolean + authorTitle: string + authorName: string + titleMargin: number + + template: PrintTemplate + + branchId: string + branch?: Branch | null +} diff --git a/apps/hcdc-access-service/src/domain/entity/print-form/example.ts b/apps/hcdc-access-service/src/domain/entity/print-form/example.ts new file mode 100644 index 00000000..e6b1a29b --- /dev/null +++ b/apps/hcdc-access-service/src/domain/entity/print-form/example.ts @@ -0,0 +1,29 @@ +import { exampleMongoObjectId } from '@diut/nest-core' + +import { EntityDataExample } from '../base-entity' +import { PrintForm, PrintTemplate } from './entity' + +export const examplePrintForm = { + displayIndex: { + example: 1, + }, + name: { + example: 'CHIV Advia centaur', + }, + isA4: {}, + isAuthorLocked: {}, + authorTitle: { + example: 'Chức vụ', + }, + authorName: { + example: 'Nguyễn Văn A', + }, + titleMargin: { example: 12 }, + template: { + enum: PrintTemplate, + }, + branchId: exampleMongoObjectId, + branch: { + required: false, + }, +} satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/domain/entity/print-form/index.ts b/apps/hcdc-access-service/src/domain/entity/print-form/index.ts new file mode 100644 index 00000000..3b1b1117 --- /dev/null +++ b/apps/hcdc-access-service/src/domain/entity/print-form/index.ts @@ -0,0 +1,3 @@ +export * from './entity' +export * from './example' +export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/entity/test/auth.ts b/apps/hcdc-access-service/src/domain/entity/test/auth.ts new file mode 100644 index 00000000..61f945ec --- /dev/null +++ b/apps/hcdc-access-service/src/domain/entity/test/auth.ts @@ -0,0 +1,14 @@ +import '@casl/mongoose' + +export enum TestAction { + Create = 'Create', + Read = 'Read', + Update = 'Update', + Delete = 'Delete', +} + +declare module '@casl/mongoose' { + interface RecordTypes { + Test: true + } +} diff --git a/apps/hcdc-access-service/src/domain/entity/test/entity.ts b/apps/hcdc-access-service/src/domain/entity/test/entity.ts new file mode 100644 index 00000000..508ab482 --- /dev/null +++ b/apps/hcdc-access-service/src/domain/entity/test/entity.ts @@ -0,0 +1,12 @@ +import { BaseEntity } from '../base-entity' +import { Branch } from '../branch' + +export type Test = BaseEntity & { + displayIndex: number + name: string + shouldNotPrint: boolean + shouldDisplayWithChildren: boolean + + branchId: string + branch?: Branch | null +} diff --git a/apps/hcdc-access-service/src/domain/entity/test/example.ts b/apps/hcdc-access-service/src/domain/entity/test/example.ts new file mode 100644 index 00000000..19544f6a --- /dev/null +++ b/apps/hcdc-access-service/src/domain/entity/test/example.ts @@ -0,0 +1,19 @@ +import { exampleMongoObjectId } from '@diut/nest-core' + +import { EntityDataExample } from '../base-entity' +import { Test } from './entity' + +export const exampleTest = { + displayIndex: { + example: 1, + }, + name: { + example: 'CHIV Advia centaur', + }, + shouldNotPrint: {}, + shouldDisplayWithChildren: {}, + branchId: exampleMongoObjectId, + branch: { + required: false, + }, +} satisfies EntityDataExample diff --git a/apps/hcdc-access-service/src/domain/entity/test/index.ts b/apps/hcdc-access-service/src/domain/entity/test/index.ts new file mode 100644 index 00000000..3b1b1117 --- /dev/null +++ b/apps/hcdc-access-service/src/domain/entity/test/index.ts @@ -0,0 +1,3 @@ +export * from './entity' +export * from './example' +export * from './auth' diff --git a/apps/hcdc-access-service/src/domain/interface/repository/index.ts b/apps/hcdc-access-service/src/domain/interface/repository/index.ts index d475aae0..7b0a8d89 100644 --- a/apps/hcdc-access-service/src/domain/interface/repository/index.ts +++ b/apps/hcdc-access-service/src/domain/interface/repository/index.ts @@ -10,3 +10,5 @@ export * from './branch' export * from './role' export * from './instrument' export * from './sample-type' +export * from './print-form' +export * from './test' diff --git a/apps/hcdc-access-service/src/domain/interface/repository/print-form.ts b/apps/hcdc-access-service/src/domain/interface/repository/print-form.ts new file mode 100644 index 00000000..b93fb050 --- /dev/null +++ b/apps/hcdc-access-service/src/domain/interface/repository/print-form.ts @@ -0,0 +1,6 @@ +import { PrintForm } from 'src/domain/entity' +import { IRepository } from './interface' + +export const PrintFormRepositoryToken = Symbol('PrintFormRepository') + +export interface IPrintFormRepository extends IRepository {} diff --git a/apps/hcdc-access-service/src/domain/interface/repository/test.ts b/apps/hcdc-access-service/src/domain/interface/repository/test.ts new file mode 100644 index 00000000..d3328523 --- /dev/null +++ b/apps/hcdc-access-service/src/domain/interface/repository/test.ts @@ -0,0 +1,6 @@ +import { Test } from 'src/domain/entity' +import { IRepository } from './interface' + +export const TestRepositoryToken = Symbol('TestRepository') + +export interface ITestRepository extends IRepository {} diff --git a/apps/hcdc-access-service/src/infrastructure/mongo/print-form/index.ts b/apps/hcdc-access-service/src/infrastructure/mongo/print-form/index.ts new file mode 100644 index 00000000..ea70ac25 --- /dev/null +++ b/apps/hcdc-access-service/src/infrastructure/mongo/print-form/index.ts @@ -0,0 +1,2 @@ +export * from './repository' +export * from './schema' diff --git a/apps/hcdc-access-service/src/infrastructure/mongo/print-form/repository.ts b/apps/hcdc-access-service/src/infrastructure/mongo/print-form/repository.ts new file mode 100644 index 00000000..10e480ca --- /dev/null +++ b/apps/hcdc-access-service/src/infrastructure/mongo/print-form/repository.ts @@ -0,0 +1,17 @@ +import { InjectModel } from '@nestjs/mongoose' +import { MongoRepository } from '@diut/nest-core' +import { Model } from 'mongoose' + +import { IPrintFormRepository } from 'src/domain' +import { PrintFormSchema } from './schema' + +export class PrintFormRepository + extends MongoRepository + implements IPrintFormRepository +{ + constructor( + @InjectModel(PrintFormSchema.name) model: Model, + ) { + super(model) + } +} diff --git a/apps/hcdc-access-service/src/infrastructure/mongo/print-form/schema.ts b/apps/hcdc-access-service/src/infrastructure/mongo/print-form/schema.ts new file mode 100644 index 00000000..9bdd2ed3 --- /dev/null +++ b/apps/hcdc-access-service/src/infrastructure/mongo/print-form/schema.ts @@ -0,0 +1,32 @@ +import { Prop, Schema } from '@nestjs/mongoose' +import { BaseSchema, baseSchemaOptions } from '@diut/nest-core' +import { Types } from 'mongoose' + +import { COLLECTION } from '../collections' +import { BranchSchema } from '../branch' + +@Schema({ + ...baseSchemaOptions, + collection: COLLECTION.BIO_PRODUCT, + virtuals: { + branch: { + options: { + ref: BranchSchema.name, + localField: 'branchId', + foreignField: '_id', + justOne: true, + }, + }, + }, +}) +export class PrintFormSchema extends BaseSchema { + @Prop({ required: true }) + displayIndex: number + + @Prop({ required: true }) + name: string + + @Prop({ required: true, type: Types.ObjectId }) + branchId: string + branch?: BranchSchema | null +} diff --git a/apps/hcdc-access-service/src/infrastructure/mongo/test/index.ts b/apps/hcdc-access-service/src/infrastructure/mongo/test/index.ts new file mode 100644 index 00000000..ea70ac25 --- /dev/null +++ b/apps/hcdc-access-service/src/infrastructure/mongo/test/index.ts @@ -0,0 +1,2 @@ +export * from './repository' +export * from './schema' diff --git a/apps/hcdc-access-service/src/infrastructure/mongo/test/repository.ts b/apps/hcdc-access-service/src/infrastructure/mongo/test/repository.ts new file mode 100644 index 00000000..167bf510 --- /dev/null +++ b/apps/hcdc-access-service/src/infrastructure/mongo/test/repository.ts @@ -0,0 +1,15 @@ +import { InjectModel } from '@nestjs/mongoose' +import { MongoRepository } from '@diut/nest-core' +import { Model } from 'mongoose' + +import { ITestRepository } from 'src/domain' +import { TestSchema } from './schema' + +export class TestRepository + extends MongoRepository + implements ITestRepository +{ + constructor(@InjectModel(TestSchema.name) model: Model) { + super(model) + } +} diff --git a/apps/hcdc-access-service/src/infrastructure/mongo/test/schema.ts b/apps/hcdc-access-service/src/infrastructure/mongo/test/schema.ts new file mode 100644 index 00000000..a307101c --- /dev/null +++ b/apps/hcdc-access-service/src/infrastructure/mongo/test/schema.ts @@ -0,0 +1,32 @@ +import { Prop, Schema } from '@nestjs/mongoose' +import { BaseSchema, baseSchemaOptions } from '@diut/nest-core' +import { Types } from 'mongoose' + +import { COLLECTION } from '../collections' +import { BranchSchema } from '../branch' + +@Schema({ + ...baseSchemaOptions, + collection: COLLECTION.BIO_PRODUCT, + virtuals: { + branch: { + options: { + ref: BranchSchema.name, + localField: 'branchId', + foreignField: '_id', + justOne: true, + }, + }, + }, +}) +export class TestSchema extends BaseSchema { + @Prop({ required: true }) + displayIndex: number + + @Prop({ required: true }) + name: string + + @Prop({ required: true, type: Types.ObjectId }) + branchId: string + branch?: BranchSchema | null +}