/// <summary>
        /// 获取门诊病人费用明细
        /// </summary>

        /// <param name="param"></param>
        /// <returns></returns>
        public List <BaseOutpatientDetailDto> GetOutpatientDetailPerson(OutpatientDetailParam param)
        {
            var resultData = new List <BaseOutpatientDetailDto>();
            var xmlData    = new MedicalInsuranceXmlDto();

            xmlData.BusinessId        = param.BusinessId;
            xmlData.HealthInsuranceNo = "48";//42MZ
            xmlData.TransactionId     = param.User.TransKey;
            xmlData.AuthCode          = param.User.AuthCode;
            xmlData.UserId            = param.User.UserId;
            xmlData.OrganizationCode  = param.User.OrganizationCode;
            var jsonParam = JsonConvert.SerializeObject(xmlData);
            var data      = _webServiceBasic.HIS_Interface("39", jsonParam);
            OutpatientPersonJsonDto dataValue = JsonConvert.DeserializeObject <OutpatientPersonJsonDto>(data.Msg);

            var detailInfo = dataValue.DetailInfo;

            foreach (var item in detailInfo)
            {
                var detail = AutoMapper.Mapper.Map <BaseOutpatientDetailDto>(item);
                detail.OrganizationCode = param.User.OrganizationCode;
                detail.OrganizationName = param.User.OrganizationName;
                detail.OutpatientNo     = dataValue.OutpatientPersonBase.OutpatientNumber;
                resultData.Add(detail);
            }
            if (param.IsSave)
            {
                _hisSqlRepository.SaveOutpatientDetail(param.User, resultData);
            }
            return(resultData);
        }
        /// <summary>
        /// 获取门诊病人
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public BaseOutpatientInfoDto GetOutpatientPerson(GetOutpatientPersonParam param)
        {
            BaseOutpatientInfoDto resultData = null;
            var xmlData = new MedicalInsuranceXmlDto();

            xmlData.BusinessId        = param.UiParam.BusinessId;
            xmlData.HealthInsuranceNo = "48";//42MZ
            xmlData.TransactionId     = param.UiParam.TransKey;
            xmlData.AuthCode          = param.User.AuthCode;
            xmlData.UserId            = param.User.UserId;
            xmlData.OrganizationCode  = param.User.OrganizationCode;
            var jsonParam = JsonConvert.SerializeObject(xmlData);
            var data      = _webServiceBasic.HIS_Interface("39", jsonParam);
            OutpatientPersonJsonDto dataValue = JsonConvert.DeserializeObject <OutpatientPersonJsonDto>(data.Msg);
            var dataValueFirst = dataValue.OutpatientPersonBase;

            if (dataValueFirst != null)
            {
                resultData                = AutoMapper.Mapper.Map <BaseOutpatientInfoDto>(dataValueFirst);
                resultData.Id             = param.Id;
                resultData.BusinessId     = param.UiParam.BusinessId;
                resultData.DiagnosticJson = JsonConvert.SerializeObject(dataValue.DiagnosisList);
                resultData.DiagnosisList  = dataValue.DiagnosisList;
                if (param.IsSave)
                {
                    _hisSqlRepository.SaveOutpatient(param.User, resultData);
                }
            }
            return(resultData);
        }
        /// <summary>
        /// 获取his住院预结算
        /// </summary>
        /// <param name="param"></param>
        public HisHospitalizationPreSettlementJsonDto GetHisHospitalizationPreSettlement(GetInpatientInfoParam param)
        {
            var xmlData = new MedicalInsuranceXmlDto();

            xmlData.BusinessId        = param.BusinessId;
            xmlData.HealthInsuranceNo = "43";
            xmlData.TransactionId     = param.User.TransKey;
            xmlData.AuthCode          = param.User.AuthCode;
            xmlData.UserId            = param.User.UserId;
            xmlData.OrganizationCode  = param.User.OrganizationCode;
            var jsonParam = JsonConvert.SerializeObject(xmlData);
            var data      = _webServiceBasic.HIS_Interface("39", jsonParam);
            HisHospitalizationPreSettlementJsonDto dataValue = JsonConvert.DeserializeObject <HisHospitalizationPreSettlementJsonDto>(data.Msg);

            return(dataValue);
        }
 public ApiJsonResultData GetInpatientInfoDetail([FromUri] GetInpatientInfoDetailParam param)
 {
     return(new ApiJsonResultData(ModelState, new InpatientInfoDetailDto()).RunWithTry(y =>
     {
         var userBase = webServiceBasicService.GetUserBaseInfo(param.UserId);
         var xmlData = new MedicalInsuranceXmlDto();
         var transactionId = Guid.NewGuid().ToString("N");
         xmlData.BusinessId = param.BusinessId;
         xmlData.HealthInsuranceNo = "31";
         xmlData.TransactionId = transactionId;
         xmlData.AuthCode = userBase.AuthCode;
         xmlData.UserId = userBase.UserId;
         xmlData.OrganizationCode = userBase.OrganizationCode;
         var data = webServiceBasic.HIS_Interface("39", JsonConvert.SerializeObject(xmlData));
     }));
 }
        /// <summary>
        /// 获取住院明细
        /// </summary>
        /// <param name="user"></param>
        /// <param name="businessId"></param>
        /// <returns></returns>
        public List <InpatientInfoDetailDto> GetInpatientInfoDetail(UserInfoDto user, string businessId)
        {
            var resultData = new List <InpatientInfoDetailDto>();

            var queryParam = new DatabaseParam()
            {
                Field     = "BusinessId",
                Value     = businessId,
                TableName = "Inpatient"
            };
            var inpatientData = _hisSqlRepository.QueryDatabase(new InpatientEntity(), queryParam);

            if (inpatientData == null)
            {
                throw new Exception("该病人未在中心库中,请检查是否办理医保入院!!!");
            }
            //获取当前病人
            var inpatient     = inpatientData.FirstOrDefault();
            var transactionId = Guid.NewGuid().ToString("N");
            var xmlData       = new MedicalInsuranceXmlDto();

            xmlData.BusinessId        = businessId;
            xmlData.HealthInsuranceNo = "31";
            xmlData.TransactionId     = transactionId;
            xmlData.AuthCode          = user.AuthCode;
            xmlData.UserId            = user.UserId;
            xmlData.OrganizationCode  = user.OrganizationCode;
            var data = _webServiceBasic.HIS_Interface("39", JsonConvert.SerializeObject(xmlData));
            InpatientDetailListJsonDto dataValue = JsonConvert.DeserializeObject <InpatientDetailListJsonDto>(data.Msg);

            if (dataValue != null)
            {
                resultData = AutoMapper.Mapper.Map <List <InpatientInfoDetailDto> >(dataValue.DetailList);
                var saveParam = new SaveInpatientInfoDetailParam()
                {
                    DataList          = resultData,
                    HospitalizationId = inpatient.HospitalizationId,
                    User = user
                };
                _hisSqlRepository.SaveInpatientInfoDetail(saveParam);
                //    //  var msg = "获取住院号【" + resultFirst.住院号 + "】,业务ID【" + param.业务ID + "】的时间段内的住院费用成功,共" + result.Count +
                //    //          "条记录";
                //}
            }

            return(resultData);
        }
        public HisHospitalizationSettlementCancelInfoJsonDto GetOutpatientSettlementCancel(SettlementCancelParam param)
        {
            var resultData = new PatientLeaveHospitalInfoDto();
            var xmlData    = new MedicalInsuranceXmlDto();

            xmlData.BusinessId        = param.BusinessId;
            xmlData.HealthInsuranceNo = "42MZ";
            xmlData.TransactionId     = param.User.TransKey;
            xmlData.AuthCode          = param.User.AuthCode;
            xmlData.UserId            = param.User.UserId;
            xmlData.OrganizationCode  = param.User.OrganizationCode;
            var jsonParam = JsonConvert.SerializeObject(xmlData);
            var data      = _webServiceBasic.HIS_Interface("39", jsonParam);
            HisHospitalizationSettlementCancelJsonDto dataValue = JsonConvert.DeserializeObject <HisHospitalizationSettlementCancelJsonDto>(data.Msg);

            return(dataValue.InfoData);
        }
        /// <summary>
        /// 获取his住院结算
        /// </summary>
        /// <param name="param"></param>
        public PatientLeaveHospitalInfoDto GetHisHospitalizationSettlement(GetInpatientInfoParam param)
        {
            var resultData = new PatientLeaveHospitalInfoDto();
            var xmlData    = new MedicalInsuranceXmlDto();

            xmlData.BusinessId        = param.BusinessId;
            xmlData.HealthInsuranceNo = "41";
            xmlData.TransactionId     = param.User.TransKey;
            xmlData.AuthCode          = param.User.AuthCode;
            xmlData.UserId            = param.User.UserId;
            xmlData.OrganizationCode  = param.User.OrganizationCode;
            var jsonParam = JsonConvert.SerializeObject(xmlData);
            var data      = _webServiceBasic.HIS_Interface("39", jsonParam);
            HisHospitalizationSettlementJsonDto dataValue = JsonConvert.DeserializeObject <HisHospitalizationSettlementJsonDto>(data.Msg);
            var dataValueFirst = dataValue.LeaveHospitalInfoData.FirstOrDefault();

            //实体转换
            if (dataValueFirst != null)
            {
                resultData.LeaveHospitalBedNumber        = dataValueFirst.LeaveHospitalBedNumber;
                resultData.LeaveHospitalDate             = dataValueFirst.LeaveHospitalDate;
                resultData.LeaveHospitalDepartmentId     = dataValueFirst.LeaveHospitalDepartmentId;
                resultData.LeaveHospitalDepartmentName   = dataValueFirst.LeaveHospitalDepartmentName;
                resultData.LeaveHospitalDiagnosticDoctor = dataValueFirst.LeaveHospitalDiagnosticDoctor;
                resultData.LeaveHospitalOperator         = dataValueFirst.LeaveHospitalOperator;
            }
            var diagnosisList = dataValue.DiagnosisJson.Select(c => new InpatientDiagnosisDto()
            {
                DiseaseCoding   = c.DiseaseCoding,
                DiseaseName     = c.DiagnosisName,
                ProjectCode     = c.DiagnosisMedicalInsuranceCode,
                IsMainDiagnosis = c.IsMainDiagnosis == "是" ? true : false,
            }).ToList();

            resultData.DiagnosisList = diagnosisList;
            return(resultData);
        }
 public ApiJsonResultData CancelOutpatientDepartmentCost([FromUri] CancelOutpatientDepartmentCostUiParam param)
 {
     return(new ApiJsonResultData(ModelState).RunWithTry(y =>
     {
         var userBase = webServiceBasicService.GetUserBaseInfo(param.UserId);
         userBase.TransKey = param.TransKey;
         var xmlData = new MedicalInsuranceXmlDto();
         xmlData.BusinessId = param.BusinessId;
         xmlData.HealthInsuranceNo = "42";//42MZ
         xmlData.TransactionId = param.TransKey;
         xmlData.AuthCode = userBase.AuthCode;
         xmlData.UserId = param.UserId;
         xmlData.OrganizationCode = userBase.OrganizationCode;
         var jsonParam = JsonConvert.SerializeObject(xmlData);
         var data = webServiceBasic.HIS_Interface("39", jsonParam);
         HisHospitalizationSettlementCancelJsonDto dataValue = JsonConvert.DeserializeObject <HisHospitalizationSettlementCancelJsonDto>(data.Msg);
         //{\"基础信息\":{\"ORGID\":\"9F44A548B22A4F84BC59A59FF4796D53\",\"YBCODE\":\"123\",\"INFID\":\"6F63E04260974852B0F461D6108DB688\",\"结算编号\":\"34556\",\"就诊编号\":\"34556\",\"经办人\":\"医保接口\"}}
         ////回参构建
         var xmlDatas = new OutpatientDepartmentCostCancelXml()
         {
             SettlementNo = dataValue.InfoData.SettlementNo
         };
         var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlDatas);
         var saveXml = new SaveXmlDataParam()
         {
             User = userBase,
             MedicalInsuranceBackNum = "Qxjs",
             MedicalInsuranceCode = "42MZ",
             BusinessId = param.BusinessId,
             BackParam = strXmlBackParam
         };
         //存基层
         webServiceBasic.SaveXmlData(saveXml);
         //_outpatientDepartmentNewService.CancelOutpatientDepartmentCost(param);
     }));
 }
 /// <summary>
 /// 获取医保构建参数
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public void GetXmlData(MedicalInsuranceXmlDto param)
 {
     var data = _webServiceBasic.HIS_InterfaceList("39", JsonConvert.SerializeObject(param));
 }
        /// <summary>
        /// 获取住院病人信息
        /// </summary>
        /// <param name="infoParam"></param>
        /// <returns></returns>
        public InpatientInfoDto GetInpatientInfo(GetInpatientInfoParam param)
        {
            var resultData = new InpatientInfoDto();
            var xmlData    = new MedicalInsuranceXmlDto();

            xmlData.BusinessId        = param.BusinessId;
            xmlData.HealthInsuranceNo = "21";
            xmlData.TransactionId     = param.User.TransKey;
            xmlData.AuthCode          = param.User.AuthCode;
            xmlData.UserId            = param.User.UserId;
            xmlData.OrganizationCode  = param.User.OrganizationCode;
            var data = _webServiceBasic.HIS_Interface("39", JsonConvert.SerializeObject(xmlData));
            InpatientInfoJsonDto dataValue = JsonConvert.DeserializeObject <InpatientInfoJsonDto>(data.Msg);

            if (dataValue != null && dataValue.InpatientInfoJsonData != null)
            {
                var diagnosisList = dataValue.DiagnosisJson.Select(c => new InpatientDiagnosisDto()
                {
                    DiseaseCoding   = c.DiseaseCoding,
                    DiseaseName     = c.DiseaseName,
                    IsMainDiagnosis = c.IsMainDiagnosis == "是" ? true : false,
                    ProjectCode     = c.ProjectCode,
                }).ToList();
                resultData = new InpatientInfoDto()
                {
                    DiagnosisList               = diagnosisList,
                    HospitalizationId           = dataValue.InpatientInfoJsonData.HospitalizationId,
                    BusinessId                  = param.BusinessId,
                    DiagnosisJson               = JsonConvert.SerializeObject(dataValue.DiagnosisJson),
                    AdmissionBed                = dataValue.InpatientInfoJsonData.AdmissionBed,
                    AdmissionDate               = dataValue.InpatientInfoJsonData.AdmissionDate,
                    AdmissionDiagnosticDoctor   = dataValue.InpatientInfoJsonData.AdmissionDiagnosticDoctor,
                    AdmissionDiagnosticDoctorId = dataValue.InpatientInfoJsonData.AdmissionDiagnosticDoctorId,
                    AdmissionMainDiagnosis      = dataValue.InpatientInfoJsonData.AdmissionMainDiagnosis,
                    AdmissionMainDiagnosisIcd10 = dataValue.InpatientInfoJsonData.AdmissionMainDiagnosisIcd10,
                    AdmissionOperateTime        = dataValue.InpatientInfoJsonData.AdmissionOperateTime,
                    AdmissionOperator           = dataValue.InpatientInfoJsonData.AdmissionOperator,
                    AdmissionWard               = dataValue.InpatientInfoJsonData.AdmissionWard,
                    FamilyAddress               = dataValue.InpatientInfoJsonData.FamilyAddress,
                    IdCardNo          = dataValue.InpatientInfoJsonData.IdCardNo,
                    PatientName       = dataValue.InpatientInfoJsonData.PatientName,
                    PatientSex        = dataValue.InpatientInfoJsonData.PatientSex,
                    ContactName       = dataValue.InpatientInfoJsonData.ContactName,
                    ContactPhone      = dataValue.InpatientInfoJsonData.ContactPhone,
                    Remark            = dataValue.InpatientInfoJsonData.Remark,
                    HospitalName      = param.User.OrganizationName,
                    HospitalizationNo = dataValue.InpatientInfoJsonData.HospitalizationNo,
                    TransactionId     = param.User.TransKey,
                    InDepartmentName  = dataValue.InpatientInfoJsonData.InDepartmentName,
                    InDepartmentId    = dataValue.InpatientInfoJsonData.InDepartmentId,
                    DocumentNo        = dataValue.InpatientInfoJsonData.DocumentNo,
                };
                if (param.IsSave == true)
                {
                    //删除以前记录
                    var deleteData = _hisSqlRepository.DeleteDatabase(new DeleteDatabaseParam()
                    {
                        User      = param.User,
                        Field     = "BusinessId",
                        Value     = param.BusinessId,
                        TableName = "Inpatient"
                    });
                    //添加病人信息
                    var inpatientEntity = new InpatientEntity();
                    var insertEntity    = AutoMapper.Mapper.Map <InpatientEntity>(resultData);
                    insertEntity.Id = Guid.NewGuid();

                    inpatientBaseService.Insert(insertEntity, param.User);
                }
            }

            return(resultData);
        }
        public ApiJsonResultData MedicalInsuranceXmlCancelSettlement([FromUri] MedicalInsuranceXmlUiParam param)
        {
            return(new ApiJsonResultData(ModelState, new UiInIParam()).RunWithTry(y =>
            {
                var userBase = webServiceBasicService.GetUserBaseInfo(param.UserId);
                userBase.TransKey = param.TransKey;



                var resultData = new InpatientInfoDto();
                var xmlData = new MedicalInsuranceXmlDto();
                xmlData.BusinessId = param.BusinessId;
                xmlData.HealthInsuranceNo = "41";
                xmlData.TransactionId = userBase.TransKey;
                xmlData.AuthCode = userBase.AuthCode;
                xmlData.UserId = userBase.UserId;
                xmlData.OrganizationCode = userBase.OrganizationCode;
                var data = webServiceBasic.HIS_Interface("39", JsonConvert.SerializeObject(xmlData));



                ////回参构建
                //var xmlData = new OutpatientDepartmentCostCancelXml()
                //{
                //    SettlementNo = param.SettlementNo
                //};
                //var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
                //var saveXml = new SaveXmlDataParam()
                //{
                //    User = userBase,
                //    MedicalInsuranceBackNum = "Qxjs",
                //    MedicalInsuranceCode = "46",
                //    BusinessId = param.BusinessId,
                //    BackParam = strXmlBackParam
                //};
                ////存基层
                //webServiceBasic.SaveXmlData(saveXml);

                ////回参构建
                //var xmlData = new HospitalSettlementCancelXml()
                //{
                //    SettlementNo = param.SettlementNo,
                //};
                //var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
                //var saveXml = new SaveXmlDataParam()
                //{
                //    User = userBase,
                //    MedicalInsuranceBackNum = "CXJB011",
                //    MedicalInsuranceCode = "42",
                //    BusinessId = param.BusinessId,
                //    BackParam = strXmlBackParam
                //};
                ////存基层
                //webServiceBasic.SaveXmlData(saveXml);

                //var ddd = "123";
                ////更新医保信息
                //var strXmlIntoParam = XmlSerializeHelper.XmlParticipationParam();
                ////回参构建
                //var xmlData = new HospitalSettlementCancelXml()
                //{


                //    SettlementNo = param.SettlementNo
                //};

                //var strXmlBackParam = XmlSerializeHelper.HisXmlSerialize(xmlData);
                //var saveXmlData = new SaveXmlData();
                //saveXmlData.OrganizationCode = userBase.OrganizationCode;
                //saveXmlData.AuthCode = userBase.AuthCode;
                //saveXmlData.BusinessId = param.BusinessId;
                //saveXmlData.TransactionId =param.TransKey;
                //saveXmlData.MedicalInsuranceBackNum = "CXJB003";
                //saveXmlData.BackParam = CommonHelp.EncodeBase64("utf-8", strXmlBackParam);
                //saveXmlData.IntoParam = CommonHelp.EncodeBase64("utf-8", strXmlIntoParam);
                //saveXmlData.MedicalInsuranceCode = "42";
                //saveXmlData.UserId = userBase.UserId;
                ////存基层
                //webServiceBasic.HIS_InterfaceList("38", JsonConvert.SerializeObject(saveXmlData));
            }));
        }