Ejemplo n.º 1
0
 //   private int ptnpk=0;
 public ShrApiManager()
 {
     _psmartShrManager  = new PsmartShrManager();
     _mstPatientManager = new MstPatientManager();
     //  _patientVisitManager=new PatientVisitManager();
     _patientProgramStart   = new PSmartPatientProgramStartManager();
     _hivTestTrackerManager = new HivTestTrackerManager();
     _immunizationTracker   = new ImmunizationTrackerManager();
     _utility = new Utility();
     _motherDetailsViewManager = new PsmartMotherDetailsViewManager();
     _patientIdentifierManager = new PatientIdentifierManager();
     _patientLookupManager     = new PatientLookupManager();
     _patientManager           = new PatientManager();
     personManager             = new PersonManager();
 }
Ejemplo n.º 2
0
        public static string Add(string firstName, string middleName, string lastName, int sex, int userId, DateTime dob, bool dobPrecision, int facilityId,
                                 int patientType, string nationalId, int visitType, DateTime dateOfEnrollment, string cccNumber, int entryPointId, string godsNumber, int matStatusId,
                                 string village, int wardId, int subCountyId, int countyId, string nearestLandMark, string postalAdress, string phoneNumber, DateTime?deathDate,
                                 List <NEXTOFKIN> nextofkin)
        {
            try
            {
                PersonManager              personManager             = new PersonManager();
                PatientManager             patientManager            = new PatientManager();
                PatientMasterVisitManager  patientMasterVisitManager = new PatientMasterVisitManager();
                PatientEnrollmentManager   patientEnrollmentManager  = new PatientEnrollmentManager();
                PatientEntryPointManager   patientEntryPointManager  = new PatientEntryPointManager();
                PersonLookUpManager        personLookUp = new PersonLookUpManager();
                PersonContactLookUpManager personContactLookUpManager = new PersonContactLookUpManager();
                MstPatientLogic            mstPatientLogic            = new MstPatientLogic();
                PatientIdentifierManager   patientIdentifierManager   = new PatientIdentifierManager();
                PersonMaritalStatusManager personMaritalStatusManager = new PersonMaritalStatusManager();
                PersonLocationManager      locationManager            = new PersonLocationManager();
                PersonContactManager       contactManager             = new PersonContactManager();
                var         treatmentSupporterManager = new PatientTreatmentSupporterManager();
                LookupLogic lookupLogic = new LookupLogic();

                var personIdentifierManager = new PersonIdentifierManager();
                //todo: fetch assigning facility from the message
                string assigning_Facility = "";
                var    personContacts     = new List <PersonContactLookUp>();
                int    ptn_Pk             = 0;

                //Start Saving
                int personId = personManager.AddPersonUiLogic(firstName, middleName, lastName, sex, userId, dob, dobPrecision);
                if (matStatusId > 0)
                {
                    personMaritalStatusManager.AddPatientMaritalStatus(personId, matStatusId, userId);
                }
                if (wardId > 0 && subCountyId > 0 && countyId > 0)
                {
                    locationManager.AddPersonLocation(personId, countyId, subCountyId, wardId, village, "", "", nearestLandMark, nearestLandMark, userId);
                }
                if (postalAdress != null || phoneNumber != null)
                {
                    contactManager.AddPersonContact(personId, postalAdress, phoneNumber, "", "", userId);
                }

                String   sDate        = DateTime.Now.ToString();
                DateTime datevalue    = Convert.ToDateTime(sDate);
                var      patientIndex = datevalue.Year.ToString() + '-' + personId;

                if (!string.IsNullOrWhiteSpace(godsNumber))
                {
                    IdentifierManager identifierManager = new IdentifierManager();
                    Identifier        identifier        = identifierManager.GetIdentifierByCode("GODS_NUMBER");
                    var personIdentifiers = personIdentifierManager.GetPersonIdentifiers(personId, identifier.Id);
                    if (personIdentifiers.Count == 0)
                    {
                        personIdentifierManager.AddPersonIdentifier(personId, identifier.Id, godsNumber, userId, assigning_Facility);
                    }
                }

                if (nextofkin.Count > 0)
                {
                    foreach (var kin in nextofkin)
                    {
                        if (kin.CONTACT_ROLE == "T")
                        {
                            //Get Gender
                            string gender = kin.SEX == "F" ? "Female" : "Male";
                            //IQCare Sex
                            int sexT = lookupLogic.GetItemIdByGroupAndItemName("Gender", gender)[0].ItemId;

                            int supporterId = personManager.AddPersonTreatmentSupporterUiLogic(kin.NOK_NAME.FIRST_NAME, kin.NOK_NAME.MIDDLE_NAME, kin.NOK_NAME.LAST_NAME, sexT, 1);

                            if (supporterId > 0)
                            {
                                treatmentSupporterManager.AddPatientTreatmentSupporter(personId, supporterId, kin.PHONE_NUMBER, userId);
                            }
                        }
                    }
                }

                PatientEntity patientEntity = new PatientEntity();
                patientEntity.PersonId     = personId;
                patientEntity.ptn_pk       = 0;
                patientEntity.FacilityId   = facilityId;
                patientEntity.PatientType  = patientType;
                patientEntity.PatientIndex = patientIndex;
                patientEntity.DateOfBirth  = dob;
                patientEntity.NationalId   = (nationalId);
                patientEntity.Active       = true;
                patientEntity.CreatedBy    = 1;
                patientEntity.CreateDate   = DateTime.Now;
                patientEntity.DeleteFlag   = false;
                patientEntity.DobPrecision = dobPrecision;

                int patientId = patientManager.AddPatient(patientEntity);

                var facility = lookupLogic.GetFacility();
                //Add enrollment visit
                int patientMasterVisitId = patientMasterVisitManager.AddPatientMasterVisit(patientId, userId, visitType, facility.FacilityID);
                //Enroll Patient to service
                int patientEnrollmentId = patientEnrollmentManager.addPatientEnrollment(patientId, dateOfEnrollment.ToString(), userId);
                //Add enrollment entry point
                int patientEntryPointId = patientEntryPointManager.addPatientEntryPoint(patientId, entryPointId, userId);

                if (deathDate.HasValue)
                {
                    PatientCareEndingManager careEndingManager = new PatientCareEndingManager();
                    int itemId = lookupLogic.GetItemIdByGroupAndItemName("CareEnded", "Death")[0].ItemId;
                    careEndingManager.AddPatientCareEndingDeath(patientId, patientMasterVisitId, patientEnrollmentId, itemId, deathDate.Value, deathDate.Value, "", null, null);

                    PatientEntityEnrollment entityEnrollment = patientEnrollmentManager.GetPatientEntityEnrollment(patientEnrollmentId);
                    entityEnrollment.CareEnded = true;
                    patientEnrollmentManager.updatePatientEnrollment(entityEnrollment);
                }
                //Get User Details to be used in BLUE CARD
                var patient_person_details = personLookUp.GetPersonById(personId);
                var greencardlookup        = new PersonGreenCardLookupManager();
                var greencardptnpk         = greencardlookup.GetPtnPkByPersonId(personId);

                if (patient_person_details != null)
                {
                    var maritalStatus = new PersonMaritalStatusManager().GetCurrentPatientMaritalStatus(personId);
                    personContacts = personContactLookUpManager.GetPersonContactByPersonId(personId);
                    var address = "";
                    var phone   = "";

                    if (personContacts.Count > 0)
                    {
                        address = personContacts[0].PhysicalAddress;
                        phone   = personContacts[0].MobileNumber;
                    }

                    var MaritalStatusId = 0;
                    if (maritalStatus != null)
                    {
                        MaritalStatusId = maritalStatus.MaritalStatusId;
                    }

                    var sexBluecard          = 0;
                    var enrollmentBlueCardId = "";

                    if (LookupLogic.GetLookupNameById(patient_person_details.Sex) == "Male")
                    {
                        sexBluecard = 16;
                    }
                    else if (LookupLogic.GetLookupNameById(patient_person_details.Sex) == "Female")
                    {
                        sexBluecard = 17;
                    }

                    enrollmentBlueCardId = cccNumber;

                    if (greencardptnpk.Count == 0)
                    {
                        ptn_Pk = mstPatientLogic.InsertMstPatient((patient_person_details.FirstName), (patient_person_details.LastName), (patient_person_details.MiddleName), facilityId, enrollmentBlueCardId, entryPointId, dateOfEnrollment, sexBluecard, dob, 1, MaritalStatusId, address, phone, 1, facilityId.ToString(), 203, dateOfEnrollment, DateTime.Now);

                        patientEntity.ptn_pk = ptn_Pk;
                        patientManager.UpdatePatient(patientEntity, patientId);
                    }
                    else
                    {
                        ptn_Pk = greencardptnpk[0].Ptn_Pk;
                        patientEntity.ptn_pk = greencardptnpk[0].Ptn_Pk;
                        patientManager.UpdatePatient(patientEntity, patientId);
                    }
                }

                if (patientMasterVisitId > 0)
                {
                    var assigningFacility   = cccNumber.Substring(0, 5);
                    int patientIdentifierId = patientIdentifierManager.addPatientIdentifier(patientId, patientEnrollmentId, 1, cccNumber, facilityId, assigningFacility, false);

                    if (greencardptnpk.Count == 0)
                    {
                        mstPatientLogic.AddOrdVisit(ptn_Pk, facilityId, DateTime.Now, 110, userId, DateTime.Now, 203);
                    }
                }

                return("successfully saved");
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 3
0
        public static string Update(string firstName, string middleName, string lastName, int personSex, int personId, int patientId, int?ptn_pk, DateTime dateOfBirth, bool DOB_Precision, string nationalId, int facilityId,
                                    int entryPointId, DateTime enrollmentDate, string cccNumber, PatientLookup patient, string godsNumber, int matStatusId,
                                    string village, int wardId, int subCountyId, int countyId, string nearestLandMark, string postalAdress, string phoneNumber, DateTime?deathDate,
                                    List <NEXTOFKIN> nextofkin, int userId)
        {
            try
            {
                //todo: fetch assigning facility from the message
                string        assigning_Facility       = "";
                PersonManager personManager            = new PersonManager();
                var           patientManager           = new PatientManager();
                var           patientEntryPointManager = new PatientEntryPointManager();
                var           patientIdentifierManager = new PatientIdentifierManager();
                var           patientEnrollmentManager = new PatientEnrollmentManager();
                var           personIdentifierManager  = new PersonIdentifierManager();
                PersonMaritalStatusManager personMaritalStatusManager = new PersonMaritalStatusManager();
                PersonLocationManager      locationManager            = new PersonLocationManager();
                PersonContactManager       contactManager             = new PersonContactManager();
                var personContactLookUp           = new PersonContactLookUpManager();
                var patientTreatmentlookupManager = new PatientTreatmentSupporterLookupManager();
                var treatmentSupporterManager     = new PatientTreatmentSupporterManager();

                personManager.UpdatePerson(firstName, middleName, lastName, personSex, userId, patient.PersonId, dateOfBirth, DOB_Precision);

                if (!string.IsNullOrWhiteSpace(godsNumber))
                {
                    IdentifierManager identifierManager = new IdentifierManager();
                    Identifier        identifier        = identifierManager.GetIdentifierByCode("GODS_NUMBER");
                    var personIdentifiers = personIdentifierManager.GetPersonIdentifiers(personId, identifier.Id);
                    if (personIdentifiers.Count == 0)
                    {
                        personIdentifierManager.AddPersonIdentifier(personId, identifier.Id, godsNumber, userId, assigning_Facility);
                    }
                }
                if (matStatusId > 0)
                {
                    var currentMaritalStatus = personMaritalStatusManager.GetCurrentPatientMaritalStatus(personId);
                    if (currentMaritalStatus != null)
                    {
                        currentMaritalStatus.MaritalStatusId = matStatusId;
                        personMaritalStatusManager.UpdatePatientMaritalStatus(currentMaritalStatus);
                    }
                    else
                    {
                        personMaritalStatusManager.AddPatientMaritalStatus(personId, matStatusId, userId);
                    }
                }

                if (wardId > 0 && subCountyId > 0 && countyId > 0)
                {
                    var currentLocation = locationManager.GetCurrentPersonLocation(personId);
                    if (currentLocation.Count > 0)
                    {
                        currentLocation[0].DeleteFlag = true;
                        locationManager.UpdatePersonLocation(currentLocation[0]);
                    }
                    locationManager.AddPersonLocation(personId, countyId, subCountyId, wardId, village, "", "", nearestLandMark, nearestLandMark, userId);
                }

                if (postalAdress != null || phoneNumber != null)
                {
                    var contacts = personContactLookUp.GetPersonContactByPersonId(personId);
                    if (contacts.Count > 0)
                    {
                        PersonContact perContact = new PersonContact();
                        perContact.Id                = contacts[0].Id;
                        perContact.PersonId          = contacts[0].PersonId;
                        perContact.PhysicalAddress   = (postalAdress);
                        perContact.MobileNumber      = (phoneNumber);
                        perContact.AlternativeNumber = "";
                        perContact.EmailAddress      = "";

                        contactManager.UpdatePatientContact(perContact);
                    }
                    else
                    {
                        contactManager.AddPersonContact(personId, postalAdress, phoneNumber, "", "", userId);
                    }
                }

                if (nextofkin.Count > 0)
                {
                    foreach (var kin in nextofkin)
                    {
                        if (kin.CONTACT_ROLE == "T")
                        {
                            //Get Gender
                            string gender = kin.SEX == "F" ? "Female" : "Male";
                            //IQCare Sex
                            LookupLogic lookupLogic = new LookupLogic();
                            int         sex         = lookupLogic.GetItemIdByGroupAndItemName("Gender", gender)[0].ItemId;

                            var listPatientTreatmentSupporter = patientTreatmentlookupManager.GetAllPatientTreatmentSupporter(personId);
                            if (listPatientTreatmentSupporter.Count > 0)
                            {
                                personManager.UpdatePerson(kin.NOK_NAME.FIRST_NAME, kin.NOK_NAME.MIDDLE_NAME, kin.NOK_NAME.LAST_NAME, sex, userId, listPatientTreatmentSupporter[0].SupporterId);
                                if (listPatientTreatmentSupporter[0].SupporterId > 0)
                                {
                                    var treatmentSupporter = patientTreatmentlookupManager.GetAllPatientTreatmentSupporter(personId);
                                    if (treatmentSupporter.Count > 0)
                                    {
                                        PatientTreatmentSupporter supporter = new PatientTreatmentSupporter()
                                        {
                                            Id            = treatmentSupporter[0].Id,
                                            PersonId      = personId,
                                            SupporterId   = listPatientTreatmentSupporter[0].SupporterId,
                                            MobileContact = kin.PHONE_NUMBER,
                                            CreatedBy     = treatmentSupporter[0].CreatedBy,
                                            DeleteFlag    = treatmentSupporter[0].DeleteFlag
                                        };

                                        treatmentSupporterManager.UpdatePatientTreatmentSupporter(supporter);
                                    }
                                }
                            }
                            else
                            {
                                int supporterId = personManager.AddPersonTreatmentSupporterUiLogic(kin.NOK_NAME.FIRST_NAME, kin.NOK_NAME.MIDDLE_NAME, kin.NOK_NAME.LAST_NAME, sex, userId);

                                if (supporterId > 0)
                                {
                                    treatmentSupporterManager.AddPatientTreatmentSupporter(personId, supporterId, kin.PHONE_NUMBER, userId);
                                }
                            }
                        }
                    }
                }

                List <PatientLookup> patientLookups = new List <PatientLookup>();
                patientLookups.Add(patient);
                var entity = patientLookups.ConvertAll(x => new PatientEntity {
                    Id = x.Id, Active = x.Active, DateOfBirth = x.DateOfBirth, ptn_pk = x.ptn_pk, PatientType = x.PatientType, PatientIndex = x.PatientIndex, NationalId = x.NationalId, FacilityId = x.FacilityId
                });
                var patientAuditData = AuditDataUtility.AuditDataUtility.Serializer(entity);

                PatientEntity updatePatient = new PatientEntity();
                updatePatient.ptn_pk       = ptn_pk;
                updatePatient.DateOfBirth  = dateOfBirth;
                updatePatient.DobPrecision = DOB_Precision;
                updatePatient.NationalId   = nationalId;
                updatePatient.FacilityId   = facilityId;
                updatePatient.AuditData    = patientAuditData;

                patientManager.UpdatePatient(updatePatient, patientId);

                List <PatientEntryPoint> entryPoints = patientEntryPointManager.GetPatientEntryPoints(patient.Id, 1);
                if (entryPoints.Count > 0)
                {
                    string entryPointAuditData = null;
                    entryPointAuditData = AuditDataUtility.AuditDataUtility.Serializer(entryPoints);

                    entryPoints[0].EntryPointId = entryPointId;
                    entryPoints[0].AuditData    = entryPointAuditData;
                    patientEntryPointManager.UpdatePatientEntryPoint(entryPoints[0]);
                }
                else
                {
                    patientEntryPointManager.addPatientEntryPoint(patientId, entryPointId, userId);
                }

                var identifiersByPatientId = patientIdentifierManager.GetPatientEntityIdentifiersByPatientId(patientId, 1);

                if (identifiersByPatientId.Count > 0)
                {
                    foreach (var entityIdentifier in identifiersByPatientId)
                    {
                        int enrollmentId = entityIdentifier.PatientEnrollmentId;

                        PatientEntityEnrollment        entityEnrollment = patientEnrollmentManager.GetPatientEntityEnrollment(enrollmentId);
                        List <PatientEntityEnrollment> listEnrollment   = new List <PatientEntityEnrollment>();
                        listEnrollment.Add(entityEnrollment);
                        var enrollmentAuditData = AuditDataUtility.AuditDataUtility.Serializer(listEnrollment);

                        entityEnrollment.EnrollmentDate = enrollmentDate;
                        entityEnrollment.AuditData      = enrollmentAuditData;

                        patientEnrollmentManager.updatePatientEnrollment(entityEnrollment);

                        var entityIdentifierAuditData = AuditDataUtility.AuditDataUtility.Serializer(identifiersByPatientId);
                        entityIdentifier.IdentifierValue = cccNumber;
                        entityIdentifier.AuditData       = entityIdentifierAuditData;
                        patientIdentifierManager.UpdatePatientIdentifier(entityIdentifier, facilityId, false);

                        if (deathDate.HasValue)
                        {
                            PatientMasterVisitManager masterVisitManager = new PatientMasterVisitManager();
                            PatientCareEndingManager  careEndingManager  = new PatientCareEndingManager();
                            LookupLogic lookupLogic          = new LookupLogic();
                            int         itemId               = lookupLogic.GetItemIdByGroupAndItemName("CareEnded", "Death")[0].ItemId;
                            int         patientMasterVisitId = masterVisitManager.GetLastPatientVisit(patientId).Id;
                            careEndingManager.AddPatientCareEndingDeath(patientId, patientMasterVisitId, enrollmentId, itemId, deathDate.Value, deathDate.Value, "", null, null);

                            PatientEntityEnrollment entityEnrollmentCareEnded = patientEnrollmentManager.GetPatientEntityEnrollment(enrollmentId);
                            entityEnrollmentCareEnded.CareEnded = true;
                            patientEnrollmentManager.updatePatientEnrollment(entityEnrollmentCareEnded);
                        }
                    }
                }
                else
                {
                    var assigningFacility   = cccNumber.Substring(0, 5);
                    int patientEnrollmentId = patientEnrollmentManager.addPatientEnrollment(patientId, enrollmentDate.ToString(), userId);
                    int patientEntryPointId = patientEntryPointManager.addPatientEntryPoint(patientId, entryPointId, userId);
                    int patientIdentifierId = patientIdentifierManager.addPatientIdentifier(patientId, patientEnrollmentId, 1, cccNumber, facilityId, assigningFacility, false);

                    if (deathDate.HasValue)
                    {
                        PatientMasterVisitManager masterVisitManager = new PatientMasterVisitManager();
                        PatientCareEndingManager  careEndingManager  = new PatientCareEndingManager();
                        LookupLogic lookupLogic          = new LookupLogic();
                        int         itemId               = lookupLogic.GetItemIdByGroupAndItemName("CareEnded", "Death")[0].ItemId;
                        int         patientMasterVisitId = masterVisitManager.GetLastPatientVisit(patientId).Id;
                        careEndingManager.AddPatientCareEndingDeath(patientId, patientMasterVisitId, patientEnrollmentId, itemId, deathDate.Value, deathDate.Value, "", null, null);

                        PatientEntityEnrollment entityEnrollmentCareEnded = patientEnrollmentManager.GetPatientEntityEnrollment(patientEnrollmentId);
                        entityEnrollmentCareEnded.CareEnded = true;
                        patientEnrollmentManager.updatePatientEnrollment(entityEnrollmentCareEnded);
                    }
                }

                return("Successfully updated patient");
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public async Task <Result <AddEnrollPatientResponse> > Handle(EnrollPatientCommand request, CancellationToken cancellationToken)
        {
            try
            {
                String               sDate     = DateTime.Now.ToString();
                DateTime             datevalue = Convert.ToDateTime(sDate);
                var                  patientMasterVisitManager = new PatientMasterVisitManager();
                var                  patientEnrollmentManager  = new PatientEnrollmentManager();
                var                  personLookUp               = new PersonLookUpManager();
                var                  patientEntryPointManager   = new PatientEntryPointManager();
                var                  patientLookUpManager       = new PatientLookupManager();
                var                  patientManager             = new PatientManager();
                var                  patientIdentifierManager   = new PatientIdentifierManager();
                var                  personContactLookUpManager = new PersonContactLookupManager();
                var                  lookupLogic        = new LookupLogic();
                var                  personContacts     = new List <PersonContactLookUp>();
                var                  identifiersObjects = request.identifiersList;
                List <PatientLookup> isPersonEnrolled   = await Task.Run(() => patientLookUpManager.GetPatientByPersonId(request.PersonId));

                string dobPrecision = String.IsNullOrEmpty(request.DobPrecision) ? "false" : "true";
                foreach (var item in identifiersObjects)
                {
                    var identifiers = await Task.Run(() => patientIdentifierManager.CheckIfIdentifierNumberIsUsed(item.Value, Convert.ToInt32(item.Key)));

                    if (identifiers.Count > 0)
                    {
                        foreach (var items in identifiers)
                        {
                            if (isPersonEnrolled.Count > 0)
                            {
                                if (items.PatientId == isPersonEnrolled[0].Id)
                                {
                                }
                                else
                                {
                                    var exception = new Exception("No: " + item.Value + " already exists");
                                    msg = exception.Message.ToString();
                                    throw exception;
                                }
                            }
                            else
                            {
                                var exception = new Exception("No: " + item.Value + " already exists");
                                msg = exception.Message.ToString();
                                throw exception;
                            }
                        }
                    }
                }

                if (isPersonEnrolled.Count == 0)
                {
                    List <PatientRegistrationLookup> patientsByPersonId = await Task.Run(() => patientManager.GetPatientIdByPersonId(request.PersonId));

                    var           patientIndex = datevalue.Year.ToString() + '-' + request.PersonId;
                    PatientEntity patient      = new PatientEntity();
                    if (patientsByPersonId.Count > 0)
                    {
                        patient.FacilityId  = request.facilityId;
                        patient.DateOfBirth = DateTime.Parse(request.DateofBirth);
                        patient.NationalId  = request.nationalId;
                        patient.ptn_pk      = patientsByPersonId[0].ptn_pk > 0 ? patientsByPersonId[0].ptn_pk : 0;

                        patientManager.UpdatePatient(patient, patientsByPersonId[0].Id);
                        patientId = patientsByPersonId[0].Id;
                    }
                    else
                    {
                        patient.PersonId     = request.PersonId;
                        patient.ptn_pk       = 0;
                        patient.FacilityId   = request.facilityId;
                        patient.PatientType  = request.PatientType;
                        patient.PatientIndex = patientIndex;
                        patient.DateOfBirth  = DateTime.Parse(request.DateofBirth);
                        patient.NationalId   = (request.nationalId);
                        patient.Active       = true;
                        patient.CreatedBy    = request.UserId;
                        patient.CreateDate   = DateTime.Now;
                        patient.DeleteFlag   = false;
                        patient.DobPrecision = bool.Parse(dobPrecision);

                        patientId = patientManager.AddPatient(patient);
                    }
                    if (patientId > 0)
                    {
                        var visitTypes = await Task.Run(() => lookupLogic.GetItemIdByGroupAndItemName("VisitType", "Enrollment"));

                        var visitType = 0;
                        if (visitTypes.Count > 0)
                        {
                            visitType = visitTypes[0].ItemId;
                        }

                        //Add enrollment visit
                        patientMasterVisitId =
                            patientMasterVisitManager.AddPatientMasterVisit(patientId, request.UserId, visitType);
                        //Enroll Patient to service
                        patientEnrollmentId = patientEnrollmentManager.addPatientEnrollment(patientId, request.EnrollmentDate, request.UserId);
                        //Add enrollment entry point
                        patientEntryPointId = patientEntryPointManager.addPatientEntryPoint(patientId, request.EntryPointId, request.UserId);



                        if (patientMasterVisitId > 0)
                        {
                            foreach (var item in identifiersObjects)
                            {
                                patientIdentifierId = await Task.Run(() => patientIdentifierManager.addPatientIdentifier(patientId,
                                                                                                                         patientEnrollmentId, Convert.ToInt32(item.Key), item.Value, request.facilityId));

                                //Get User Details to be used in BLUE CARD
                            }

                            msg = "Succefully enrolled patient.";
                        }
                    }

                    {
                        var patientLookManager           = new PatientLookupManager();
                        List <PatientLookup> patientlook = await Task.Run(() => patientLookManager.GetPatientByPersonId(request.PersonId));

                        if (patientlook.Count > 0)
                        {
                            int ptn_pk = patientlook[0].Id;

                            List <PatientEntity> listPatient = new List <PatientEntity>();
                            var entity = await Task.Run(() => patientlook.ConvertAll(x => new PatientEntity {
                                Id = x.Id, Active = x.Active, DateOfBirth = x.DateOfBirth, ptn_pk = x.ptn_pk, PatientType = x.PatientType, PatientIndex = x.PatientIndex, NationalId = x.NationalId, FacilityId = x.FacilityId
                            }));

                            var patientAuditData = await Task.Run(() => AuditDataUtility.Serializer(entity));

                            PatientEntity updatePatient = new PatientEntity();
                            updatePatient.ptn_pk      = patientlook[0].ptn_pk;
                            updatePatient.DateOfBirth = patientlook[0].DateOfBirth;
                            updatePatient.NationalId  = request.nationalId;
                            updatePatient.FacilityId  = patientlook[0].FacilityId;


                            //listPatient.Add(entity);
                            updatePatient.AuditData = patientAuditData;
                            //var enrollmentAuditData = AuditDataUtility.Serializer(patient);

                            await Task.Run(() => patientManager.UpdatePatient(updatePatient, patientlook[0].Id));

                            int patientMasterVisitId = await Task.Run(() => patientMasterVisitManager.PatientMasterVisitCheckin(patientlook[0].Id, request.UserId));

                            int PatientMasterVisitId = patientMasterVisitId;

                            List <PatientEntryPoint> entryPoints = await Task.Run(() => patientEntryPointManager.GetPatientEntryPoints(patientlook[0].Id));

                            if (entryPoints.Count > 0)
                            {
                                var entryPointAuditData = await Task.Run(() => AuditDataUtility.Serializer(entryPoints));

                                entryPoints[0].EntryPointId = request.EntryPointId;
                                entryPoints[0].AuditData    = entryPointAuditData;

                                await Task.Run(() => patientEntryPointManager.UpdatePatientEntryPoint(entryPoints[0]));
                            }
                            foreach (var item in identifiersObjects)
                            {
                                var identifiersByPatientId = await Task.Run(() => patientIdentifierManager
                                                                            .GetPatientEntityIdentifiersByPatientId(patientlook[0].Id, Convert.ToInt32(item.Key)));

                                if (identifiersByPatientId.Count > 0)
                                {
                                    foreach (var entityIdentifier in identifiersByPatientId)
                                    {
                                        int enrollmentId = entityIdentifier.PatientEnrollmentId;

                                        PatientEntityEnrollment entityEnrollment =
                                            await Task.Run(() => patientEnrollmentManager.GetPatientEntityEnrollment(enrollmentId));

                                        List <PatientEntityEnrollment> listEnrollment = new List <PatientEntityEnrollment>();
                                        await Task.Run(() => listEnrollment.Add(entityEnrollment));

                                        var enrollmentAuditData = await Task.Run(() => AuditDataUtility.Serializer(listEnrollment));

                                        entityEnrollment.EnrollmentDate = DateTime.Parse(request.EnrollmentDate);
                                        entityEnrollment.AuditData      = enrollmentAuditData;

                                        patientEnrollmentManager.updatePatientEnrollment(entityEnrollment);

                                        var entityIdentifierAuditData = AuditDataUtility.Serializer(identifiersByPatientId);
                                        entityIdentifier.IdentifierValue = item.Value;
                                        entityIdentifier.AuditData       = entityIdentifierAuditData;
                                        patientIdentifierManager.UpdatePatientIdentifier(entityIdentifier, request.facilityId);
                                    }
                                }
                                else
                                {
                                    patientEnrollmentId = await Task.Run(() => patientEnrollmentManager.addPatientEnrollment(patientlook[0].Id, request.EnrollmentDate, request.UserId));

                                    patientEntryPointId = await Task.Run(() => patientEntryPointManager.addPatientEntryPoint(patientlook[0].Id, request.EntryPointId, request.UserId));

                                    patientIdentifierId = await Task.Run(() => patientIdentifierManager.addPatientIdentifier(patientlook[0].Id,
                                                                                                                             patientEnrollmentId, Convert.ToInt32(item.Key), item.Value, request.facilityId));
                                }
                            }
                        }
                    }
                }


                return(Result <AddEnrollPatientResponse> .Valid(new AddEnrollPatientResponse()
                {
                    IdentifierValue = Convert.ToString(patientEnrollmentId),
                    IdentifierId = patientIdentifierId,
                    PatientId = patientId,
                    Message = msg
                }

                                                                ));
            }
            catch (Exception ex)
            {
                return(Result <AddEnrollPatientResponse> .Invalid(ex.Message));
            }
        }
Ejemplo n.º 5
0
        public string GetPatientEnrollmentDetails()
        {
            try
            {
                EnrollmentDetails enrollmentDetails = new EnrollmentDetails();
                enrollmentDetails.IndentifiersList = new List <Identifier>();
                PersonId = int.Parse(Session["PersonId"].ToString());
                PatientLookupManager     patientLookupManager = new PatientLookupManager();
                PatientEntryPointManager entryPointManager    = new PatientEntryPointManager();
                PatientIdentifierManager identifierManager    = new PatientIdentifierManager();
                IdentifierManager        ideManager           = new IdentifierManager();
                PersonLookUpManager      personLookUp         = new PersonLookUpManager();

                PatientLookup patientList = patientLookupManager.GetPatientByPersonId(PersonId);

                if (patientList != null)
                {
                    enrollmentDetails.DOB          = String.Format("{0:dd-MMM-yyyy}", patientList.DateOfBirth);
                    enrollmentDetails.DobPrecision = patientList.DobPrecision;
                    if (enrollmentDetails.DOB == null)
                    {
                        PersonLookUp person = personLookUp.GetPersonById(PersonId);
                        if (person.DateOfBirth != null)
                        {
                            enrollmentDetails.DOB          = String.Format("{0:dd-MMM-yyyy}", person.DateOfBirth);
                            enrollmentDetails.DobPrecision = person.DobPrecision == null?false:Convert.ToBoolean(person.DobPrecision);
                        }
                    }
                    enrollmentDetails.NationalId     = patientList.NationalId;
                    enrollmentDetails.EnrollmentDate = String.Format("{0:dd-MMM-yyyy}", patientList.EnrollmentDate);

                    var entryPoints   = entryPointManager.GetPatientEntryPoints(patientList.Id);
                    var identifiers   = identifierManager.GetAllPatientEntityIdentifiers(patientList.Id);
                    var dynamicFields = EnrollmentService.ServiceDynamicFields(1);
                    if (entryPoints.Count > 0)
                    {
                        string Name = LookupLogic.GetLookupNameById(entryPoints[0].EntryPointId);
                        if (Name == "Unknown")
                        {
                            enrollmentDetails.EntryPointIdUnknown = true;
                            enrollmentDetails.EntryPointId        = entryPoints[0].EntryPointId;
                        }
                        else
                        {
                            enrollmentDetails.EntryPointIdUnknown = false;
                            enrollmentDetails.EntryPointId        = entryPoints[0].EntryPointId;
                        }
                    }
                    var dynamicObject = new ExpandoObject() as IDictionary <string, Object>;
                    foreach (var field in dynamicFields)
                    {
                        foreach (var itemsEntityIdentifier in identifiers)
                        {
                            if (itemsEntityIdentifier.IdentifierTypeId == field.ID)
                            {
                                var code = field.Code;
                                dynamicObject.Add(code, itemsEntityIdentifier.IdentifierValue);
                            }
                        }
                    }
                    //if (identifiers.Count > 0)
                    //{
                    //    enrollmentDetails.IndentifierId = identifiers[0].IdentifierTypeId;
                    //}

                    foreach (var dynamicItem in dynamicObject)
                    {
                        var key           = dynamicItem.Key;
                        var identifier    = ideManager.GetIdentifierByCode(key);
                        var dynIdentifier = new Identifier();
                        if (identifier.PrefixType != null)
                        {
                            string[] enrollmentParts = dynamicItem.Value.ToString().Split('-');
                            int      parts           = enrollmentParts.Length;
                            if (parts > 1)
                            {
                                dynIdentifier.Code       = key;
                                dynIdentifier.PrefixType = enrollmentParts[0];
                                dynIdentifier.DataType   = enrollmentParts[1];
                                //enrollmentDetails.EnrollmentValue = enrollmentParts[1];
                                //enrollmentDetails.Prefix = enrollmentParts[0];
                                //enrollmentDetails.Suffix = null;
                            }
                            else
                            {
                                dynIdentifier.Code     = key;
                                dynIdentifier.DataType = dynamicItem.Value.ToString();
                                //enrollmentDetails.EnrollmentValue = dynamicItem.Value.ToString();
                            }
                        }
                        else
                        {
                            dynIdentifier.Code     = key;
                            dynIdentifier.DataType = dynamicItem.Value.ToString();
                        }
                        enrollmentDetails.IndentifiersList.Add(dynIdentifier);
                    }

                    //string[] enrollmentParts = patientList[0].EnrollmentNumber.Split('-');
                    //int parts = enrollmentParts.Length;
                    //if (parts > 1)
                    //{
                    //    enrollmentDetails.EnrollmentValue = enrollmentParts[1];
                    //    enrollmentDetails.Prefix = enrollmentParts[0];
                    //    enrollmentDetails.Suffix = null;
                    //}
                    //else
                    //{
                    //    enrollmentDetails.EnrollmentValue = patientList[0].EnrollmentNumber;
                    //}
                }
                else
                {
                    PersonLookUp person = personLookUp.GetPersonById(PersonId);
                    if (person.DateOfBirth != null)
                    {
                        enrollmentDetails.DOB          = String.Format("{0:dd-MMM-yyyy}", person.DateOfBirth);
                        enrollmentDetails.DobPrecision = person.DobPrecision == null ? false : Convert.ToBoolean(person.DobPrecision);
                    }
                }

                return(new JavaScriptSerializer().Serialize(enrollmentDetails));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
        public string AddPatient(int facilityId, int entryPointId, string enrollmentDate, string personDateOfBirth, string nationalId, int patientType, string dobPrecision, string identifiersList)
        {
            ExMessage message = new ExMessage();

            try
            {
                PersonId = int.Parse(Session["PersonId"].ToString());
                int userId = Convert.ToInt32(Session["AppUserId"]);

                var patientManager             = new PatientManager();
                var patientMasterVisitManager  = new PatientMasterVisitManager();
                var patientEnrollmentManager   = new PatientEnrollmentManager();
                var patientIdentifierManager   = new PatientIdentifierManager();
                var patientEntryPointManager   = new PatientEntryPointManager();
                var patientLookUpManager       = new PatientLookupManager();
                var mstPatientLogic            = new MstPatientLogic();
                var personContactLookUpManager = new PersonContactLookUpManager();
                var personContacts             = new List <PersonContactLookUp>();
                var personLookUp = new PersonLookUpManager();
                var lookupLogic  = new LookupLogic();

                //var identifiersObjects = JsonConvert.DeserializeObject<Dictionary<int, string>>(identifiersList);
                var           identifiersObjects = new JavaScriptSerializer().Deserialize <Dictionary <string, string> >(identifiersList);
                String        sDate            = DateTime.Now.ToString();
                DateTime      datevalue        = Convert.ToDateTime(sDate);
                PatientLookup isPersonEnrolled = patientLookUpManager.GetPatientByPersonId(PersonId);
                dobPrecision = String.IsNullOrWhiteSpace(dobPrecision) ? "false" : "true";

                foreach (var item in identifiersObjects)
                {
                    var identifiers = patientIdentifierManager.CheckIfIdentifierNumberIsUsed(item.Value, Convert.ToInt32(item.Key));
                    if (identifiers.Count > 0)
                    {
                        foreach (var items in identifiers)
                        {
                            if (isPersonEnrolled != null)
                            {
                                if (items.PatientId == isPersonEnrolled.Id)
                                {
                                }
                                else
                                {
                                    var exception = new SoapException("No: " + item.Value + " already exists", SoapException.ClientFaultCode);
                                    throw exception;
                                }
                            }
                            else
                            {
                                var exception = new SoapException("No: " + item.Value + " already exists", SoapException.ClientFaultCode);
                                throw exception;
                            }
                        }
                    }
                }

                if (isPersonEnrolled != null)
                {
                    List <PatientRegistrationLookup> patientsByPersonId = patientManager.GetPatientIdByPersonId(PersonId);
                    var           patientIndex = datevalue.Year.ToString() + '-' + PersonId;
                    PatientEntity patient      = new PatientEntity();
                    if (patientsByPersonId.Count > 0)
                    {
                        patient.FacilityId  = facilityId;
                        patient.DateOfBirth = DateTime.Parse(personDateOfBirth);
                        patient.NationalId  = nationalId;
                        patient.ptn_pk      = patientsByPersonId[0].ptn_pk > 0 ? patientsByPersonId[0].ptn_pk : 0;

                        patientManager.UpdatePatient(patient, patientsByPersonId[0].Id);
                        patientId = patientsByPersonId[0].Id;
                    }
                    else
                    {
                        patient.PersonId     = PersonId;
                        patient.ptn_pk       = 0;
                        patient.FacilityId   = facilityId;
                        patient.PatientType  = patientType;
                        patient.PatientIndex = patientIndex;
                        patient.DateOfBirth  = DateTime.Parse(personDateOfBirth);
                        patient.NationalId   = (nationalId);
                        patient.Active       = true;
                        patient.CreatedBy    = userId;
                        patient.CreateDate   = DateTime.Now;
                        patient.DeleteFlag   = false;
                        patient.DobPrecision = bool.Parse(dobPrecision);

                        patientId = patientManager.AddPatient(patient);
                    }
                    Session["PatientPK"] = patientId;

                    if (patientId > 0)
                    {
                        var visitTypes = lookupLogic.GetItemIdByGroupAndItemName("VisitType", "Enrollment");
                        var visitType  = 0;
                        if (visitTypes.Count > 0)
                        {
                            visitType = visitTypes[0].ItemId;
                        }

                        //Add enrollment visit
                        patientMasterVisitId =
                            patientMasterVisitManager.AddPatientMasterVisit(patientId, userId, visitType);
                        //Enroll Patient to service
                        patientEnrollmentId = patientEnrollmentManager.addPatientEnrollment(patientId, enrollmentDate, userId);
                        //Add enrollment entry point
                        patientEntryPointId = patientEntryPointManager.addPatientEntryPoint(patientId, entryPointId, userId);

                        //Get User Details to be used in BLUE CARD
                        var patient_person_details = personLookUp.GetPersonById(PersonId);
                        var greencardlookup        = new PersonGreenCardLookupManager();
                        var greencardptnpk         = greencardlookup.GetPtnPkByPersonId(PersonId);

                        if (patient_person_details != null)
                        {
                            var maritalStatus =
                                new PersonMaritalStatusManager().GetCurrentPatientMaritalStatus(PersonId);
                            personContacts = personContactLookUpManager.GetPersonContactByPersonId(PersonId);
                            var address  = "";
                            var phone    = "";
                            var facility = lookupLogic.GetFacility();

                            if (personContacts.Count > 0)
                            {
                                address = personContacts[0].PhysicalAddress;
                                phone   = personContacts[0].MobileNumber;
                            }

                            var MaritalStatusId = 0;
                            if (maritalStatus != null)
                            {
                                MaritalStatusId = maritalStatus.MaritalStatusId;
                            }

                            var sex = 0;
                            var enrollmentBlueCardId = "";

                            if (LookupLogic.GetLookupNameById(patient_person_details.Sex) == "Male")
                            {
                                sex = 16;
                            }
                            else if (LookupLogic.GetLookupNameById(patient_person_details.Sex) == "Female")
                            {
                                sex = 17;
                            }

                            foreach (var item in identifiersObjects)
                            {
                                if (Convert.ToInt32(item.Key) == 1)
                                {
                                    enrollmentBlueCardId = item.Value;
                                }
                            }


                            if (greencardptnpk.Count == 0)
                            {
                                ptn_Pk = mstPatientLogic.InsertMstPatient(
                                    (patient_person_details.FirstName),
                                    (patient_person_details.LastName),
                                    (patient_person_details.MiddleName),
                                    facility.FacilityID, enrollmentBlueCardId, entryPointId,
                                    DateTime.Parse(enrollmentDate), sex,
                                    DateTime.Parse(personDateOfBirth),
                                    1, MaritalStatusId,
                                    address, phone, userId, Session["AppPosID"].ToString(),
                                    203, DateTime.Parse(enrollmentDate), DateTime.Now);

                                patient.ptn_pk = ptn_Pk;
                                patientManager.UpdatePatient(patient, patientId);
                            }
                            else
                            {
                                ptn_Pk         = greencardptnpk[0].Ptn_Pk;
                                patient.ptn_pk = greencardptnpk[0].Ptn_Pk;
                                patientManager.UpdatePatient(patient, patientId);
                            }
                        }

                        Session["PatientMasterVisitId"] = patientMasterVisitId;

                        if (patientMasterVisitId > 0)
                        {
                            foreach (var item in identifiersObjects)
                            {
                                patientIdentifierId = patientIdentifierManager.addPatientIdentifier(patientId,
                                                                                                    patientEnrollmentId, Convert.ToInt32(item.Key), item.Value, facilityId);

                                var identifierManager = new IdentifierManager();
                                var identifierList    = identifierManager.GetIdentifiersById(Convert.ToInt32(item.Key));
                                var hivtesting        = _hivTestingManager.GetAll().OrderByDescending(y => y.Id).FirstOrDefault(n => n.PersonId == PersonId);
                                if (identifierList.Count > 0)
                                {
                                    if (identifierList[0].Code == "CCCNumber")
                                    {
                                        if (hivtesting != null)
                                        {
                                            hivtesting.ReferredToCare = true;
                                            _hivTestingManager.UpdatePatientHivTesting(hivtesting);

                                            PatientLinkage patLinkage = new PatientLinkage();
                                            patLinkage.LinkageDate = DateTime.Parse(enrollmentDate);
                                            patLinkage.CCCNumber   = item.Value;
                                            patLinkage.PersonId    = PersonId;
                                            patLinkage.CreatedBy   = userId;
                                            patLinkage.Enrolled    = true;
                                            patLinkage.PatientId   = patientId;

                                            linkageManager.AddPatientLinkage(patLinkage);
                                        }
                                    }
                                }
                            }

                            if (greencardptnpk.Count == 0)
                            {
                                mstPatientLogic.AddOrdVisit(ptn_Pk, facilityId, DateTime.Now, 110,
                                                            userId, DateTime.Now, 203);
                            }


                            message.errorcode = 0;
                            message.msg      += "<p>Successfully enrolled patient.</p>";
                        }
                    }
                }
                else
                {
                    var                  patientLookManager = new PatientLookupManager();
                    PatientLookup        patient            = patientLookManager.GetPatientByPersonId(PersonId);
                    List <PatientLookup> pk = new List <PatientLookup>();
                    pk.Add(patient);
                    if (patient != null)
                    {
                        Session["PatientPK"] = patient.Id;

                        List <PatientEntity> listPatient = new List <PatientEntity>();
                        var entity = pk.ConvertAll(x => new PatientEntity {
                            Id         = x.Id, Active = x.Active, DateOfBirth = x.DateOfBirth,
                            ptn_pk     = x.ptn_pk, PatientType = x.PatientType, PatientIndex = x.PatientIndex, NationalId = x.NationalId,
                            FacilityId = x.FacilityId
                        });

                        var patientAuditData = AuditDataUtility.Serializer(entity);

                        PatientEntity updatePatient = new PatientEntity();
                        updatePatient.ptn_pk      = patient.ptn_pk;
                        updatePatient.DateOfBirth = patient.DateOfBirth;
                        updatePatient.NationalId  = nationalId;
                        updatePatient.FacilityId  = patient.FacilityId;


                        //listPatient.Add(entity);
                        updatePatient.AuditData = patientAuditData;
                        //var enrollmentAuditData = AuditDataUtility.Serializer(patient);

                        patientManager.UpdatePatient(updatePatient, patient.Id);

                        int patientMasterVisitId = patientMasterVisitManager.PatientMasterVisitCheckin(patient.Id, userId);
                        Session["PatientMasterVisitId"] = patientMasterVisitId;

                        List <PatientEntryPoint> entryPoints = patientEntryPointManager.GetPatientEntryPoints(patient.Id);

                        if (entryPoints.Count > 0)
                        {
                            var entryPointAuditData = AuditDataUtility.Serializer(entryPoints);

                            entryPoints[0].EntryPointId = entryPointId;
                            entryPoints[0].AuditData    = entryPointAuditData;

                            patientEntryPointManager.UpdatePatientEntryPoint(entryPoints[0]);
                        }
                        foreach (var item in identifiersObjects)
                        {
                            var identifiersByPatientId = patientIdentifierManager
                                                         .GetPatientEntityIdentifiersByPatientId(patient.Id, Convert.ToInt32(item.Key));

                            if (identifiersByPatientId.Count > 0)
                            {
                                foreach (var entityIdentifier in identifiersByPatientId)
                                {
                                    int enrollmentId = entityIdentifier.PatientEnrollmentId;

                                    PatientEntityEnrollment entityEnrollment =
                                        patientEnrollmentManager.GetPatientEntityEnrollment(enrollmentId);
                                    List <PatientEntityEnrollment> listEnrollment = new List <PatientEntityEnrollment>();
                                    listEnrollment.Add(entityEnrollment);
                                    var enrollmentAuditData = AuditDataUtility.Serializer(listEnrollment);

                                    entityEnrollment.EnrollmentDate = DateTime.Parse(enrollmentDate);
                                    entityEnrollment.AuditData      = enrollmentAuditData;

                                    patientEnrollmentManager.updatePatientEnrollment(entityEnrollment);

                                    var entityIdentifierAuditData = AuditDataUtility.Serializer(identifiersByPatientId);
                                    entityIdentifier.IdentifierValue = item.Value;
                                    entityIdentifier.AuditData       = entityIdentifierAuditData;
                                    patientIdentifierManager.UpdatePatientIdentifier(entityIdentifier, facilityId);
                                }
                            }
                            else
                            {
                                patientEnrollmentId = patientEnrollmentManager.addPatientEnrollment(patient.Id, enrollmentDate, userId);
                                patientEntryPointId = patientEntryPointManager.addPatientEntryPoint(patient.Id, entryPointId, userId);
                                patientIdentifierId = patientIdentifierManager.addPatientIdentifier(patient.Id,
                                                                                                    patientEnrollmentId, Convert.ToInt32(item.Key), item.Value, facilityId);
                            }
                        }
                    }
                }
            }
            catch (SoapException ex)
            {
                message.errorcode = 1;
                message.msg       = ex.Message;
            }

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