Exemplo n.º 1
0
        public async Task <ActionResult <Patient> > PutPatient(int id, Patient patient)
        {
            if (id != patient.PatientId)
            {
                return(BadRequest());
            }

            _context.Entry(patient).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PatientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            var result = await _context.Patients.FindAsync(id);

            return(result);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutTreatment(int id, Treatment treatment)
        {
            if (id != treatment.TreatmentId)
            {
                return(BadRequest());
            }

            _context.Entry(treatment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TreatmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutTreatmentType(int id, TreatmentType treatmentType)
        {
            if (id != treatmentType.TreatmentTypeId)
            {
                return(BadRequest());
            }

            _context.Entry(treatmentType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TreatmentTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetTreatmentType", new { id = treatmentType.TreatmentTypeId }, treatmentType));
        }
Exemplo n.º 4
0
        public async Task <TreatmentType> Add(TreatmentType treatmentType)
        {
            var result = _context.TreatmentTypes.Add(treatmentType);
            await _context.SaveChangesAsync();

            return(result.Entity);
        }
Exemplo n.º 5
0
        public async Task <Patient> Add(Patient Patient)
        {
            await _context.Patients.AddAsync(Patient);

            await _context.SaveChangesAsync();

            return(Patient);
        }
Exemplo n.º 6
0
        public async Task <Patient> Add(Patient patient)
        {
            patient.CreatedAt = DateTime.Now;
            Console.WriteLine(patient.CreatedAt);
            _context.Patients.Add(patient);

            await _context.SaveChangesAsync();

            return(patient);
        }
Exemplo n.º 7
0
        public async Task <ActionResult <PatientDTO> > AddPatient(PatientDTO dto)
        {
            if (ModelState.IsValid)
            {
                var patient = _mapper.Map <Patient>(dto);

                using (var trans = _context.Database.BeginTransaction())
                {
                    _context.Patients.Add(patient);
                    await _context.SaveChangesAsync();

                    await _sender.SendMessage(new MessagePayload
                    {
                        EmailAddress = dto.Email ?? "*****@*****.**",
                        Message      = "Powiadomienie o kwarantannie.",
                        Title        = "COVID-19"
                    });

                    await trans.CommitAsync();

                    return(CreatedAtAction(nameof(GetPatient), new { id = patient.Id }, patient));
                }
            }

            return(BadRequest());
        }
Exemplo n.º 8
0
        public async Task <ActionResult <TreatmentViewModel> > PutTreatment(int id, Treatment treatment)
        {
            if (id != treatment.TreatmentId)
            {
                System.Console.WriteLine("Hello from Error");
                return(BadRequest());
            }

            _context.Entry(treatment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TreatmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            var treatmentType = await _context.TreatmentTypes.FindAsync(treatment.TreatmentTypeId);

            var t = await _context.Treatments.FindAsync(id);


            var result = new TreatmentViewModel()
            {
                TreatmentId        = t.TreatmentId,
                UserId             = t.UserId,
                TreatmentCost      = t.TreatmentCost,
                CreatedAt          = t.CreatedAt,
                TreatmentImageUrl  = t.TreatmentImageUrl,
                TreatmentImageName = t.TreatmentImageName,
                PatientId          = t.PatientId,
                TreatmentName      = treatmentType.Name,
                TreatmentTypeId    = t.TreatmentTypeId
            };

            return(result);
        }
Exemplo n.º 9
0
        public async Task <Patient> AddPatient(Patient model)
        {
            if (model == null)
            {
                throw new Exception("model should not be null");
            }
            var patient = await _dbContext.Patients.FirstOrDefaultAsync(x => x.FirstName == model.FirstName &&
                                                                        x.LastName == model.LastName && x.DateOfBirth == model.DateOfBirth);

            if (patient != null)
            {
                throw new Exception("This patient already exists in the database");
            }

            await _dbContext.Patients.AddAsync(model);

            await _dbContext.SaveChangesAsync();

            return(model);
        }
        public async Task <IActionResult> PostRecordAsync([FromBody] PatientModel request)
        {
            Logger?.LogDebug("'{0}' has been invoked", nameof(PostRecordAsync));

            var response = new SingleResponse <PatientModel>();

            try
            {
                var existingEntity = await DbContext
                                     .GetPatientDetailByNameAsync(new Patient { Forename = request.Forename, Surname = request.Surname });

                if (existingEntity != null)
                {
                    ModelState.AddModelError("PatientModel", "Patient name already exists");
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                Patient entity = new Patient
                {
                    Forename        = request.Forename,
                    Surname         = request.Surname,
                    Gender          = request.Gender,
                    DateOfBirth     = request.DateOfBirth,
                    TelephoneNumber = request.TelephoneNumber != null?JsonConvert.SerializeObject(request.TelephoneNumber) : null,
                                          CreatedOn = DateTime.UtcNow,
                                          CreatedBy = "System"
                };

                // Add entity to repository
                DbContext.Add(entity);

                // Save entity in database
                await DbContext.SaveChangesAsync();

                // Set the entity to response model
                response.Model = request;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = "There was an internal error, please contact to support.";

                Logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(PostRecordAsync), ex);
            }

            return(response.ToHttpResponse());
        }
Exemplo n.º 11
0
        public async Task <TreatmentViewModel> Add(Treatment treatment)
        {
            treatment.CreatedAt = DateTime.Now;
            _context.Treatments.Add(treatment);
            await _context.SaveChangesAsync();

            var treatmentType = await _context.TreatmentTypes.FindAsync(treatment.TreatmentTypeId);


            var result = new TreatmentViewModel()
            {
                TreatmentId        = treatment.TreatmentId,
                UserId             = treatment.UserId,
                TreatmentCost      = treatment.TreatmentCost,
                CreatedAt          = treatment.CreatedAt,
                TreatmentImageUrl  = treatment.TreatmentImageUrl,
                TreatmentImageName = treatment.TreatmentImageName,
                PatientId          = treatment.PatientId,
                TreatmentName      = treatmentType.Name,
                TreatmentTypeId    = treatment.TreatmentTypeId
            };

            return(result);
        }
Exemplo n.º 12
0
        public async Task SavePatientAsync(PatientModel patient)
        {
            await _dbContext.Patients.AddAsync(MapPatientModelToPatient(patient));

            await _dbContext.SaveChangesAsync();
        }