Exemple #1
0
        public DeletePatientObservationByPatientIdDataResponse DeletePatientObservationByPatientId(DeletePatientObservationByPatientIdDataRequest request)
        {
            DeletePatientObservationByPatientIdDataResponse response = null;

            try
            {
                response = new DeletePatientObservationByPatientIdDataResponse();
                IPatientObservationRepository repo = Factory.GetRepository(request, RepositoryType.PatientObservation);
                List <PatientObservationData> patientObservations = repo.FindObservationIdByPatientId(request.PatientId) as List <PatientObservationData>;
                List <string> deletedIds = null;
                if (patientObservations != null)
                {
                    deletedIds = new List <string>();
                    patientObservations.ForEach(u =>
                    {
                        //request.Id = u.Id;
                        DeletePatientObservationRequest deletePatientObservationRequest = new DeletePatientObservationRequest {
                            Context              = request.Context,
                            ContractNumber       = request.ContractNumber,
                            UserId               = request.UserId,
                            Version              = request.Version,
                            PatientObservationId = u.Id,
                        };
                        repo.Delete(deletePatientObservationRequest);
                        deletedIds.Add(deletePatientObservationRequest.PatientObservationId);
                    });
                    response.DeletedIds = deletedIds;
                }
                response.Success = true;
                return(response);
            }
            catch (Exception ex) { throw ex; }
        }
        void IRepository.Delete(object entity)
        {
            DeletePatientObservationRequest request = (DeletePatientObservationRequest)entity;

            try
            {
                using (PatientObservationMongoContext ctx = new PatientObservationMongoContext(_dbName))
                {
                    var q = MB.Query <MEPatientObservation> .EQ(b => b.Id, ObjectId.Parse(request.PatientObservationId));

                    var uv = new List <MB.UpdateBuilder>();
                    uv.Add(MB.Update.Set(MEPatientObservation.TTLDateProperty, System.DateTime.UtcNow.AddDays(_expireDays)));
                    uv.Add(MB.Update.Set(MEPatientObservation.LastUpdatedOnProperty, System.DateTime.UtcNow));
                    uv.Add(MB.Update.Set(MEPatientObservation.DeleteFlagProperty, true));
                    uv.Add(MB.Update.Set(MEPatientObservation.UpdatedByProperty, ObjectId.Parse(this.UserId)));

                    IMongoUpdate update = MB.Update.Combine(uv);
                    ctx.PatientObservations.Collection.Update(q, update);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientObservation.ToString(),
                                             request.PatientObservationId,
                                             Common.DataAuditType.Delete,
                                             request.ContractNumber);
                }
            }
            catch (Exception) { throw; }
        }