import { Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { CheckForDuplicateAppointment } from './entities/check-for-duplicate-appointment.entity';
import axios from 'axios';
@Injectable()
export class CheckForDuplicateAppointmentService {
   constructor(private readonly connection: DataSource
   ) { }


   async create(AppointmentEntity: CheckForDuplicateAppointment) {
      try {
         const [getBaseURL] = await this.connection.query(`select op_hub_base_url from hospitals where plenome_id = ?`, [AppointmentEntity.Hospital_id])
         let apiURL = `${getBaseURL.op_hub_base_url}/op-hub-check-for-duplicate-appointment`
         const getAppointment = await axios.post(apiURL, AppointmentEntity)
         return getAppointment.data

      } catch (error) {
         throw new Error(error);
      }
   }
}
