Skip to content

Commit

Permalink
Bugfix/show all added patients (#112)
Browse files Browse the repository at this point in the history
* add patient edit endpoint

* add ability to save addedBy field equal to payerId
  • Loading branch information
artweb11 authored Nov 28, 2023
1 parent 6922d49 commit 3dec594
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/modules/patient-svc/dto/patient.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/modules/patient-svc/entities/patient.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ export class Patient extends BaseEntity {

@Column({ nullable: true })
city?: string;

@Column({ nullable: true })
addedBy?: string
}
16 changes: 15 additions & 1 deletion src/modules/patient-svc/patient-svc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 3dec594

Please sign in to comment.