Skip to content

Commit

Permalink
Merge branch 'main' into Blog
Browse files Browse the repository at this point in the history
  • Loading branch information
Frdrcpeter007 authored Dec 14, 2023
2 parents 87d6ea3 + 0514564 commit f24c678
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
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 PatientResponseDto {
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
}
3 changes: 3 additions & 0 deletions src/modules/patient-svc/patient-svc.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ describe('PatientSvcService', () => {
create: jest.fn().mockReturnValue(mockPatient),
save: jest.fn().mockResolvedValue(mockPatient),
createQueryBuilder: jest.fn().mockReturnValue({
select: jest.fn().mockReturnThis(),
where: jest.fn().mockReturnThis(),
whereInIds: jest.fn().mockReturnThis(),
getMany: jest.fn().mockResolvedValue([mockPatient, mockPatient]),
getRawMany: jest.fn().mockResolvedValue([mockPatient, mockPatient]),
}),
} as unknown as Repository<Patient>;

Expand Down
30 changes: 28 additions & 2 deletions src/modules/patient-svc/patient-svc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { _403, _404 } from '../../common/constants/errors';
import { Repository } from 'typeorm';
import { UserType } from '../../common/constants/enums';
import { Transaction } from '../smart-contract/entities/transaction.entity';
import { CreatePatientDto, PatientResponseDto } from './dto/patient.dto';
import { CreatePatientDto, EditPatientDto, PatientResponseDto } from './dto/patient.dto';
import { Patient } from './entities/patient.entity';

@Injectable()
Expand Down Expand Up @@ -36,6 +36,18 @@ export class PatientSvcService {
return await this.patientRepository.save(patient);
}

async updatePatient(patientDto: EditPatientDto): Promise<Patient> {
const patient = await this.patientRepository.findOne({
where: { id: patientDto.id },
});

const updateData = patientDto;
delete updateData.id;
await this.patientRepository.save( {...patient, ...updateData } );

return { ...patient,...updateData};
}

/**
* This function is used to find a patient by his/her phone number
*/
Expand Down Expand Up @@ -78,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
12 changes: 12 additions & 0 deletions src/modules/payer-svc/payer-svc.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { _403, _404, _409 } from '../../common/constants/errors';
import { CachingService } from '../caching/caching.service';
import {
CreatePatientDto,
EditPatientDto,
PatientResponseDto,
} from '../patient-svc/dto/patient.dto';
import { PatientSvcService } from '../patient-svc/patient-svc.service';
Expand Down Expand Up @@ -125,6 +126,17 @@ export class PayerSvcController {
return await this.patientService.registerPatient(createPatientAccountDto);
}

@Put('patient')
@Roles(UserRole.PAYER)
@ApiOperation({
summary: 'This API is used update the Patient by PAYER.',
})
async updatePatient(
@Body() editPatientAccountDto: EditPatientDto,
): Promise<PatientResponseDto> {
return await this.patientService.updatePatient(editPatientAccountDto);
}

@Post('send-invite')
@Roles(UserRole.PAYER)
@ApiOperation({
Expand Down

0 comments on commit f24c678

Please sign in to comment.