import { Post } from "../../lib/request/method";

export function getPatients(id?: string) {
  id ??= wx.getStorageSync('patientId')
  const transform = ({ data }: AnyObject) => {
    const patient = void 0
      ?? data.find((item: AnyObject) => item.patientId == id)
      ?? data.find((item: AnyObject) => item.isDefault?.toUpperCase() === 'Y')
      ?? data[0];

    return { patient, patients: data }
  }
  return Post('/mobileAccountManage/getPatsByAid', {}, { transform })
}

export function healthReportMethod() {
  const transform = ({ data }: AnyObject) => {
    if (Array.isArray(data?.conditProgram?.types)) {
      data.conditProgram.types = data.conditProgram.types.map((item: AnyObject) => (item.summary = item.summary?.replace(/null/g, '') || '', item))
    }
    return data;
  };

  return Post(`/analysisManage/getLastHealRepDetail`, {}, { transform })
}

export function healthIndexMethod() {
  const transform = ({ data }: AnyObject) => {
    return Array.isArray(data) ? data.map(item => ({ ...item, ...item.patientQuotaRecordDTOS?.slice(-1)[0] })) : [];
  };
  return Post(`/patientQuota/getCurQuoval`, {}, { transform })
}