public void Edit(PrescriptionModel prescription) { PrescriptionData data = new PrescriptionData(); string prescriberId = RequestContext.Principal.Identity.GetUserId(); data.EditPrescription(prescription, prescriberId); }
/// <summary> /// Processes the row. /// </summary> /// <param name="row">The row.</param> public virtual void ProcessRow(PrescriptionData row) { if (row.BNFCode == BnfCode) { TotalSold += row.Items; TotalCost += row.ActualCost; } }
public override void ProcessRow(PrescriptionData row) { // Get region from practices string rowRegion = Practices.GetPracticeRegionByPracticeCode(row.PracticeCode); // If row matches search criteria, add it if (row.BNFCode == BnfCode && rowRegion == Region.ToString()) { total += row.NIC; } }
/// <summary> /// Processes the row. /// </summary> /// <param name="row">The row.</param> public override void ProcessRow(PrescriptionData row) { // Get region from practices string rowRegion = practices.GetPracticeRegionByPracticeCode(row.PracticeCode); // If row matches search criteria, add it if (row.BNFCode == BnfCode && rowRegion == Region.ToString()) { TotalSold += row.Items; TotalCost += row.ActualCost; } }
public void PopulateRowData() { ValidRow = new PrescriptionData { PracticeCode = Data.PracticeCode1, BNFCode = Data.BnfCode1, Items = Data.Items1, NIC = Data.Cost1, ActualCost = Data.Cost2, SHA = string.Empty, PCT = string.Empty, BNFName = string.Empty, Period = string.Empty }; ValidRowDifferentCosts = new PrescriptionData { PracticeCode = Data.PracticeCode1, BNFCode = Data.BnfCode1, Items = Data.Items2, NIC = Data.Cost2, ActualCost = Data.Cost3, SHA = string.Empty, PCT = string.Empty, BNFName = string.Empty, Period = string.Empty }; ZeroRow = new PrescriptionData { PracticeCode = Data.PracticeCode1, BNFCode = Data.BnfCode1, Items = Data.ItemsZero, NIC = Data.CostZero, ActualCost = Data.CostZero, SHA = string.Empty, PCT = string.Empty, BNFName = string.Empty, Period = string.Empty }; ValidRowBnfCode2 = new PrescriptionData { PracticeCode = Data.PracticeCode1, BNFCode = Data.BnfCode2, Items = Data.Items1, NIC = Data.Cost1, ActualCost = Data.Cost1, SHA = string.Empty, PCT = string.Empty, BNFName = string.Empty, Period = string.Empty }; ValidRowPractice2 = new PrescriptionData { PracticeCode = Data.PracticeCode2, BNFCode = Data.BnfCode1, Items = Data.Items1, NIC = Data.Cost1, ActualCost = Data.Cost2, SHA = string.Empty, PCT = string.Empty, BNFName = string.Empty, Period = string.Empty }; }
public async Task <IActionResult> Prescription(PrescriptionData data) { try { var info = data.PrescriptionInfo; var code = HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value; if (string.IsNullOrEmpty(code)) { return(ErrorResult("توکن نامعتبر است", 403)); } var pharmacy = await repo.GetPharmacyByCode(code); if (pharmacy == null) { return(ErrorResult("توکن نامعتبر است، اطلاعات داروخانه یافت نشد", 403)); } if (info == null || info.Payload == null) { return(ErrorResult("داده های ورودی نامعتبر میباشند", 400)); } var patientInfo = info.Payload.PatientInfo; if (patientInfo == null || patientInfo.PatientId == null || string.IsNullOrEmpty(patientInfo.PatientId.Content)) { return(ErrorResult("کد ملی بیمار یافت نشد", 400)); } if (info.Payload.MedicationsInfo.Count == 0) { return(ErrorResult("اطلاعات دارو یافت نشد", 400)); } var patient = await repo.GetPatientByCode(patientInfo.PatientId.Content); if (patient == null) { patient = await repo.NewPatient(CreatePatientEntity(patientInfo)); } var now = DateTime.Now; var medicines = await repo.GetMedicinesByPatient(patient.Id); var illegalDrug = ""; var prescriptionMedicines = new List <PrescriptionMedicine>(); var status = Status.NoTracked; // وضعیت پیش فرض foreach (var med in info.Payload.MedicationsInfo) { var genericCode = med.AcceptedMedicationItemInfo.GenericCode; var medicine = medicines.SingleOrDefault(a => a.GenericCode == genericCode.Content); if (medicine != null) { status = Status.Verified; // اگر یکی از داروها، در لیست وجود داشت وضعیت به تایید شده تغیر میکند //var usedAmount = medicine.PrescriptionMedicines // .Where(a => a.Prescription.PatientId == patient.Id && // !a.Prescription.RawData.IsCanceled && // a.Prescription.DeliveryDate > now.AddDays(-a.Medicine.UsagePeriod)) // .Sum(a => a.Amount); double usedAmount = 0; foreach (var pm in medicine.PrescriptionMedicines) { if (pm.Prescription.PatientId != patient.Id) { continue; } if (pm.Prescription.RawData.IsCanceled) { continue; } if (pm.Prescription.DeliveryDate <= now.AddDays(-pm.Medicine.UsagePeriod)) { continue; } usedAmount += pm.Amount; } if (usedAmount + med.AcceptedMedicationItemInfo.MedicationCount.Content > medicine.MaximumUsageAmount) { illegalDrug += " /" + medicine.FaName + "، " + medicine.Dosage; status = Status.Unverified; // چنانچه داروی مورد نظر تایید نشود، وضعیت به تایید نشده تغیر میکند } prescriptionMedicines.Add(new PrescriptionMedicine() { Amount = med.AcceptedMedicationItemInfo.MedicationCount.Content, MedicineId = medicine.Id, }); } } var rnd = new Random(now.Millisecond); var rawData = new RawData() { IsCanceled = false, Json = JsonSerializer.Serialize(info), PharmacyId = pharmacy.Id, ReceivedDate = now, Status = status, TrackCode = Helpers.Random(rnd) }; await repo.NewRawData(rawData); if (status == Status.NoTracked) { // تمام اقلام نسخه مجاز میباشند چون هیچ یک از داروهای آن در لیست داروها یافت نشد return(Ok(new ServicePrescriptionResult() { IllegalDrug = "", MessageCode = 1, Message = "کلیه اقلام نسخه مجاز میباشند.", TrackNo = rawData.TrackCode })); } else if (status == Status.Unverified) { // برخی اقلام فاقد اعتبار مجاز میباشند return(Ok(new ServicePrescriptionResult() { IllegalDrug = illegalDrug, MessageCode = 0, Message = " برخی اقلام فاقد اعتبار مجاز میباشند.", TrackNo = rawData.TrackCode })); } // در غیر اینصورت باید نسخه و داروهای آن ثبت شوند var medicalCouncilCode = info.Payload.AdmissionInfo?.HealthCenterInfo?.AttendingDoctorInfo?.MedicalCouncilCode?.Content; Physician physician = null; if (!string.IsNullOrEmpty(medicalCouncilCode)) { physician = await repo.GetPhysicianByCode(medicalCouncilCode); } if (physician == null) { var specialities = await repo.GetSpecialities(); physician = await repo.NewPhysician(CreatePhysicianEntity(info.Payload.AdmissionInfo.HealthCenterInfo.AttendingDoctorInfo, specialities)); } var prescription = new Prescription() { DeliveryDate = info.Payload.AdmissionInfo.AdmissionDate.DateContent.ToGregoryDate() ?? now, PatientId = patient.Id, PharmacyId = pharmacy.Id, PhysicianId = physician.Id, PrescriptionDate = info.Payload.PrescriptionDate.DateContent.ToGregoryDate() ?? now, SubmitDate = now, PrescriptionMedicines = prescriptionMedicines, Distributions = new List <Distribution>() }; foreach (var pm in prescriptionMedicines) { var lastStock = await repo.GetMedicineStock(pm.MedicineId, prescription.PharmacyId); prescription.Distributions.Add( new Distribution() { Amount = -pm.Amount, DateTime = now, MedicineId = pm.MedicineId, PharmacyId = prescription.PharmacyId, PrescriptionId = prescription.Id, Stock = lastStock - pm.Amount } ); } rawData.Prescription = prescription; prescription.RawData = rawData; await repo.NewPrescription(prescription); return(Ok(new ServicePrescriptionResult() { IllegalDrug = "", MessageCode = 1, Message = "کلیه اقلام نسخه مجاز میباشند.", TrackNo = rawData.TrackCode })); } catch (Exception ex) { return(ErrorResult(ex.Message, 500)); } }