Example #1
0
 public static bool InsertMedicine(Medicine medicine)
 {
     return(ErpServer.InsertMedicine(medicine));
 }
Example #2
0
        /// <summary>
        /// save prescription as an history record to patient
        /// and as an prescription image attachment
        /// </summary>
        /// <param name="historyRecord">
        /// record that contains symptoms, diseases, medicines and remarks that was writen to patient
        /// </param>
        /// <param name="patientMedicines">written medicines names</param>
        /// <param name="dosesDescription">written medicines doses</param>
        /// <param name="medicinesAlternatives">written medicines alternatives</param>
        /// <param name="savingPath">
        /// path that will be saved as attribute in attachment for prscription image
        /// </param>
        /// <param name="notifyPrognosis">user ID and diseases that marked as genetic by doctor</param>
        /// <returns>bitmap prescription image to be saved to server then downloaded</returns>
        public Bitmap SavePrescription(HistoryRecord historyRecord, string[] patientMedicines,
                                       string[] dosesDescription, List <List <string> > medicinesAlternatives, string savingPath, Action <long, string> notifyPrognosis = null)
        {
            PrescriptionCanvas canvas = new PrescriptionCanvas();
            Bitmap             bitmap = null;
            string             medicineName;
            int prescriptionTypeID = 3;

            // get IDs of patient medicines names then assign doses to history record
            for (int i = 0; i < patientMedicines.Length; i++)
            {
                medicineName = patientMedicines[i];
                if (!medicineName.Equals(""))
                {
                    Medicine medicine = DBEntities.Medicines.FirstOrDefault(m => m.Name == medicineName);
                    if (medicine == null)
                    {
                        return(null);
                    }

                    historyRecord.Doses.Add(new Dose
                    {
                        MedicineID  = medicine.ID,
                        Description = dosesDescription[i]
                    });
                }
            }

            // save history record to database
            historyRecord.IsRead = false;
            historyRecord        = DBEntities.HistoryRecords.Add(historyRecord);

            // get whole object of this history record
            historyRecord.MedicalPlace = DBEntities.MedicalPlaces.Single(medicalPlace =>
                                                                         medicalPlace.ID == historyRecord.MedicalPlaceID);
            historyRecord.Citizen = DBEntities.Citizens.Single(citizen =>
                                                               citizen.Id == historyRecord.CitizenID);
            historyRecord.Specialist = DBEntities.Citizens.OfType <Specialist>().Single(specialist =>
                                                                                        specialist.Id == historyRecord.SpecialistID);

            // create prescription only if doctor wrote drugs to patient
            if (patientMedicines[0] != "")
            {
                // add prescription as an attachment
                Attachment attachment = new Attachment
                {
                    TypeID       = prescriptionTypeID,
                    Date         = historyRecord.Date,
                    SpecialistID = historyRecord.SpecialistID,
                    CitizenID    = historyRecord.CitizenID,
                    FilePath     = savingPath,
                    FileName     = Path.GetFileName(savingPath),
                    IsRead       = false
                };

                // save attachment to database
                SaveAttachment(attachment);

                // Draw prescription as image
                bitmap = canvas.Draw(historyRecord, patientMedicines,
                                     medicinesAlternatives, dosesDescription);
            }
            NotifyForGeneticDiseases(historyRecord.Citizen, historyRecord, 0, true, notifyPrognosis);
            DBEntities.SaveChanges();
            return(bitmap);
        }