From 3dec594da56015d8db0e7abb85d21f4c3212456d Mon Sep 17 00:00:00 2001 From: Bratu Sebastian Date: Tue, 28 Nov 2023 21:59:39 +0200 Subject: [PATCH] Bugfix/show all added patients (#112) * add patient edit endpoint * add ability to save addedBy field equal to payerId --- src/modules/patient-svc/dto/patient.dto.ts | 11 +++++++++++ .../patient-svc/entities/patient.entity.ts | 3 +++ src/modules/patient-svc/patient-svc.service.ts | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/modules/patient-svc/dto/patient.dto.ts b/src/modules/patient-svc/dto/patient.dto.ts index 5a7f245..931bc6d 100644 --- a/src/modules/patient-svc/dto/patient.dto.ts +++ b/src/modules/patient-svc/dto/patient.dto.ts @@ -35,6 +35,17 @@ export class CreatePatientDto { @IsOptional() @IsString() city?: string; + + @IsOptional() + @IsString() + addedBy?: string +} + +export class EditPatientDto extends CreatePatientDto { + @IsNotEmpty() + @IsUUID() + @IsString() + id: string; } export class EditPatientDto extends CreatePatientDto { diff --git a/src/modules/patient-svc/entities/patient.entity.ts b/src/modules/patient-svc/entities/patient.entity.ts index 04fb1d0..3c1448f 100644 --- a/src/modules/patient-svc/entities/patient.entity.ts +++ b/src/modules/patient-svc/entities/patient.entity.ts @@ -28,4 +28,7 @@ export class Patient extends BaseEntity { @Column({ nullable: true }) city?: string; + + @Column({ nullable: true }) + addedBy?: string } diff --git a/src/modules/patient-svc/patient-svc.service.ts b/src/modules/patient-svc/patient-svc.service.ts index 57d0f2d..dfddc0d 100644 --- a/src/modules/patient-svc/patient-svc.service.ts +++ b/src/modules/patient-svc/patient-svc.service.ts @@ -90,13 +90,27 @@ export class PatientSvcService { .groupBy('transaction.ownerId') .getRawMany(); + const addedByUser = await this.patientRepository + .createQueryBuilder('patient') + .select('patient.id', 'id') + .where('patient.added_by = :payerId', { payerId }) + .getRawMany(); + const addedByUserUniqueIds = addedByUser.map( result => result.id ); + const uniquePatientIds = uniquePatientIdsQuery.map( (result) => result.ownerId, ); + const combinedPatientIds = Object.values( [...uniquePatientIds, ...addedByUserUniqueIds ].reduce( ( acc, item ) => { + acc[ item ] = item; + return acc; + }, {} )); + + console.log('combined', combinedPatientIds ); + const patients = await this.patientRepository .createQueryBuilder('patient') - .whereInIds(uniquePatientIds) + .whereInIds(combinedPatientIds) .getMany(); return patients.map((patient) => {