public async Task <OutpatientModel> GetOutpatientByPatientAndDoctorId(DoctorPatientModel model) { var outpatient = await _context.OutpatientCards .FirstOrDefaultAsync(x => x.PatientId == model.PatientId && x.DoctorId == model.DoctorId); var newOutpatient = new OutpatientModel { CreatedDate = outpatient.CreatedDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture), Description = outpatient.Description, OutpatientCardId = outpatient.OutpatientCardId, Status = (OutpatientStatuses)outpatient.Status }; var userResponse = await RequestExecutor.ExecuteRequestAsync( MicroservicesEnum.User, RequestUrl.GetPatientById, new Parameter[] { new Parameter("patientId", (int)outpatient.PatientId, ParameterType.GetOrPost) }); var patientData = JsonConvert.DeserializeObject <MksResponse>(userResponse); if (!patientData.Success) { throw new Exception(patientData.Data); } var patientCtx = JsonConvert.DeserializeObject <Patients>(patientData.Data); newOutpatient.Patient = patientCtx; var diseaseResponse = await RequestExecutor.ExecuteRequestAsync( MicroservicesEnum.Medical, RequestUrl.GetDiseaseNameById, new Parameter[] { new Parameter("diseaseId", model.DiseaseId, ParameterType.GetOrPost) }); var diseaseResponseName = JsonConvert.DeserializeObject <MksResponse>(diseaseResponse); var diseaseName = string.Empty; if (diseaseResponseName.Success) { diseaseName = JsonConvert.DeserializeObject <string>(diseaseResponseName.Data); } outpatient.DiseaseId = model.DiseaseId; await _context.SaveChangesAsync(); newOutpatient.Disease = diseaseName; return(newOutpatient); }
public async Task <IActionResult> GetOutpatientByPatientAndDoctorId([FromBody] DoctorPatientModel model) { try { var outpat = await _outpatientRepository.GetOutpatientByPatientAndDoctorId(model); return(Json( new { Success = true, Data = JsonConvert.SerializeObject(outpat) })); } catch (Exception exception) { return(Json(new { Success = false, exception.Message })); } }
// Get (DoctorPatientModel) patient detail for doctor public DoctorPatientModel GetDoctorPatientDetail(int patientId) { var model = new DoctorPatientModel(); var patient = db.TM_Users.Find(patientId); var patDetail = db.TM_Patient.Where(p => p.UserId == patientId).FirstOrDefault(); var address = db.UserAddresses.Where(ua => ua.UserId == patientId) .Join( db.TM_Address, // first table u => u.AddressId, // first key a => a.Id, (u, a) => new { a.Id, a.Address, a.WardId } ).FirstOrDefault(); model.PatientId = patientId; model.PatientName = patient.FullName; model.AssurenceCard = patDetail.AssuranceCard; model.Gender = patient.Gender == "M" ? "Nam" : patient.Gender == "F" ? "Nữ" : "Khác"; model.LastOrder = GetLastOrder(patientId); model.Age = patient.DateOfBirth == null ? 0 : DateTime.Now.Year - patient.DateOfBirth.Value.Year; model.FullAddress = address == null?null:ToFullAddress((int)address.WardId, address.Address); return(model); }