Esempio n. 1
0
        public string EndPatientCare(string exitDate, int exitReason, string facilityOutTransfer, string dateOfDeath, string careEndingNotes)
        {
            try
            {
                DateTime?emptyDateOfDeath = null;

                PatientCareEndingManager careEndingManager    = new PatientCareEndingManager();
                PatientEnrollmentManager enrollmentManager    = new PatientEnrollmentManager();
                PatientLookupManager     patientLookupManager = new PatientLookupManager();



                patientId            = int.Parse(Session["PatientPK"].ToString());
                patientMasterVisitId = int.Parse(Session["PatientMasterVisitId"].ToString());
                var enrollments = enrollmentManager.GetPatientEnrollmentByPatientId(patientId);
                if (enrollments.Count > 0)
                {
                    patientEnrollmentId = enrollments[0].Id;
                }

                var patient = patientLookupManager.GetPatientDetailSummary(patientId);

                if (patientEnrollmentId > 0)
                {
                    if (!String.IsNullOrWhiteSpace(facilityOutTransfer))
                    {
                        careEndingManager.AddPatientCareEndingTransferOut(patientId, patientMasterVisitId,
                                                                          patientEnrollmentId,
                                                                          exitReason, DateTime.Parse(exitDate), GlobalObject.unescape(facilityOutTransfer),
                                                                          GlobalObject.unescape(careEndingNotes));
                    }
                    else if (String.IsNullOrWhiteSpace(facilityOutTransfer) && String.IsNullOrWhiteSpace(dateOfDeath))
                    {
                        careEndingManager.AddPatientCareEndingOther(patientId, patientMasterVisitId,
                                                                    patientEnrollmentId,
                                                                    exitReason, DateTime.Parse(exitDate), GlobalObject.unescape(careEndingNotes));
                    }
                    else
                    {
                        careEndingManager.AddPatientCareEndingDeath(patientId, patientMasterVisitId, patientEnrollmentId,
                                                                    exitReason, DateTime.Parse(exitDate), (string.IsNullOrEmpty(dateOfDeath))?DateTime.Parse(dateOfDeath):emptyDateOfDeath, GlobalObject.unescape(careEndingNotes));
                    }



                    PatientEntityEnrollment entityEnrollment =
                        enrollmentManager.GetPatientEntityEnrollment(patientEnrollmentId);
                    entityEnrollment.CareEnded = true;
                    enrollmentManager.updatePatientEnrollment(entityEnrollment);
                    Session["EncounterStatusId"] = 0;
                    Session["PatientEditId"]     = 0;
                    Session["PatientPK"]         = 0;
                    Msg = "Patient has been successfully care ended";
                    MessageEventArgs args = new MessageEventArgs()
                    {
                        PatientId     = patientId,
                        EntityId      = patientEnrollmentId,
                        MessageType   = MessageType.UpdatedClientInformation,
                        EventOccurred = "Patient CareEnded Identifier = ",
                        FacilityId    = patient.FacilityId
                    };
                    Publisher.RaiseEventAsync(this, args).ConfigureAwait(false);
                }
                else
                {
                    SoapException b = new SoapException();
                    SoapException e = (SoapException)Activator.CreateInstance(b.GetType(), "Patient is already care ended", b);
                    Msg = e.Message;
                }
            }
            catch (SoapException e)
            {
                Msg = e.Message;
            }
            return(Msg);
        }
Esempio n. 2
0
        public string UpdatePatientEnrollment(string enrollmentNo, string enrollmentDate, string serviceName)
        {
            ExMessage message = new ExMessage();

            try
            {
                var patientPK                 = Convert.ToInt32(Session["PatientPK"]);
                var patientEnrollment         = new PatientEnrollmentManager();
                var patientIdentifier         = new PatientIdentifierManager();
                var patientMasterVisitManager = new PatientMasterVisitManager();
                var patientManager            = new PatientLookupManager();

                var lookupLogic        = new LookupLogic();
                var patientIdentifiers = lookupLogic.GetItemIdByGroupAndDisplayName("PatientIdentifier", serviceName);
                var identifierId       = 0;
                if (patientIdentifiers.Count > 0)
                {
                    identifierId = patientIdentifiers[0].ItemId;
                }

                var patient = patientManager.GetPatientDetailSummary(patientPK);
                if (DateTime.Parse(enrollmentDate) < DateTime.Parse(patient.DateOfBirth.ToString()))
                {
                    var DOBexception = new SoapException("Enrollment Date: " + enrollmentDate + " should not be before the date of birth " + DateTime.Parse(patient.DateOfBirth.ToString()).ToString("dd-MM-yyyy"), SoapException.ClientFaultCode);
                    throw DOBexception;
                }

                var enrollmentIdentifiers = lookupLogic.GetItemIdByGroupAndDisplayName("VisitType", "Enrollment");
                var itemId = 0;
                if (enrollmentIdentifiers.Count > 0)
                {
                    itemId = enrollmentIdentifiers[0].ItemId;
                }

                List <PatientMasterVisit> visitsNonEnrollments = patientMasterVisitManager.GetNonEnrollmentVisits(patientPK, itemId);

                var identifierTypesCheck = patientIdentifier.CheckIfIdentifierNumberIsUsed(enrollmentNo, identifierId);

                if (identifierTypesCheck.Count > 0)
                {
                    if (patientPK != identifierTypesCheck[0].PatientId)
                    {
                        var exception = new SoapException("No: " + enrollmentNo + " already exists", SoapException.ClientFaultCode);
                        throw exception;
                    }
                }

                if (visitsNonEnrollments.Count > 0)
                {
                    foreach (var items in visitsNonEnrollments)
                    {
                        if (DateTime.Parse(enrollmentDate) > items.VisitDate)
                        {
                            var newexception = new SoapException("Enrollment Date: " + enrollmentDate + " is after encounters in the system", SoapException.ClientFaultCode);
                            throw newexception;
                        }
                    }
                }

                List <PatientEntityEnrollment> entityEnrollments = new List <PatientEntityEnrollment>();

                if (patientPK > 0)
                {
                    entityEnrollments = patientEnrollment.GetPatientEnrollmentByPatientId(patientPK);

                    if (entityEnrollments.Count > 0)
                    {
                        var identifiers = patientIdentifier.GetPatientEntityIdentifiers(patientPK, entityEnrollments[0].Id, identifierId);

                        if (identifiers.Count > 0)
                        {
                            var identifiersAuditData = AuditDataUtility.Serializer(identifiers);
                            identifiers[0].IdentifierValue = enrollmentNo;
                            identifiers[0].AuditData       = identifiersAuditData;


                            patientIdentifier.UpdatePatientIdentifier(identifiers[0], patient.FacilityId);
                        }

                        var enrollmentAuditData = AuditDataUtility.Serializer(entityEnrollments);

                        entityEnrollments[0].EnrollmentDate = DateTime.Parse(enrollmentDate);
                        entityEnrollments[0].AuditData      = enrollmentAuditData;

                        patientEnrollment.updatePatientEnrollment(entityEnrollments[0]);

                        message.errorcode = 0;
                        message.msg      += "<p>Successfully edited patient enrollment.</p>";
                    }
                }
            }
            catch (SoapException ex)
            {
                message.errorcode = 1;
                message.msg       = ex.Message;
            }

            return(Msg = new JavaScriptSerializer().Serialize(message));
        }