public int AddPatientFamilyTestings(PatientFamilyTesting p, int userId) { PersonManager pm = new PersonManager(); int personId = pm.AddPersonUiLogic(p.FirstName, p.MiddleName, p.LastName, p.Sex, userId, p.DateOfBirth, p.DobPrecision); PersonRelationship relationship = new PersonRelationship() { PersonId = personId, PatientId = p.PatientId, BaselineResult = p.BaseLineHivStatusId, BaselineDate = p.BaselineHivStatusDate, RelationshipTypeId = p.RelationshipId, CreatedBy = userId }; _personRelationshipManager.AddPersonRelationship(relationship); DateTime?testingDate = p.HivTestingResultsDate; if (testingDate == DateTime.MinValue) { testingDate = null; } PatientHivTesting familyTesting = new PatientHivTesting() { PersonId = personId, PatientMasterVisitId = p.PatientMasterVisitId, TestingResult = p.HivTestingResultsId, TestingDate = testingDate, ReferredToCare = p.CccReferal, CreatedBy = userId }; int hivTestingId = _hivTestingManager.AddPatientHivTesting(familyTesting); if (p.CccReferal == true) { PatientLinkage patientLinkage = new PatientLinkage() { PersonId = personId, LinkageDate = (DateTime)p.LinkageDate, CCCNumber = p.CccReferaalNumber, CreatedBy = userId }; linkageManager.AddPatientLinkage(patientLinkage); } return(hivTestingId); }
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); } }
public async Task <Result <PersonRegistrationResponse> > Handle(PersonRegistrationCommand request, CancellationToken cancellationToken) { try { Client c = new Client(); c.FirstName = request.Person.FirstName; c.LastName = request.Person.LastName; c.MiddleName = request.Person.MiddleName; c.LastName = request.Person.LastName; c.MaritalStatus = request.Person.MaritalStatus; c.Sex = request.Person.Sex; c.PersonId = request.Person.PersonId; c.CreatedBy = request.Person.CreatedBy; c.DateOfBirth = request.Person.DateOfBirth; c.DobPrecision = request.Person.DobPrecision; int PerId; if (!String.IsNullOrEmpty(c.PersonId.ToString())) { PerId = Convert.ToInt32(c.PersonId.ToString()); if (PerId > 0) { var personManager = new PersonManager(); //UpdatePerson(string firstname, string middlename, string lastname, int gender, int userId, int id, DateTime dateOfBirth, bool dobPrecision) await Task.Run(() => personManager.UpdatePerson(c.FirstName, c.MiddleName, c.LastName, c.Sex, c.CreatedBy, Convert.ToInt32(c.PersonId.ToString()), c.DateOfBirth, c.DobPrecision)); PId = Convert.ToInt32(c.PersonId.ToString()); msg = string.Format("Person with the PersonId: {0} updated successfully", PId); } var maritalstatus = new PersonMaritalStatusManager(); var _marStatus = maritalstatus.GetInitialPatientMaritalStatus(PerId); if (_marStatus != null && c.MaritalStatus > 0) { _marStatus.MaritalStatusId = c.MaritalStatus; _marStatus.CreatedBy = c.CreatedBy; res = await Task.Run(() => maritalstatus.UpdatePatientMaritalStatus(_marStatus)); if (res > 0) { msg += "<p>Person Marital Status Updated Successfully!</p>"; } } else if (_marStatus != null && c.MaritalStatus == 0) { _marStatus.DeleteFlag = true; res = await Task.Run(() => maritalstatus.UpdatePatientMaritalStatus(_marStatus)); if (res > 0) { msg += "<p>Person Marital Status Updated Successfully!</p>"; } } else { if (c.MaritalStatus > 0) { res = await Task.Run(() => maritalstatus.AddPatientMaritalStatus(Convert.ToInt32(c.PersonId.ToString()), c.MaritalStatus, c.CreatedBy)); { if (res > 0) { msg += "PersonMarital Status Added Successfully!"; } } } } } else { var personLogic = new PersonManager(); PId = personLogic.AddPersonUiLogic(c.FirstName, c.MiddleName, c.LastName, c.Sex, Convert.ToInt32(c.CreatedBy), c.DateOfBirth, Convert.ToBoolean(c.DobPrecision)); if (PId > 0) { msg = "New Person Added successfully:PersonId=>" + PId + "</p>"; var MaritalStatus = new PersonMaritalStatusManager(); if (c.MaritalStatus > 0) { res = MaritalStatus.AddPatientMaritalStatus(PId, c.MaritalStatus, c.CreatedBy); if (res > 0) { msg += "Person Marital Status Added Successfully!"; } } else { } } } } catch (Exception e) { msg = e.Message; } return(Result <PersonRegistrationResponse> .Valid(new PersonRegistrationResponse() { PersonId = PId, Message = msg })); }