
import { Injectable } from "@nestjs/common";
import axios from "axios";
import { DataSource } from "typeorm";


@Injectable()
export class UploadDocPreviwService {
  constructor(
    private connection: DataSource,


  ) { }


  async create(
    file: any,
    opd_id: number,
    hospital_id: number,
    abhaAddress: string
  ) {
    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])


      let upload_doc_Req_body = {
        dongri: file,
        opd_id: opd_id,
        hospital_id: hospital_id,
        abhaAddress: abhaAddress
      }


      const upload_doc = await axios.post(`${getBaseURL.op_hub_base_url}/op-hub-upload-doc-preview`, upload_doc_Req_body)

      return upload_doc.data
    } catch (error) {
      throw new Error(error)
    }
  }


  async uploadDoc(
    file: any,
    opd_id: number,
    hospital_id: number,
  ) {
    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])

      let upload_doc_Req_body = {
        file: file,
        opd_id: opd_id,
        hospital_id: hospital_id,
      }


      const upload_doc = await axios.post(`${getBaseURL.op_hub_base_url}/op-hub-upload-doc-preview/uploadCaseSheet`, upload_doc_Req_body)

      return upload_doc.data
    } catch (error) {
      throw new Error(error)
    }
  }
}