syntax = "proto3";

package com.ywt.gapi.taihe.outpaitent;

option java_multiple_files = true;
option java_package = "com.ywt.gapi.taihe.outpaitent";
option java_outer_classname = "TaiheOutpaitentProto";

message CreateOutpatientRequest{
    string deptCode = 1;
    string deptName = 2;
    string doctorCode = 3;
    string doctorName = 4;
    int32 total = 5;
    int32 reimbursement = 6;
    int32 individual = 7;
    string hisPatientId = 8;
    string hisClinicCode = 9;
    string hisOrderNo = 10;
    string payName = 11;
    int64 prescriptionDate = 12;
    string patientName = 13;
    int32 patientAge = 14;
    int32 patientSex = 15;
    string idNo = 16;
}

message CreateOutpatientResponse{
    int32 code = 1;
    string msg = 2;
    int32 orderId = 3;
    string orderNo = 4;
    string qrcodeContent = 5;
    string qrcodeImage = 6;
}

//订单支付成功通知消息
message PayCallbackRequest{
    string orderNo = 1;
    int32 orderId = 2;
    int32 payType = 3; //1: 微信; 2: 管理员线下收费
    string custom = 4; //回发创建单时设置的自定义数据
    int32 bizId = 5;
    string paymentNo = 6; //订单中心支付流水号
    int32 userId = 7;//用户id
    string prepayId = 8; //本次支付微信 prepay_id
    int32 terminal = 9;  //发起支付终端
    string openid = 10; //完成微信支付的微信用户 openid
    int32 paymentChannel = 11;
    string oneTimeCustom = 12;//本次操作自定义数据
}
//订单支付成功通知响应消息
message PayCallbackResponse{
    int32 code = 1;
    string msg = 2;
}

//门诊缴费单二维码
message OutpatientQrcode{
    int32 id = 1;
    int32 orderId = 2;
    string orderNo = 3;
    int32 outpatientId = 4;
    string qrcodeContent = 5;
    string qrcodeImage = 6;
    string qrcodeImageType = 7;
    int32 expired = 8;
    int64 createTime = 9;
    string hisOrderNo = 10;
}

//获取门诊缴费单二维码请求
message GetOutpatientQrcodeRequest{
    string hisOrderNo = 1;
    int32 orderId = 2;
    string orderNo = 3;
    int32 outpatientId = 4;
}

//获取门诊缴费单二维码响应
message GetOutpatientQrcodeResponse{
    int32 code = 1;
    string msg = 2;
    OutpatientQrcode qrCode = 3;
}

//门诊缴费单
message OutpatientOrder{
    int32 orderId = 1;
    string orderNo = 2;
    int64 createTime = 3;
    int32 hospitalId = 4;
    string hospitalName = 5;
    string deptCode = 6;
    string deptName = 7;
    string doctorCode = 8;
    string doctorName = 9;
    int32 total = 10;
    int32 reimbursement = 11;
    int32 individual = 12;
    int32 paymentStatus = 13;
    int32 outpatientStatus = 14;
    int32 userId = 15;
    string hisPatientId = 16;
    string payName = 17;
    string patientName = 18;
    int32 patientAge = 19;
    int32 patientSex = 20;
    int64 prescriptionDate = 21;
    string hisOrderNo = 22;
    string statusName = 23;
    string invoiceNo = 24;
    string selfPay = 25;
    string insurance = 26;
    string insDetail = 27;
}

//得到门诊缴费单详情
message GetOutpatientDetailRequest{
    int32 orderId = 1;
}

message GetOutpatientDetailResponse{
    int32 code = 1;
    string msg = 2;
    OutpatientOrder order = 3;
}

//更新门诊单信息请求
message UpdateOutpatientRequest{
    int32 orderId = 1;
    int32 individual = 2;
    int32 reimbursement = 3;
    string insureKey = 4;
    string insureBizType = 5;
    string insureTreatmentType = 6;
    int32 deliveryMethod = 7;
    int32 postage = 8;
}

//更新门诊单信息响应
message UpdateOutpatientResponse{
    int32 code = 1;
    string msg = 2;
}

// 门诊缴费订单退款回调Request
message RefundOutpatientCallbackRequest{
    int32 amount = 1;       //已退金额
    int32 bizId = 2;
    int32 orderId = 3;
    string orderNo = 4;
    string refundNo = 5;    //退款单号
    int32 refundStatus = 6; //退款状态 1: 退款成功，2: 退款异常，3: 退款关闭
    string custom = 7;      //回发 custom 数据
}

// 门诊缴费订单退款回调Response
message RefundOutpatientCallbackResponse{
    int32 code = 1;
    string msg = 2;
}

//获取门诊缴费单列表请求
message GetOutpatientListRequest{
    int32 userId = 1;
    int32 pageIndex = 2;		//页码
    int32 pageSize = 3;			//页大小
}

//获取门诊缴费单列表响应
message GetOutpatientListResponse{
    int32 code = 1;
    string msg = 2;
    repeated OutpatientOrder order = 3;
    int32 totalPage = 4;
    int32 count = 5;
}

message GetMedicalCardInfoByPatientIdRequest {
    string hisPatientId = 1;
    int32 userId = 2;
    int32 hospitalId = 3;
}

message GetMedicalCardInfoByIdRequest {
    int32 id = 1;
}

message GetMedicalCardInfoByPatientIdResponse {
    int32 code = 1;
    string msg = 2;
    int32 userId = 3;
    int32 hospitalId = 4;
    string cardNo = 5;
    string cardType = 6;
    string patientName = 7;
    string mobile = 8;
    int32 sex = 9;
    string birthday = 10;
    string address = 11;
    string telephoneNo = 12;
    string documentId = 13;
    int32 balance = 14;
    string idTypeCode = 15;
    string idTypeDesc = 16;
    string idNo = 17;
    string insureCardNo = 18;
    string accInfo = 19;
    string patientType = 20;
    int32 status = 21;
    string hisPatientId = 22;
    string guardian = 23;
    int32 cardId = 24;
    string selfPay = 25;
    string insurance = 26;
    string insDetail = 27;
}

message GetOutpatientOrderByHisOrderNoRequest {
    string hisOrderNo = 1;
    string invoiceNo = 2;
    int32 hospitalId = 3;
}

message GetOutpatientOrderByHisOrderNoResponse {
    int32 code = 1;
    string msg = 2;
    int32 hospitalId =  3;
    string hospitalName =  4;
    string deptName =  5;
    string doctorName = 6;
    int32 total =  7;
    int32 reimbursement =  8;
    int32 individual =  9;
    int32 paymentStatus =  10;
    int32 outpatientStatus =  11;
    int32 userId =  12;
    string hisPatientId =  13;
    string hisClinicCode =  14;
    string hisOrderNo =   15;
    string orderNo = 16;
    int32 orderId = 17;
    string payUrl = 18;
    string medTransId = 19;
    string payAppId = 20;
}

message OutpatientOrderDetail {
    string itemCode = 1;
    string itemName = 2;
    string itemType = 3;
    int32 itemPrice = 4;
    string itemNumber = 5;
    int32 itemTotalFee = 6;
    string itemUnit = 7;
    string itemSpec = 8;
}

message SaveOutpatientOrderDetailsRequest {
    string hisOrderNo = 1;
    repeated OutpatientOrderDetail detail = 2;
}

message BaseResult {
    int32 code = 1;
    string msg = 2;
}

message GetOutpatientOrderDetailRequest {
    string hisOrderNo = 1;
    int32 hospitalId = 2;
}

message GetOutpatientOrderDetailResponse {
    int32 code = 1;
    string msg = 2;
    repeated OutpatientOrderDetail detail = 3;
    string patientName = 4;
    int32 patientAge = 5;
    int32 patientSex = 6;
    string invoiceNo = 7;
    string selfPay = 8;
    string insurance = 9;
    string insDetail = 10;
    int32 type = 11;
}

message UpdateOutpatientOrderRequest {
    string hisOrderNo = 1;
    string invoiceNo = 2;
}

message UpdateOutpatientOrderResponse {
    int32 code = 1;
    string msg = 2;
}

message GetLatestOutpatientOrderRequest {
    int32 doctorId = 1;
    int32 userId = 2;
    int32 hospitalId = 3;
}

message GetLatestOutpatientOrderResponse {
    int32 code = 1;
    string info = 2;
    int64 createTime = 3;
}

message GetOutPatientConfigRequest {
    int32 hospitalId = 1;
}

message GetOutPatientConfigResponse {
    string notifyUrl = 1;
    string returnUrl = 2;
    string openId = 3;
    int32 hospitalId = 4;
    bool hisPay = 5;
    string insuSupportCardType = 6;// 支持医保结算的诊疗卡类型，多个类型用英文逗号分割
}
message CheckHasOutstandingOutpatientOrderRequest{
    int32 userId = 1;
    int32 hospitalId = 2;
    int32 type = 3;     // 类型，用作兼容，1-暂时是查找当天未支付的订单，其他待定
}
message CheckHasOutstandingOutpatientOrderResponse{
    int32 code = 1;
    string msg = 2;
    bool hasOutstandingOutpatientOrder = 3; // 是否有未支付的订单，true：是，false：否
}

message GetOutpatientOrderDetailByInvoiceRequest {
    string invoiceNo = 1;
    int32 hospitalId = 2;
}


message GetOutpatientOrderDetailByInvoiceResponse {
    int32 code = 1;
    string msg = 2;
    repeated OutpatientOrderDetail detail = 3;
    string patientName = 4;
    int32 patientAge = 5;
    int32 patientSex = 6;
    string invoiceNo = 7;
    string selfPay = 8;
    string insurance = 9;
    string insDetail = 10;
    int32 type = 11;
}



//太和门诊服务类    // 对应 taihe-service 项目的 TaiheOutpatientServiceImpl 类
service TaiheOutpatientService{
    //生成门诊缴费单
    rpc createOutpatient(CreateOutpatientRequest) returns (CreateOutpatientResponse);

    //订单支付成功通知
    rpc payCallback(PayCallbackRequest) returns (PayCallbackResponse);

    //获取门诊缴费单二维码
    rpc getOutpatientQrcode(GetOutpatientQrcodeRequest) returns(GetOutpatientQrcodeResponse);

    //获取门诊缴费单详情
    rpc getOutpatientDetail(GetOutpatientDetailRequest) returns (GetOutpatientDetailResponse);

    //更新门诊单信息
    rpc updateOutpatient(UpdateOutpatientRequest) returns (UpdateOutpatientResponse);

    //门诊缴费订单退款回调
    rpc refundOutpatientCallback(RefundOutpatientCallbackRequest) returns (RefundOutpatientCallbackResponse);

    //获取门诊缴费单列表
    rpc getOutpatientList(GetOutpatientListRequest) returns (GetOutpatientListResponse);

    // 根据 his_patient_id 获取诊疗卡信息
    rpc getMedicalCardInfoByPatientId(GetMedicalCardInfoByPatientIdRequest) returns (GetMedicalCardInfoByPatientIdResponse);

    // 根据 his_order_no 获取门诊订单信息
    rpc getOutpatientOrderByHisOrderNo(GetOutpatientOrderByHisOrderNoRequest) returns (GetOutpatientOrderByHisOrderNoResponse);
    // 保存门诊缴费订单明细
    rpc saveOutpatientOrderDetails(SaveOutpatientOrderDetailsRequest) returns (BaseResult);
    // 获取门诊缴费订单明细
    rpc getOutpatientOrderDetail(GetOutpatientOrderDetailRequest) returns (GetOutpatientOrderDetailResponse);

    // 根据 medical_id 获取诊疗卡信息
    rpc getMedicalCardInfoById(GetMedicalCardInfoByIdRequest) returns (GetMedicalCardInfoByPatientIdResponse);

    // 更新 outpatient order
    rpc updateOutpatientOrder(UpdateOutpatientOrderRequest) returns (UpdateOutpatientOrderResponse);

    // 获取最近一次门诊缴费
    rpc getLatestOutpatientOrder (GetLatestOutpatientOrderRequest) returns (GetLatestOutpatientOrderResponse);
    rpc getOutpatientConfigs (GetOutPatientConfigRequest) returns (GetOutPatientConfigResponse);
    // 判断是否有未支付的门诊缴费订单
    rpc checkHasOutstandingOutpatientOrder (CheckHasOutstandingOutpatientOrderRequest) returns (CheckHasOutstandingOutpatientOrderResponse);
    //获取白云门诊缴费
    rpc getOutpatientOrderByInvoiceNo (GetOutpatientOrderDetailByInvoiceRequest) returns (GetOutpatientOrderDetailByInvoiceResponse);
}
