/** 病历词条字段选项（与后端 MedicalRecordFieldCodeEnum 对齐） */
export const MEDICAL_RECORD_FIELD_OPTIONS = [
  { label: '主诉', value: 'chief_complaint' },
  { label: '现病史', value: 'present_illness' },
  { label: '舌象', value: 'tongue' },
  { label: '脉象', value: 'pulse' },
  { label: '中医病案', value: 'tcm_case' },
  { label: '治疗意见', value: 'treatment_advice' },
  // 诊断/医嘱与处方「常用诊断」「常用医嘱」同源，不在此表维护
  { label: '家族史', value: 'family_history' },
  { label: '流行病学史', value: 'epidemic_history' },
  { label: '既往史', value: 'past_history' },
  { label: '月经史', value: 'menstrual_history' },
  { label: '婚育史', value: 'marital_history' },
  { label: '个人史', value: 'personal_history' },
  { label: '过敏史', value: 'allergy_history' },
  { label: '体征检查', value: 'physical_exam' },
  { label: '辅助检查', value: 'auxiliary_exam' },
];

/** 病历只读展示字段（含诊断/医嘱正文） */
export const MEDICAL_RECORD_VIEW_FIELDS = [
  { label: '临床诊断', value: 'diagnosis' },
  { label: '主诉', value: 'chief_complaint' },
  { label: '现病史', value: 'present_illness' },
  { label: '舌象', value: 'tongue' },
  { label: '脉象', value: 'pulse' },
  { label: '中医病案', value: 'tcm_case' },
  { label: '中医证候', value: 'tcm_syndrome' },
  { label: '中医疾病', value: 'tcm_disease' },
  { label: '中医治法', value: 'tcm_method' },
  { label: '治疗意见', value: 'treatment_advice' },
  { label: '医嘱', value: 'doctor_order' },
  { label: '家族史', value: 'family_history' },
  { label: '流行病学史', value: 'epidemic_history' },
  { label: '既往史', value: 'past_history' },
  { label: '月经史', value: 'menstrual_history' },
  { label: '婚育史', value: 'marital_history' },
  { label: '个人史', value: 'personal_history' },
  { label: '过敏史', value: 'allergy_history' },
  { label: '体征检查', value: 'physical_exam' },
  { label: '辅助检查', value: 'auxiliary_exam' },
];

export const STATUS_OPTIONS = [
  { label: '启用', value: 1 },
  { label: '禁用', value: 0 },
];

/**
 * 按性别/年龄判断病史字段是否展示
 * 月经史：仅女；婚育史：男>22 或 女>20；个人史：始终
 */
export function isHistoryFieldVisible(
  fieldCode: string,
  sex: number,
  age: number,
): boolean {
  if (fieldCode === 'menstrual_history') {
    return Number(sex) === 2;
  }
  if (fieldCode === 'marital_history') {
    const s = Number(sex);
    const a = Number(age) || 0;
    return (s === 1 && a > 22) || (s === 2 && a > 20);
  }
  if (fieldCode === 'personal_history') {
    return true;
  }
  return true;
}

/** 空病历结构 */
export function emptyMedicalRecord(registerId = 0, storeId = 0) {
  return {
    id: 0,
    store_id: storeId,
    register_id: registerId,
    user_patient_id: 0,
    doctor_id: 0,
    chief_complaint: '',
    present_illness: '',
    tcm_disease: '',
    tcm_syndrome: '',
    tcm_method: '',
    tongue: '',
    pulse: '',
    tcm_case: '',
    treatment_advice: '',
    doctor_order: '',
    diagnosis: '',
    family_history: '',
    epidemic_history: '',
    past_history: '',
    menstrual_history: '',
    marital_history: '',
    personal_history: '',
    allergy_history: '',
    physical_exam: '',
    auxiliary_exam: '',
    temperature: 0,
    height: 0,
    weight: 0,
    respiratory_rate: 0,
    bp_systolic: 0,
    bp_diastolic: 0,
  };
}
