Пример #1
0
        public IQueryable <HistoricoPacienteDTO> List(Guid?idpacinte = null, bool?soinativos = null)
        {
            var historicospacientes = repository.List();

            if (soinativos != null)
            {
                if (soinativos == true)
                {
                    historicospacientes = historicospacientes.Where(a => a.inativo != null);
                }
                else
                {
                    historicospacientes = historicospacientes.Where(a => a.inativo == null);
                }
            }

            if (idpacinte != null)
            {
                historicospacientes = historicospacientes.Where(a => a.idpaciente == idpacinte);
            }

            return(historicospacientes.ProjectTo <HistoricoPacienteDTO>(mapper.ConfigurationProvider));
        }
Пример #2
0
        public void Update(Guid Idpaciente, PacienteUpdateDTO pacienteNew)
        {
            var _pacienteNew = mapper.Map <paciente>(pacienteNew);

            repository.Update(Idpaciente, _pacienteNew);

            var idhispacientes = pacienteNew.historicoPaciente.Where(a => a.idhispaciente != null)
                                 .Select(a => (Guid)a.idhispaciente)
                                 .ToArray();
            var idhispacientesDell = historicoRepository.List()
                                     .Where(a => a.idpaciente == Idpaciente && (!idhispacientes.Contains(a.idhispaciente) || a.inativo == null))
                                     .Select(a => a.idhispaciente)
                                     .ToArray();

            foreach (var IdDell in idhispacientesDell)
            {
                historicoRepository.Delete(IdDell);
            }

            foreach (var historico in pacienteNew.historicoPaciente)
            {
                var _historico = mapper.Map <historicopaciente>(historico);

                if (historico.idhispaciente == null)
                {
                    _historico.idhispaciente = Guid.NewGuid();
                    _historico.idpaciente    = _pacienteNew.idpaciente;

                    historicoRepository.Insert(_historico);
                }
            }



            var Idpacientesinformacoes = pacienteNew.pacienteInformacao.Where(a => a.Idpacienteinformacao != null)
                                         .Select(a => (Guid)a.Idpacienteinformacao)
                                         .ToArray();
            var IdpacientesinformacoesDell = pacienteInformacaoRepository.List()
                                             .Where(a => a.idpaciente == Idpaciente && !Idpacientesinformacoes.Contains(a.Idpacienteinformacao))
                                             .Select(a => a.Idpacienteinformacao)
                                             .ToArray();

            foreach (var IdDell in IdpacientesinformacoesDell)
            {
                pacienteInformacaoRepository.Delete(IdDell);
            }

            foreach (var pacienteInformacao in pacienteNew.pacienteInformacao)
            {
                var _pacienteInformacao = mapper.Map <pacienteinformacao>(pacienteInformacao);

                if (pacienteInformacao.Idpacienteinformacao == null)
                {
                    _pacienteInformacao.Idpacienteinformacao = Guid.NewGuid();
                    _pacienteInformacao.idpaciente           = _pacienteNew.idpaciente;

                    pacienteInformacaoRepository.Insert(_pacienteInformacao);
                }
                else
                {
                    pacienteInformacaoRepository.Update(_pacienteInformacao.Idpacienteinformacao, _pacienteInformacao);
                }
            }
        }