public async Task <IActionResult> UploadMedicalRecord([FromBody] UploadMedicalRecordInput input) { Patient patient = await dbContext.Patients.FirstOrDefaultAsync(p => p.Id == input.PatientId); if (patient == null) { return(BadRequest(Json(new { Error = "不存在该患者" }))); } InitialDiagnosis initialDiagnosis = await dbContext.InitialDiagnoses.FirstOrDefaultAsync(i => i.PatientId == patient.Id); if (initialDiagnosis == null) { return(BadRequest(Json(new { Error = "该患者未填写初步诊断" }))); } PastMedicalHistory pastMedicalHistory = await dbContext.PastMedicalHistories.FirstOrDefaultAsync(p => p.PatientId == patient.Id); if (pastMedicalHistory == null) { return(BadRequest(Json(new { Error = "该患者未填写既往史" }))); } Symptom symptom = await dbContext.Symptoms.FirstOrDefaultAsync(s => s.PatientId == patient.Id); if (symptom == null) { return(BadRequest(Json(new { Error = "该患者未填写症状体征信息" }))); } List <FoodInfo> foodInfos = await dbContext.FoodInfos.Where(f => f.PatientId == patient.Id).ToListAsync(); XmlHelper xmlHelper = new XmlHelper(); string requestXml = ""; if (input.OperationType == 3) { requestXml = xmlHelper.ConvertToXml(input.OperationType, apiOptions, patient); } else { requestXml = xmlHelper.ConvertToXml(input.OperationType, apiOptions, patient, initialDiagnosis, pastMedicalHistory, symptom, foodInfos); } ReportServiceClient reportService = new ReportServiceClient(); string responseString = await reportService.WEBRequestAsync(Encrypt.Base64Encode(requestXml)); string responseXmlString = Encrypt.Base64Decode(responseString); XmlReader xmlReader = XmlReader.Create(new StringReader(responseXmlString)); XDocument xdoc = XDocument.Load(xmlReader); UploadMedicalRecordOutput output = new UploadMedicalRecordOutput { Code = Convert.ToInt32(xdoc.Element("接口").Element("操作状态").Value), Msg = xdoc.Element("接口").Element("状态描述").Value }; if (input.OperationType == 1 && output.Code == 1) { patient.Status = "已上传"; } if (input.OperationType == 3 && output.Code == 1) { patient.Status = "正常"; } dbContext.Patients.Update(patient); dbContext.SaveChanges(); return(new ObjectResult(output)); }