// 开医疗设备检查的功能
syntax = "proto3";

package com.ywt.gapi.med_equip;

option java_multiple_files = true;
option java_package = "com.ywt.gapi.med_equip";
option java_outer_classname = "MedEquipProto";

// 医生开检查单请求
message CreateOrderRequest {
    int32 hospitalId = 1;// unused
    int32 doctorId = 2;// 开单医生 id
    int32 deptId = 3;// 科室 id, unused
    string diagnose = 4;// 诊断
    repeated InspectionItem inspectionItem = 5;// 检查项目列表
    int32 totalPrice = 6;// 总价，单位：分, unused
    int32 doctorSignId = 7;// 医生签名 id
    string remark = 8;// 备注
}

message InspectionItem {
    int32 id = 1;// 检查项目主键
    int32 count = 2;// 数量
    string name = 3;
    string spec = 4;
    int32 price = 5;// 单位：分
    string remark = 6;
}

message CreateOrderResponse {
    int32 code = 1;
    string info = 2;
    int32 orderId = 3;
    string orderNo = 4;
    int32 equipOrderId = 5;
}

message QueryOrderRequest {
    int32 orderId = 1;
    int32 userId = 2;
}

message QueryOrderResponse {
    int32 code = 1;
    string info = 2;
    OrderInfo orderInfo = 3;
}

message QueryOrderRecordsRequest {
    int32 status = 1;
    string startTime = 2;// yyyy-MM-DD
    string endTime = 3;// yyyy-MM-DD
    int32 userId = 4;// 请求用户 id。当用户为医生，可以查看该医生的所有开单记录；若用户是设备管理员，可以查看所在医院的所有医疗设备订单。患者用户查看自己的所有检查订单。
    int32 pageIndex = 5;		//页码
    int32 pageSize = 6;			//页大小
    int32 hospitalId = 7;
    string keyword = 8;// 关键字搜索，目前支持患者姓名
}

message OrderInfo {
    string orderNo = 1;
    string hospitalName = 2;
    string doctorName = 3;
    string deptName = 4;
    string patientName = 5;
    string patientIdCard = 6;
    int32 patientAge = 7;
    int32 patientGender = 8;
    string patientMobile = 9;
    string paymentTime = 10;
    string diagnose = 11;
    repeated InspectionItem inspectionItem = 12;
    int32 doctorSignId = 13;
    string remark = 14;
    int32 status = 15;
    string statusStr = 16;
    string payUrl = 17;// 展示给患者扫码支付的地址
    string equipCode = 18;// 设备码
    string senderName = 19;// 派发人姓名
    string recyclerName = 20;// 回收人员姓名
    string refundApplyDoctor = 21;// 退款申请医生
    string refundRejectReason = 22;// 退款不通过原因
    int32 equipId = 23;// 设备 id
    int32 orderId = 24;
    string createTime = 25;
    int32 totalPrice = 26;
    int32 refundFlag = 27;// 申请退款按钮显示状态：1：显示且可以点击；0：隐藏；-1：显示但不能点击
    int32 allocFlag = 28;// 确认领取按钮显示状态：1：显示且可以点击；0：隐藏；-1：显示但不能点击
    int32 recycleFlag = 29;// 确认回收按钮显示状态：1：显示且可以点击；0：隐藏；-1：显示但不能点击
    string doctorSignUrl = 30;
    int32 equipOrderId = 31;
    string recCode = 32;// 领取码
    bool equipCodeEditable = 33;// 设备码能否修改
    int32 hospitalId = 34;
    int32 changedHospitalId = 35;
    int32 viewReportFlag = 36;// 查看检查报告按钮显示状态：1：显示且可以点击；0：隐藏
    int32 relatedReportId = 37;// 订单关联的报告 id，用于查看报告详情
}

message QueryOrderRecordsResponse {
    int32 code = 1;
    string info = 2;
    repeated OrderInfo orderInfo = 3;
    int32 totalPage = 4;
    int32 count = 5;
}

message QueryInspectionItemsRequest {
    string keyword = 1;
    int32 pageIndex = 2;		//页码
    int32 pageSize = 3;			//页大小
    int32 hospitalId = 4;
}

message QueryInspectionItemsResponse {
    int32 code = 1;
    string info = 2;
    repeated InspectionItem inspectionItem = 3;
    int32 totalPage = 4;
    int32 count = 5;
}

message QueryEquipListRequest {
    int32 hospitalId = 1;
    int32 deptId = 2;
    int32 pageIndex = 3;		//页码
    int32 pageSize = 4;			//页大小
}

message Equip {
    int32 id = 1;
    string name = 2;
    string deptName = 3;
    int32 deptId = 4;
    int32 hospitalId = 5;
    int32 status = 6;
    int32 occupationStatus = 7;// 占用状态：0-未用，1-使用中
    string payCode = 8;
    string equipCode = 9;
}

message QueryEquipListResponse {
    int32 code = 1;
    string info = 2;
    repeated Equip equip = 3;
    int32 totalPage = 4;
    int32 count = 5;
}

message AllocEquipRequest {
    int32 orderId = 1;
    int32 equipId = 2;// 设备主键, unused
    int32 operatorId = 3;// 操作用户 id
    string eqmtNo = 4;
    string patientName = 5;
    int32 age = 6;
    int32 sex = 7;
    string mobile = 8;
    string idCard = 9;
    string operatorName = 10;
    bool fromMg = 11;// 是否管理后台调用
}

message AllocEquipResponse {
    int32 code = 1;
    string info = 2;
    int64 wearId = 3;
}

message RecycleEquipRequest {
    int32 orderId = 1;
    int32 operatorId = 2;// 操作用户 id
    string operatorName = 3;
    bool fromMg = 4;// 是否管理后台调用
}

message RecycleEquipResponse {
    int32 code = 1;
    string info = 2;
}

message ApplyForRefundRequest {
    int32 orderId = 1;
    int32 operatorId = 2;// 申请人用户 id
    string reason = 3;
}

message ApplyForRefundResponse {
    int32 code = 1;
    string info = 2;
}

message UpdateDiagnosisRequest {
    int64 wearId = 1;
    string content = 2;
    string pdfUrl = 3;
    string callbackTime = 4;
    int32 orderId = 5;
    string equipCode = 6;
}

message UpdateDiagnosisResponse {
    int32 code = 1;
    string info = 2;
}


//订单支付成功通知消息
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;//本次操作自定义数据
    string wxTransactionId = 13; //本次微信支付交易流水号
    int64 payFinishDate = 14; //支付完成时间，单位：秒
}

//订单支付成功通知响应消息
message PayCallbackResponse{
    int32 code = 1;
    string info = 2;
}

//退款结果通知请求消息
message RefundNotifyRequest {
    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 数据
    int64 refundSuccessTime = 8;    //退款成功时间, 时间戳: 秒
}
//退款结果通知响应消息
message RefundNotifyResponse {
    int32 code = 1;
    string info = 2;
}

message UpdateOrderInfoRequest {
    string patientName = 1;
    string patientIdCard = 2;
    string patientMobile = 3;
    int32 orderId = 4;
    int32 userId = 5;
}

message UpdateOrderInfoResponse {
    int32 code = 1;
    string info = 2;
}

message QueryReportListRequest {
    int32 userId = 1;
    int32 pageIndex = 2;		//页码
    int32 pageSize = 3;			//页大小
    int32 hospitalId = 4;
}

message QueryReportListResponse {
    int32 code = 1;
    string info = 2;
    repeated ReportItem reportItem = 3;
    int32 totalPage = 4;
    int32 count = 5;
}

message ReportItem {
    int32 id = 1;
    string content = 2;
    string pdfUrl = 3;
    string timeStamp = 4;
}

message QueryReportDetailRequest {
    int32 reportId = 1;
    int32 userId = 2;
}

message QueryReportDetailResponse {
    int32 code = 1;
    string info = 2;
    ReportItem reportItem = 3;
}

message CheckIfUserHasAdminPermissionRequest {
    int32 userId = 1;
    int32 orderId = 2;
}

message CheckIfUserHasAdminPermissionResponse {
    int32 code = 1;
    string info = 2;
    bool isAdmin = 3;
}

message GetEquipDeptListRequest {
    int32 hospitalId = 1;
}

message GetEquipDeptListResponse {
    int32 code = 1;
    string info = 2;
    repeated EquipDept equipDept = 3;
}

message EquipDept {
    int32 id = 1;
    string name = 2;
}

message ChangeEquipCodeRequest {
    int32 orderId = 1;
    string equipCode = 2;
    int32 operatorId = 3;
    int32 source = 4;// 1-医生端，2-医院后台，3-药企后台
    string operatorName = 5;
}

message ChangeEquipCodeResponse {
    int32 code = 1;
    string info = 2;
}

message CheckIfUserEquipAdminRequest {
    int32 userId = 1;
    int32 hospitalId = 2;
}

message CheckIfUserEquipAdminResponse {
    int32 code = 1;
    string info = 2;
    bool isEquipAdmin = 3;// 是否拥有管理员身份，可能是医生
    bool isEquipAdminOnly = 4;// 是否只是管理员身份，非医生
}

message TriggerScheduledJobRequest {
    int32 event = 1;// 事件类型：1-24小时归还设备提醒
}

message TriggerScheduledJobResponse {
    int32 code = 1;
    string info = 2;
}

message GetEquipAdminInfoRequest {
    int32 userId = 1;
    int32 hospitalId = 2;
}

message GetEquipAdminInfoResponse {
    int32 code = 1;
    string info = 2;
    string hospitalName = 3;
    string deptName = 4;
    int32 deptId = 5;
    int32 hospitalId = 6;
    string name = 7;
    string mobile = 8;
    string remark = 9;
    int32 status = 10;
}

// 中控
service LepuService {
    // 分配设备（确认领取设备）
    rpc allocEquip(AllocEquipRequest) returns (AllocEquipResponse);
    // 回收设备
    rpc recycleEquip(RecycleEquipRequest) returns (RecycleEquipResponse);
}

// rpc
service MedEquipService {
    // 医生创建订单
    rpc createOrder(CreateOrderRequest) returns (CreateOrderResponse);
    // 查询订单详情
    rpc queryOrder(QueryOrderRequest) returns (QueryOrderResponse);
    // 医生查询开检查记录
    rpc queryOrderRecords(QueryOrderRecordsRequest) returns (QueryOrderRecordsResponse);
    // 查询检查项目
    rpc queryInspectionItems(QueryInspectionItemsRequest) returns (QueryInspectionItemsResponse);
    // 查询设备列表
    rpc queryEquipList(QueryEquipListRequest) returns (QueryEquipListResponse);
    // 申请退款
    rpc applyForRefund(ApplyForRefundRequest) returns (ApplyForRefundResponse);
    // 更新回调接口接收到的诊断推送
    rpc updateDiagnosis(UpdateDiagnosisRequest) returns (UpdateDiagnosisResponse);
    // 支付成功回调
    rpc payCallback(PayCallbackRequest) returns (PayCallbackResponse);
    //退款结果通知
    rpc orderRefundNotify(RefundNotifyRequest) returns (RefundNotifyResponse);
    // 更新订单信息，患者端支付前提交姓名身份证手机号等信息
    rpc updateOrderInfo(UpdateOrderInfoRequest) returns (UpdateOrderInfoResponse);
    // 查询检查报告列表
    rpc queryReportList(QueryReportListRequest) returns (QueryReportListResponse);
    // 查询检查报告详情
    rpc queryReportDetail(QueryReportDetailRequest) returns(QueryReportDetailResponse);
    // 判断用户是否有管理设备的权限(领取、回收)
    rpc checkIfUserHasAdminPermission(CheckIfUserHasAdminPermissionRequest) returns(CheckIfUserHasAdminPermissionResponse);
    // 获取设备科室
    rpc getEquipDeptList(GetEquipDeptListRequest) returns (GetEquipDeptListResponse);
    // 修改设备码
    rpc changeEquipCode(ChangeEquipCodeRequest) returns (ChangeEquipCodeResponse);
    // 判断用户是否是设备管理员
    rpc checkIfUserEquipAdmin(CheckIfUserEquipAdminRequest) returns (CheckIfUserEquipAdminResponse);
    // 触发定时任务
    rpc triggerScheduledJob(TriggerScheduledJobRequest) returns (TriggerScheduledJobResponse);
    // 获取设备管理员信息
    rpc getEquipAdminInfo(GetEquipAdminInfoRequest) returns (GetEquipAdminInfoResponse);
}
