控制器代码:
#region 入院登记
public ActionResult SaveRegisterInsert(Patient patient,
RegisterAdmission registerAdmission)
{
ReturnJson RtJson = new ReturnJson();
try
{
//判断数据是否为空
if ((!String.IsNullOrEmpty(registerAdmission.HealthDiagnosis) ||
!String.IsNullOrEmpty(registerAdmission.ClinicDiagnosis)) &&
registerAdmission.InpatientWardId > 0 && registerAdmission.DepartmentId > 0 &&
registerAdmission.HospitalWayId > 0 && registerAdmission.PayModeId > 0 &&
registerAdmission.BedId > 0)
{
//去重复
int OldCount = (from tbRegisterAdmission in myModels.RegisterAdmission
where tbRegisterAdmission.RegisterAdmissionId != registerAdmission.RegisterAdmissionId &&
(tbRegisterAdmission.PatientId == patient.PatientId &&
(tbRegisterAdmission.DischargeTime == null ||
tbRegisterAdmission.AdmissionStateId != 2 ||
tbRegisterAdmission.AdmissionStateId != 5 ||
tbRegisterAdmission.AdmissionStateId != 6)) ||
tbRegisterAdmission.BedId == registerAdmission.BedId
select tbRegisterAdmission).Count();
if (OldCount == 0)
{
//Patient dbPatient = new Patient();
patient.PatientId = patient.PatientId;
patient.DateOfBirth = patient.DateOfBirth;
//patient.PatientTypeId = patient.PatientTypeId;
patient.AdmissionStateId = 1;
//修改
myModels.Entry(patient).State = System.Data.Entity.EntityState.Modified;
if (myModels.SaveChanges() > 0)
{
registerAdmission.PatientId = patient.PatientId;
registerAdmission.AdmissionStateId = 1;
registerAdmission.StaffId = registerAdmission.StaffId;
registerAdmission.BedId = registerAdmission.BedId;
registerAdmission.OutPatientDoctorId = registerAdmission.OutPatientDoctorId;
if (registerAdmission.AdmissionDate == null)
{
registerAdmission.AdmissionDate = DateTime.Now;
}
else if (registerAdmission.AdmissionDate < DateTime.Now &&
registerAdmission.AdmissionDate != null)
{
registerAdmission.AdmissionDate = registerAdmission.AdmissionDate;
}
else if (registerAdmission.AdmissionDate > DateTime.Now)
{
RtJson.Text = "入院日期大于当前时间!";
}
if (!String.IsNullOrEmpty(registerAdmission.ClinicDiagnosis))
{
if (registerAdmission.DiagnosisDate < DateTime.Now &&
registerAdmission.DiagnosisDate != null)
{
registerAdmission.DiagnosisDate = registerAdmission.DiagnosisDate;
}
else if (registerAdmission.DiagnosisDate == null)
{
registerAdmission.DiagnosisDate = DateTime.Now;
}
else if (registerAdmission.DiagnosisDate > DateTime.Now ||
registerAdmission.DiagnosisDate > registerAdmission.AdmissionDate)
{
RtJson.Text = "诊断日期大于当前时间或大于入院时间!";
}
registerAdmission.ClinicDiagnosis = registerAdmission.ClinicDiagnosis;
}
//新增
myModels.RegisterAdmission.Add(registerAdmission);
if (myModels.SaveChanges() > 0)
{
RtJson.State = true;
RtJson.Text = "登记入院成功!";
}
}
else
{
RtJson.State = false;
RtJson.Text = "登记入院失败!";
}
}
else
{
RtJson.Text = "登记信息已重复,请检查是否重复登记!";
}
}
else
{
RtJson.Text = "请将登记信息填写完整!";
}
}
catch (Exception)
{
RtJson.Text = "数据异常!";
}
return Json(RtJson, JsonRequestBehavior.AllowGet);
}
#endregion
页面样式代码:
Js代码:
//登记入院
$("#AdmissionBtn").click(function () {
//判断病人ID是否为空
if (obj.data.PatientId > 0) {
$.post("/Main/SelectStaff", {}, function (JsonData) {
$("#StaffID").val(JsonData.value);
$("#staffCode").val(JsonData.text);
}, "json");
OpenAdmissionModal();
//console.log(obj.data);
loadDatatoForm("PatientForm>div:hidden", obj.data);
$("#dateOfBirth").val(obj.data.Birthday);
$("#InpatientWard").val(0);
$("#Department").val(0);
$("#Bed").val(0);
$("#HospitalWay").val(0);
$("#PayMode").val(0);
$.post("SelectPatientByID",
{ PatientID: obj.data.PatientId },
function (rtMsg) {
//$("#patientTypeID").val(rtMsg.PatientTypeId);
$("#PatientType").val(rtMsg.PatientTypeId);
});
$("#OutPatientDoctor").attr("disabled", "");
$("#clinicDiagnosis").change(function () {
var ClDi = $("#clinicDiagnosis").val();
if (IsNullorNot(ClDi)) {
$("#OutPatientDoctor").attr("disabled", "");
$("#OutPatientDoctor").val(0);
} else {
$("#OutPatientDoctor").removeAttr("disabled", "");
}
});
}
});
//打开登记入院的模态框
function OpenAdmissionModal() {
//重置表格
$("#formPatient")[0].reset();
$("#PatientForm>div").attr("hidden", "");
//设置模态框标题
$("#modalPatientTitle").text("登记入院");
$("#PatientForm>div:gt(25)").removeAttr("hidden", "");
$("#PatientForm>div:eq(34)>label").text("费用类别");
$("#PatientForm>div:gt(41)").attr("hidden", "");
//设置请求路径
$("#formPatient").prop("action", "SaveRegisterInsert");
//弹出模态框,设置点击背景&按下Esc的时候不动态关闭模态框
$("#modalPatient").modal({ backdrop: 'static', keyboard: false });
}
//保存新增/修改
function SavePatient() {
//获取页面填写数据
var ArrData = $("#formPatient").resize();
//声明一个变量,对象类型的变量
var JsonObj = {};
//创建对象,FormData
var FmData = new FormData();
//fmData.append(名称,值);
//将序列化出来的对象数组转化为JSON对象 for in遍历对象属性
for (var index in ArrData) {
//console.log(index);
//JsonObj[键] = 值;
JsonObj[ArrData[index].name] = ArrData[index].value;
//将页面数据传入FormData对象里
FmData.append(ArrData[index].name, ArrData[index].value);
}
//console.log(JsonObj);
//打开加载层
var Index = layer.load();
$("#formPatient").ajaxSubmit(function (RtMsg) {
//关闭加载层
layer.close(Index);
if (RtMsg.State) {
//关闭模态框
$('#modalPatient').modal("hide");
//输出
layer.alert(RtMsg.Text, { icon: 1, title: "提示" });
//刷新页面
//window.location.reload();
tabPatient.reload({ page: { curr: 1 } });
}
else {
layer.alert(RtMsg.Text, { icon: 0, title: "提示" });
}
});
}
效果图: