Skip to content

Commit

Permalink
get sections updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Sep 27, 2024
1 parent b62dd03 commit b5c835d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
speech
/clean.txt

# Ignore all node_modules directories
Expand Down
2 changes: 2 additions & 0 deletions server/src/domain/entities/IVideoChatSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export default interface IVideoSection {
doctorName?: string;
patientName?: string;
doctorProfile?: string;
doctorId?: string;
patientProfile?: string;
patientId?: string;
createdAt?: Date;
updatedAt?: Date;
startTime?: Date | string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export interface IVideoSectionRepository {
delete(id: string): Promise<void>;
findByAppointmentId(appointmentId: string): Promise<IVideoSection | null>;
findByStatus(status: VideoSectionStatus): Promise<IVideoSection | null>;
findByStartTimeRange(startTime: string, endTime: string): Promise<IVideoSection[] | null>;
findByStartTimeRangeByDoctorId(startTime: string, endTime: string, doctorId: string): Promise<IVideoSection[] | null>;
findByStartTimeRangeByPatientId(startTime: string, endTime: string, patientId: string): Promise<IVideoSection[] | null>;
}


14 changes: 13 additions & 1 deletion server/src/infrastructure/model/VideoSectionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@ import { model, Schema } from "mongoose";
import IVideoSection, { VideoSectionStatus } from "../../domain/entities/IVideoChatSection";

const videoSectionSchema = new Schema<IVideoSection>({
appointmentId: { type: String, required: true, index: true },
appointmentId: { type: String, required: true },
doctorId: {
type: Schema.Types.ObjectId,
ref: "Doctor",
required: true,
index: true,
},
patientId: {
type: Schema.Types.ObjectId,
ref: "Patient",
required: true,
index: true,
},
doctorName: { type: String, required: true },
patientName: { type: String, required: true },
startTime: { type: Date, required: true, index: true },
Expand Down
14 changes: 11 additions & 3 deletions server/src/infrastructure/repositories/VideoSectionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ export default class VideoSectionRepository implements IVideoSectionRepository {
async findByAppointmentId(appointmentId: string): Promise<IVideoSection | null> {
return await this.model.findOne({ appointmentId });
}

async findByStartTimeRange(startTime: string, endTime: string): Promise<IVideoSection[] | null> {

async findByStartTimeRangeByDoctorId(startTime: string, endTime: string, doctorId: string): Promise<IVideoSection[] | null> {
return await this.model.find({
startTime: { $gte: startTime, $lte: endTime },
doctorId
});
}

async findByStartTimeRangeByPatientId(startTime: string, endTime: string, patientId: string): Promise<IVideoSection[] | null> {
return await this.model.find({
startTime: { $gte: startTime, $lte: endTime }
startTime: { $gte: startTime, $lte: endTime },
patientId
});
}

Expand Down
18 changes: 12 additions & 6 deletions server/src/use_case/video/GetVideoSectionUseCase.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import IVideoSection from "../../domain/entities/IVideoChatSection";
// import IAppointmentRepository from "../../domain/interface/repositories/IAppointmentRepository";
import { IVideoSectionRepository } from "../../domain/interface/repositories/IVideoSectionRepository";
import IValidatorService from "../../domain/interface/services/IValidatorService";
import { addHours } from "../../utils/date-formatter";

export default class GetVideoSectionUseCase {
constructor(
private readonly videoSectionRepository: IVideoSectionRepository,
private readonly validatorService: IValidatorService
// private readonly appointmentRepository: IAppointmentRepository
) { }

async getSectionById(id: string): Promise<IVideoSection | null> {
Expand All @@ -20,12 +19,19 @@ export default class GetVideoSectionUseCase {
return await this.videoSectionRepository.findByAppointmentId(appointmentId);
}

async getSectionsInOneHour(): Promise<IVideoSection[] | []> {
async getSectionsInOneHourDoctor(doctorId: string): Promise<IVideoSection[] | []> {
this.validatorService.validateIdFormat(doctorId)
const currentTime = new Date();
const afterOneHour = new Date(currentTime.getTime() + 60 * 60 * 1000);
const sections = await this.videoSectionRepository.findByStartTimeRange(currentTime.toISOString(), afterOneHour.toISOString());
const afterOneHour = addHours(currentTime, 1);
const sections = await this.videoSectionRepository.findByStartTimeRangeByDoctorId(currentTime.toISOString(), afterOneHour.toISOString(), doctorId);
return sections ?? [];
}


async getSectionsInOneHourPatient(patientId: string): Promise<IVideoSection[] | []> {
this.validatorService.validateIdFormat(patientId)
const currentTime = new Date();
const afterOneHour = addHours(currentTime, 1);
const sections = await this.videoSectionRepository.findByStartTimeRangeByPatientId(currentTime.toISOString(), afterOneHour.toISOString(), patientId);
return sections ?? [];
}
}

0 comments on commit b5c835d

Please sign in to comment.