const db = require("../../../../managers/dbConfig");

const caseNote = async (req, res) => {
  ptID = req.params.ptid;

  const sql = `SELECT phone_num, patient_id FROM patients WHERE patient_id=? OR phone_num=?`;
  const sql1 = `SELECT * FROM tx WHERE patient_id=?`;

  const [ptExist] = await db.execute(sql, [ptID, ptID]);
  if (ptExist.length === 0)
    throw "Patient Not Found: Incorrect patient ID or Phone number";
  const pt_id = ptExist[0].patient_id;
  const [txData] = await db.execute(sql1, [pt_id]);
  console.log(pt_id);
  res.status(200).json({
    status: "success",
    ...txData[0],
  });
};

module.exports = caseNote;
