public override Result <EmergencyRequiredVehicle> Register(EmergencyRequiredVehicleModel model)
        {
            try
            {
                EmergencyRequiredVehicle emergencyRequiredVehicle = _mapper.Map <EmergencyRequiredVehicle>(model);

                var result = _emergencyRequiredVehicleValidation.Validate(emergencyRequiredVehicle);
                if (!result.Success)
                {
                    return(result);
                }

                var emergency = _emergencyDAL.Find(new EmergencyFilter {
                    Id = model.EmergencyId
                });
                if (emergency.EmergencyStatus != EmergencyStatus.Committed)
                {
                    emergency.EmergencyStatus = EmergencyStatus.InService;
                    _emergencyDAL.Update(emergency);
                }

                _emergencyRequiredVehicleDAL.Insert(emergencyRequiredVehicle);

                MedicalDecisionHistory medicalDecision = _mapper.Map <MedicalDecisionHistory>(model.MedicalDecisionHistoryModel);
                _medicalDecisionHistoryDAL.Insert(medicalDecision);

                var resultSave = _emergencyRequiredVehicleDAL.Save();
                if (!resultSave.Success)
                {
                    return(Result <EmergencyRequiredVehicle> .BuildError(resultSave.Messages));
                }

                return(Result <EmergencyRequiredVehicle> .BuildSuccess(null));
            }
            catch (Exception error)
            {
                return(Result <EmergencyRequiredVehicle> .BuildError("Erro no momento de registar do veículo requerido para a ocorrência.", error));
            }
        }
示例#2
0
        public override Result <EmergencyHistory> Register(EmergencyHistoryModel model)
        {
            try
            {
                EmergencyHistory emergencyHistory = _mapper.Map <EmergencyHistory>(model);

                var emergency = _emergencyDAL.Find(new EmergencyFilter {
                    Id = model.EmergencyId
                });
                emergency.EmergencyStatus = model.EmergencyStatus;
                _emergencyDAL.Update(emergency);

                //var resultEmergency = _emergencyBLL.SimpleUpdate(model.EmergencyModel);
                //if (!resultEmergency.Success)
                //    return Result<EmergencyHistory>.BuildError(resultEmergency.Messages);

                var result = _emergencyHistoryValidation.Validate(emergencyHistory);
                if (!result.Success)
                {
                    return(result);
                }

                _emergencyHistoryDAL.Insert(emergencyHistory);

                var resultSave = _emergencyHistoryDAL.Save();
                if (!resultSave.Success)
                {
                    return(Result <EmergencyHistory> .BuildError(resultSave.Messages));
                }

                return(Result <EmergencyHistory> .BuildSuccess(null));
            }
            catch (Exception error)
            {
                return(Result <EmergencyHistory> .BuildError("Erro no momento de registar o histórico de ocorrência.", error));
            }
        }
示例#3
0
        public override Result <Emergency> Update(EmergencyModel model)
        {
            try
            {
                //lógica para remover pacientes vazios
                var patientsRemove = model.PatientModels.Where
                                     (
                    d => d.Age == 0 &&
                    d.Gender == Entities.Enums.Gender.Invalido &&
                    string.IsNullOrWhiteSpace(d.Name) &&
                    d.Id == 0
                                     ).ToList();
                patientsRemove.ForEach(d => model.PatientModels.Remove(d));

                Emergency emergency = _mapper.Map <Emergency>(model);

                var history = _emergencyHistoryDAL
                              .Find(new EmergencyHistoryFilter {
                    EmergencyId = emergency.Id, EmergencyStatus = EmergencyStatus.InEvaluation
                });

                if (history == null)
                {
                    if (emergency.EmergencyHistories == null)
                    {
                        emergency.EmergencyHistories = new List <EmergencyHistory>();
                    }

                    emergency.EmergencyHistories.Add(new EmergencyHistory
                    {
                        Date            = DateTime.Now,
                        Description     = "Ocorrência em Avaliação",
                        Emergency       = emergency,
                        EmergencyStatus = emergency.EmergencyStatus,
                        EmployeeGuid    = model.EmployeeGuid
                    });
                }

                if ((model?.AddressModel?.Id ?? 0) == 0)
                {
                    var resultAddress = _addressBLL.Register(model.AddressModel);
                    if (!resultAddress.Success)
                    {
                        return(Result <Emergency> .BuildError(resultAddress.Messages));
                    }
                    emergency.Address = resultAddress.Model;
                }
                else
                {
                    var resultAddress = _addressValidation.Validate(emergency.Address);
                    if (!resultAddress.Success)
                    {
                        return(Result <Emergency> .BuildError(resultAddress.Messages));
                    }
                }

                foreach (var patientModel in model.PatientModels)
                {
                    if ((patientModel?.Id ?? 0) == 0)
                    {
                        patientModel.EmergencyId = emergency.Id;
                        var resultPatient = _patientBLL.Register(patientModel);
                        if (!resultPatient.Success)
                        {
                            return(Result <Emergency> .BuildError(resultPatient.Messages));
                        }
                    }
                    else
                    {
                        var patient = emergency.Patients.FirstOrDefault(d => d.Id == patientModel.Id);
                        patient.EmergencyId = emergency.Id;
                        var resultPatient = _patientValidation.Validate(patient);
                        if (!resultPatient.Success)
                        {
                            return(Result <Emergency> .BuildError(resultPatient.Messages));
                        }
                    }
                }

                var result = _emergencyValidation.Validate(emergency);
                if (!result.Success)
                {
                    return(result);
                }

                _emergencyDAL.Update(emergency);
                var resultSave = _emergencyDAL.Save();
                if (!resultSave.Success)
                {
                    return(Result <Emergency> .BuildError(resultSave.Messages));
                }

                return(Result <Emergency> .BuildSuccess(null));
            }
            catch (Exception error)
            {
                return(Result <Emergency> .BuildError("Erro ao alterar o registro da ocorrência.", error));
            }
        }