import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { DataSource } from 'typeorm';
@Injectable()
export class GetAbhaAddressOfPatientService {
  constructor(private readonly connection: DataSource,
  ) { }
  async findAll(hospital_id: number, patient_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 apiURL = `${getBaseURL.op_hub_base_url}/op-hub-get-abha-address-of-patient`;
      let body = {
        "patient_id": patient_id,
        "hospital_id": hospital_id
      }
      const check_old = await axios.post(apiURL, body)
      return check_old.data
    } catch (error) {
      throw new Error(error);
    }
  }

}
