syntax = "proto3";
package com.ywt.gapi.third.sinopharm;

option java_multiple_files = true;
option java_package = "com.ywt.gapi.third.sinopharm";
option java_outer_classname = "SinopharmProto";

//收药人地址信息
message ContactInfo{
    string contactName = 1;
    string contactPhone = 2;
    string  province = 3;
    string  provinceCode = 4;
    string  city = 5;
    string  cityCode = 6;
    string  area = 7;
    string  areaCode = 8;
    string  street = 9;
    string  streetCode = 10;
    string  address = 11;
    string  location = 12;
}

//患者信息
message PatInfo{
    string patName = 1;
    string patIdCardNo = 2;
    int32 patAge = 3;
    int32 patSex = 4;//患者性别,0-男，1-女
    string patInsCardNo = 5;
}

//药品信息
message DrugInfo{
    int32 pscriptDtlId = 1;       //药品明细ID Long
    string drugCode = 2;
    string drugTradeName = 3;     //药品商品名 ++++++
    string hosDrugName = 4;       //医院化学名
    string hosDrugTradeName = 5;  //医院商品名
    string drugName = 6;          //药品名称(化学名，通用名)
    string drugSpec = 7;          //药品规格
    string drugDose = 8;          //剂型名称
    double oneDosage = 9;          //单次服用剂量，保留两位小数
    string oneDosageUnit = 10;        //单次服用剂量单位
    double totalDosage = 11;        //总剂量，保留两位小数
    string totalDosageUnit = 12;      //总剂量单位
    int32 amount = 13;                  //整包装数量
    string units = 14;               //整包装单位
    string frequencyCode = 15;
    string frequency = 16;
    int32 frequencyQty = 17;           //频次数量 INT
    string usageCode = 18;          //用法编码 如PO
    string usage = 20;              //用法说明
    int32 drugType = 21;                //药品类型 0-处方药；1-OTC
    int32 drugSource = 22;              //一品两规 1-国产；2-进口；3-合资
    int32 assemble = 23;                //是否整装 1-是；0-否
    string manufaturer = 24;       //厂家
    string usageDesc = 25;   //总的用法说明：口服 一天三次 一次1片
    string dpDrugCode = 26;  // "DJ1001IG27",             //药商药品编码  对应药品编码
    double price = 27;  //200,        //单价,保留两位小数
    double sum = 28;    //200,      //该明细总价
    string dpPscriptDtlId = 29;     //药商处方明细映射ID
    string doctorAdvice = 30;
    string executionDT = 31;
}

//药店信息
message DrugStore {                    //药店信息(选择到店自取时传递)
    string storeName = 1;   //国控广州如意坊大药房门店',
    string storePhone = 2;
    string province = 3; //广东省
    string provinceCode = 4;
    string city = 5; // '广州市',
    string cityCode = 6;
    string area = 7;    //天河
    string areaCode = 8;
    string street = 9;  //'黄埔大道西601号',
    string streetCode = 10;
    string address = 11;    //黄埔大道西601号',
    string location = 12;   //广州市荔湾区黄沙大道涌边一马路6号之五2号楼自编1、2、3号铺（自主申报）
    double drugFee = 13;    // 800,         //本次请求药品在该店自取时的总金额
    string storeId = 14;    // '9116001'          //药店编号
}

//推送给国控处方单
message DpPrescription{
    string matchId = 1;         //匹配流水
    string dpMatchId = 2;    //药商报价ID
    int32 pscriptId = 3;         //处方单号 String? Long?
    string pscriptdate = 4;//'2018-04-25 22:10:23', //处方开具日期
    string dpPscriptId = 5;      //药商处方映射ID(我方处方总ID，接口的非零售处方表的)
    int32 hosId = 6;            //医院Id
    string hoscode = 7;        //医院代码
    string hosName = 8;        //医院名称
    string deptName = 9;   //门诊名称
    string docName = 10;     //医生姓名
    string accPscriptId = 11;       //医院处方单号
    string accessVisitId = 12;     //医院就诊流水(对应多个处方单)
    string diagnosis = 13;     //诊断
    PatInfo patInfo = 14;
    repeated DrugInfo drugs = 15;
    ContactInfo contactInfo = 16;
    DrugStore drugStore = 17;
    int32 pscriptType = 18; //用于区别门店或是院内药房取药地点（ 0-院内取药，1-门店取药）
}

//匹配信息
message MatchInfo{

}

//药品匹配信息请求
message DrugMatchingRequest{
    string matchId = 1;
    int32 isExpress = 2;    //取药方式：0-快递；1-到店自取(会传递收药人信息)  目前取药方式没有快递
    repeated DpPrescription pscripts = 3;
    ContactInfo contactInfo = 4;
}

//药品匹配信息响应
message DrugMatchingResponse{
    message Drug {
        int32 amout = 1;
        string dpDrugCode = 2;
        string dpDrugId = 3;
        string dpPscriptDtlId = 4;
        string drugCode = 5;
        int32 hasStock = 6;
        string manufaturer = 7;
        double price = 8;
        int32 pscriptDtlId = 9;
        double score = 10;
        double sum = 11;
        string units = 12;
    }
    message Pscript{
        repeated Drug drugs = 1;
        double pscriptFee = 2;  //处方粒度总金额
        int32 pscriptId = 3;    //处方单号
    }

    int32 code = 1;
    string msg = 2;
    string dpMatchId = 3;
    repeated Pscript pscripts = 4;
}

//处方订单确认请求
message ConfirmOrderRequest{
    string orderNo = 1;
    int32 orderId = 2;
    string payTime = 3;
    string invoiceTitle = 4;
    double orderFee = 5;
    double drugFee = 6;
    double deliveryFee = 7;
    string deliveryId = 8;           //快递请求流水 （传空）
    string dpDeliveryId = 9;       //药商快递报价ID （传空）
    int32 isExpress = 10;                     //取药方式：0-快递，1-到店自取
    int32 payOff = 11;
    repeated DpPrescription pscripts = 12;
    ContactInfo contactInfo = 13;
    DrugStore drugStore = 14;
}

//处方订单确认响应
message ConfirmOrderResponse{
    int32 code = 1;
    string msg = 2;
}

// 发票信息
message InvoiceDetail{
    string custBankAccount = 1; //购方银行、账号（非个人需传）(选填)
    string createDate = 2;  // 订单时间,yyyy-MM-dd HH:mm:ss
    string custTaxNo = 3;   // 购方税号（非个人需传）(选填)
    double dmount = 4;      // 订单明细金额
    int32 invsort = 5;      // 发票类型：0：增值税专票 1：增值税普票 4：增值税电子发票
    string mail = 6;        // 购方邮箱，用于发给患者电子发票链接
    string matchId = 7;     // 匹配流水
    string orderNo = 8;
    string phone = 9;
    string pscriptId = 10;  // 处方单号
}

// 发送发票请求
message PushInvoiceRequest{
    // 发票信息
    message InvoiceInfo{
        double amount = 1;      // 订单总金额
        string custName = 2;    // 购方名称(发票抬头)
        repeated InvoiceDetail invoiceDetails = 3;
    }
    repeated InvoiceInfo invoices = 1;
}

// 发票响应
message PushInvoiceResponse{
    message Result{
        string message = 1;     // 处理信息
        string orderNo = 2;     // 订单编号
        bool result = 3;       // 处理结果：true 、 false
    }
    int32 code = 1;
    string msg = 2;
    string resultCode = 3;
    string resultMsg = 4;     
    repeated Result contents = 5;
}

//处方订单确认请求
message ConfirmOrderOpenHisAPIRequest{
    string orderNo = 1;
    int32 orderId = 2;
    string payTime = 3;
    string invoiceTitle = 4;
    double orderFee = 5;
    double drugFee = 6;
    double deliveryFee = 7;
    string deliveryId = 8;           //快递请求流水 （传空）
    string dpDeliveryId = 9;       //药商快递报价ID （传空）
    int32 isExpress = 10;                     //取药方式：0-快递，1-到店自取
    int32 payOff = 11;
    repeated DpPrescription pscripts = 12;
    ContactInfo contactInfo = 13;
    DrugStore drugStore = 14;
}

//处方订单确认响应
message ConfirmOrderOpenHisAPIResponse{
    int32 code = 1;
    string msg = 2;
    bool success = 3;
    string data = 4;
}
// 对应 central-control-service 项目的 sinopharm.js 文件
service SinopharmService{
    //药品匹配信息
    rpc drugMatching(DrugMatchingRequest) returns (DrugMatchingResponse);	
    
    //处方订单确认
    rpc confirmOrder(ConfirmOrderRequest) returns (ConfirmOrderResponse);

    //发送发票信息
    rpc pushInvoice(PushInvoiceRequest) returns (PushInvoiceResponse);

    //处方OpenHisAPI订单确认
    rpc confirmOpenHisAPIOrder(ConfirmOrderOpenHisAPIRequest) returns (ConfirmOrderOpenHisAPIResponse);
}