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 static string Update(PatientAppointSchedulingDTO appointmentScheduling) { try { //todo: fetch assigning facility from the message string assigning_Facility = ""; PatientAppointmentManager manager = new PatientAppointmentManager(); PatientLookupManager patientLookup = new PatientLookupManager(); LookupLogic lookupLogic = new LookupLogic(); PatientMasterVisitManager masterVisitManager = new PatientMasterVisitManager(); var personIdentifierManager = new PersonIdentifierManager(); var interopPlacerValuesManager = new InteropPlacerValuesManager(); PatientLookup patient = new PatientLookup(); string cccNumber = String.Empty; string appointmentReason = String.Empty; string appointmentStatus = String.Empty; string appointmentType = String.Empty; int interopUserId = InteropUser.UserId; foreach (var item in appointmentScheduling.PATIENT_IDENTIFICATION.INTERNAL_PATIENT_ID) { if (item.IDENTIFIER_TYPE == "CCC_NUMBER" && item.ASSIGNING_AUTHORITY == "CCC") { cccNumber = item.ID; } } string godsNumber = appointmentScheduling.PATIENT_IDENTIFICATION.EXTERNAL_PATIENT_ID.ID; if (!String.IsNullOrWhiteSpace(cccNumber)) { patient = patientLookup.GetPatientByCccNumber(cccNumber); if (patient != null) { if (!string.IsNullOrWhiteSpace(godsNumber)) { IdentifierManager identifierManager = new IdentifierManager(); Identifier identifier = identifierManager.GetIdentifierByCode("GODS_NUMBER"); var personIdentifiers = personIdentifierManager.GetPersonIdentifiers(patient.PersonId, identifier.Id); if (personIdentifiers.Count == 0) { personIdentifierManager.AddPersonIdentifier(patient.PersonId, identifier.Id, godsNumber, interopUserId, assigning_Facility); } } int patientMasterVisitId = masterVisitManager.GetLastPatientVisit(patient.Id).Id; int serviceAreaId = lookupLogic.GetItemIdByGroupAndItemName("ServiceArea", "MoH 257 GREENCARD")[0].ItemId; foreach (var appointment in appointmentScheduling.APPOINTMENT_INFORMATION) { switch (appointment.APPOINTMENT_REASON) { case "PHARMACY_REFILL": appointmentReason = "Pharmacy Refill"; break; case "TREATMENT_PREP": appointmentReason = "Treatment Preparation"; break; case "LAB_TEST": appointmentReason = "Lab Tests"; break; case "FOLLOWUP": appointmentReason = "Follow Up"; break; default: appointmentReason = "Follow Up"; break; } switch (appointment.APPOINTMENT_STATUS) { case "HONORED": appointmentStatus = "Met"; break; case "MISSED": appointmentStatus = "Missed"; break; case "PENDING": appointmentStatus = "Pending"; break; case "CANCELLED": appointmentStatus = "CareEnded"; break; default: appointmentStatus = "Pending"; break; } switch (appointment.APPOINTMENT_TYPE) { case "CLINICAL": appointmentType = "Standard Care"; break; case "PHARMACY": appointmentType = "Express Care"; break; case "INVESTIGATION": appointmentType = "Express Care"; break; default: appointmentType = "Standard Care"; break; } var reasons = lookupLogic.GetItemIdByGroupAndItemName("AppointmentReason", appointmentReason); int reasonId = 0; if (reasons == null || reasons.Count > 0) { throw new Exception($"No matching reasons in the databases {appointmentReason}"); } reasonId = reasons[0].ItemId; int statusId = 0; var status = lookupLogic.GetItemIdByGroupAndItemName("AppointmentStatus", appointmentStatus); if (status == null || status.Count > 0) { throw new Exception($"No matching appointmentstatus in the databases {appointmentStatus}"); } statusId = status[0].ItemId; int differentiatedCareId = 0; var diffCare = lookupLogic.GetItemIdByGroupAndItemName("DifferentiatedCare", appointmentType); if (diffCare == null || diffCare.Count > 0) { throw new Exception($"No matching differentiated care option in the databases {appointmentType}"); } differentiatedCareId = diffCare[0].ItemId; InteropPlacerTypeManager interopPlacerTypeManager = new InteropPlacerTypeManager(); int interopPlacerTypeId = interopPlacerTypeManager.GetInteropPlacerTypeByName(appointment.PLACER_APPOINTMENT_NUMBER.ENTITY).Id; var interopPlacerValues = interopPlacerValuesManager.GetInteropPlacerValues(interopPlacerTypeId, 3, Convert.ToInt32(appointment.PLACER_APPOINTMENT_NUMBER.NUMBER)); if (interopPlacerValues != null) { PatientAppointment patientAppointment = manager.GetPatientAppointment(interopPlacerValues.EntityId); patientAppointment.AppointmentDate = DateTime.ParseExact(appointment.APPOINTMENT_DATE, "yyyyMMdd", null); patientAppointment.Description = appointment.APPOINTMENT_NOTE; patientAppointment.DifferentiatedCareId = differentiatedCareId; patientAppointment.ReasonId = reasonId; patientAppointment.ServiceAreaId = serviceAreaId; patientAppointment.StatusId = statusId; manager.UpdatePatientAppointments(patientAppointment); } else { PatientAppointment patientAppointment = new PatientAppointment() { PatientId = patient.Id, PatientMasterVisitId = patientMasterVisitId, AppointmentDate = DateTime.ParseExact(appointment.APPOINTMENT_DATE, "yyyyMMdd", null), Description = appointment.APPOINTMENT_NOTE, DifferentiatedCareId = differentiatedCareId, ReasonId = reasonId, ServiceAreaId = serviceAreaId, StatusId = statusId, CreatedBy = interopUserId, CreateDate = DateTime.Now }; int appointmentId = manager.AddPatientAppointments(patientAppointment); InteropPlacerValues placerValues = new InteropPlacerValues() { IdentifierType = 3, EntityId = appointmentId, InteropPlacerTypeId = interopPlacerTypeId, PlacerValue = Convert.ToInt32(appointment.PLACER_APPOINTMENT_NUMBER.NUMBER) }; interopPlacerValuesManager.AddInteropPlacerValue(placerValues); } } } } } catch (Exception e) { throw new Exception(e.Message); } return(String.Empty); }