
import { Injectable } from '@nestjs/common';

import axios from 'axios';
import { DataSource } from 'typeorm';
@Injectable()
export class SendNotificationService {
  constructor(private readonly connection: DataSource,

  ) { }

  async SendNotificationForPatientProfile(from_staff_id: string, to_staff_id: any, room_id: string, hospital_id: any) {

    if (!hospital_id) {
      return {
        "status": "failed",
        "messege": "enter hospital_id to post clinical notes"
      }
    }
    try {
      const [getBaseURL] = await this.connection.query(`select op_hub_base_url from hospitals where plenome_id = ?`, [hospital_id])
      const createPrescriptionDto = {
        "from_staff_id": from_staff_id,
        "to_staff_id": to_staff_id,
        "room_id": room_id,
        "hospital_id": hospital_id
      }
      const getAppointment = await axios.post(`${getBaseURL.op_hub_base_url}/op-hub-send-notification/to-profile`, createPrescriptionDto)
      return getAppointment.data
    } catch (error) {
      console.log(error, "error");
      throw new Error(error);
    }
  }



}