public string Save(PatientRegistrationDTO registration) { try { LookupLogic lookupLogic = new LookupLogic(); PatientLookupManager patientLookup = new PatientLookupManager(); PatientLookup patient = new PatientLookup(); PatientRegistrationValidation registrationValidation = new PatientRegistrationValidation(); //Validate DTO string results = registrationValidation.ValidateDTO(registration); if (!String.IsNullOrWhiteSpace(results)) { throw new Exception(results); } int interopUserId = InteropUser.UserId; //Get FacilityId int facilityId = Convert.ToInt32(registration.MESSAGE_HEADER.SENDING_FACILITY); //Get Gender string gender = registration.PATIENT_IDENTIFICATION.SEX == "F" ? "Female" : "Male"; //IQCare Sex int sex = lookupLogic.GetItemIdByGroupAndItemName("Gender", gender)[0].ItemId; //Assume this is a new patient int patientType = lookupLogic.GetItemIdByGroupAndItemName("PatientType", registration.PATIENT_VISIT.PATIENT_TYPE)[0].ItemId; //Get Enrollment Id Type int visitType = lookupLogic.GetItemIdByGroupAndItemName("VisitType", "Enrollment")[0].ItemId; //Get DOB DateTime DOB = DateTime.ParseExact(registration.PATIENT_IDENTIFICATION.DATE_OF_BIRTH, "yyyyMMdd", null); bool DOB_Precision = true; switch (registration.PATIENT_IDENTIFICATION.DATE_OF_BIRTH_PRECISION) { case "ESTIMATED": DOB_Precision = false; break; case "EXACT": DOB_Precision = true; break; default: DOB_Precision = true; break; } //Get Enrollment Date DateTime dateOfEnrollment = DateTime.ParseExact(registration.PATIENT_VISIT.HIV_CARE_ENROLLMENT_DATE, "yyyyMMdd", null); //Get Patient Names string firstName = registration.PATIENT_IDENTIFICATION.PATIENT_NAME.FIRST_NAME; string middleName = registration.PATIENT_IDENTIFICATION.PATIENT_NAME.MIDDLE_NAME; string lastName = registration.PATIENT_IDENTIFICATION.PATIENT_NAME.LAST_NAME; //Get gods number string godsNumber = registration.PATIENT_IDENTIFICATION.EXTERNAL_PATIENT_ID.ID; //get marital status string maritalStatusString = String.Empty; int maritalStatusId = 0; switch (registration.PATIENT_IDENTIFICATION.MARITAL_STATUS) { case "S": maritalStatusString = "Single"; break; case "W": maritalStatusString = "Widowed"; break; case "D": maritalStatusString = "Divorced"; break; case "MP": maritalStatusString = "Married Polygamous"; break; case "C": maritalStatusString = "Cohabiting"; break; case "MM": maritalStatusString = "Married Monogamous"; break; default: maritalStatusString = "Unknown"; break; } maritalStatusId = lookupLogic.GetItemIdByGroupAndItemName("MaritalStatus", maritalStatusString)[0].ItemId; //Get patient Address string village = String.Empty; string ward = String.Empty; string sub_county = String.Empty; string county = String.Empty; string nearestLandMark = String.Empty; string postalAdress = String.Empty; string phoneNumber = String.Empty; string deathDate = String.Empty; var patient_address = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS; if (patient_address != null) { var physicalAddress = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS; if (physicalAddress != null) { village = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS.VILLAGE; ward = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS.WARD; sub_county = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS.SUB_COUNTY; county = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS.COUNTY; nearestLandMark = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS.NEAREST_LANDMARK; } postalAdress = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.POSTAL_ADDRESS; } //Lookup Ward, sub_county_county int wardId = 0; int subCountyId = 0; int countyId = 0; var countyDetails = lookupLogic.GetCountyDetailsByWardName(ward); if (countyDetails != null) { wardId = countyDetails.WardId; subCountyId = countyDetails.SubcountyId; countyId = countyDetails.CountyId; } //Get Phone Number phoneNumber = registration.PATIENT_IDENTIFICATION.PHONE_NUMBER; deathDate = registration.PATIENT_IDENTIFICATION.DEATH_DATE; DateTime?DateOfDeath = null; if (!string.IsNullOrWhiteSpace(deathDate)) { DateOfDeath = DateTime.ParseExact(deathDate, "yyyyMMdd", null); } //GET NEXT OF KIN var nextOfKin = registration.NEXT_OF_KIN; //Get CCCNumber and NationalId string nationalId = String.Empty; string cccNumber = String.Empty; int entryPointId = 0; var lookupEntryPoints = lookupLogic.GetItemIdByGroupAndItemName("Entrypoint", registration.PATIENT_VISIT.PATIENT_SOURCE); if (lookupEntryPoints.Count > 0) { entryPointId = lookupEntryPoints[0].ItemId; } else { entryPointId = lookupLogic.GetItemIdByGroupAndDisplayName("Entrypoint", "Other")[0].ItemId; } foreach (var internalpatientid in registration.PATIENT_IDENTIFICATION.INTERNAL_PATIENT_ID) { if (internalpatientid.IDENTIFIER_TYPE == "NATIONAL_ID" && internalpatientid.ASSIGNING_AUTHORITY == "GOK") { nationalId = internalpatientid.ID; } if (internalpatientid.IDENTIFIER_TYPE == "CCC_NUMBER" && internalpatientid.ASSIGNING_AUTHORITY == "CCC") { cccNumber = internalpatientid.ID; } } if (!String.IsNullOrWhiteSpace(cccNumber)) { patient = patientLookup.GetPatientByCccNumber(cccNumber); if (patient == null) { msg = ProcessPatient.Add(firstName, middleName, lastName, sex, interopUserId, DOB, DOB_Precision, facilityId, patientType, nationalId, visitType, dateOfEnrollment, cccNumber, entryPointId, godsNumber, maritalStatusId, village, wardId, subCountyId, countyId, nearestLandMark, postalAdress, phoneNumber, DateOfDeath, nextOfKin); } else { msg = ProcessPatient.Update(firstName, middleName, lastName, sex, patient.PersonId, patient.Id, patient.ptn_pk, DOB, DOB_Precision, nationalId, facilityId, entryPointId, dateOfEnrollment, cccNumber, patient, godsNumber, maritalStatusId, village, wardId, subCountyId, countyId, nearestLandMark, postalAdress, phoneNumber, DateOfDeath, nextOfKin, interopUserId); } } } catch (Exception ex) { throw new Exception(ex.Message); } return(msg); }
public string addOneTimeEventsTracker(string Stage1DateValue, string Stage2DateValue, string Stage3DateValue, string SexPartnerDateValue, string INHStartDateValue, string INHCompletion, string CompletionDate, string adultVaccine, string vaccines) { try { var jss = new JavaScriptSerializer(); IList <ListVaccination> data = jss.Deserialize <IList <ListVaccination> >(vaccines); var dataAdult = jss.Deserialize <IList <Object> >(adultVaccine); PatientDisclosureManager disclosure = new PatientDisclosureManager(); INHProphylaxisManager inhProphylaxis = new INHProphylaxisManager(); PatientVaccinationManager patientVaccination = new PatientVaccinationManager(); int patientId = int.Parse(HttpContext.Current.Session["PatientPK"].ToString()); //int patientId = int.Parse(Session["PatientId"].ToString()); int patientMasterVisitId = int.Parse(Session["PatientMasterVisitId"].ToString()); if (String.IsNullOrEmpty(INHCompletion) || String.IsNullOrWhiteSpace(INHCompletion) || INHCompletion == "null") { INHCompletion = "false"; } if (String.IsNullOrEmpty(CompletionDate)) { IsCompletionDate = null; } else { IsCompletionDate = DateTime.Parse(CompletionDate); } if (String.IsNullOrEmpty(INHStartDateValue)) { IsINHStartDateValue = null; } else { IsINHStartDateValue = DateTime.Parse(INHStartDateValue); } if (!String.IsNullOrWhiteSpace(Stage1DateValue)) { List <PatientDisclosure> patientDisclosures = disclosure.GetPatientDisclosure(patientId, "Adolescents", "Stage1"); if (patientDisclosures.Count > 0) { patientDisclosures[0].DisclosureDate = DateTime.Parse(Stage1DateValue); disclosure.UpdatePatientDisclosure(patientDisclosures[0]); } else { disclosure.AddPatientDisclosure(patientId, patientMasterVisitId, "Adolescents", "Stage1", DateTime.Parse(Stage1DateValue)); } } if (!String.IsNullOrWhiteSpace(Stage2DateValue)) { List <PatientDisclosure> patientDisclosures = disclosure.GetPatientDisclosure(patientId, "Adolescents", "Stage2"); if (patientDisclosures.Count > 0) { patientDisclosures[0].DisclosureDate = DateTime.Parse(Stage2DateValue); disclosure.UpdatePatientDisclosure(patientDisclosures[0]); } else { disclosure.AddPatientDisclosure(patientId, patientMasterVisitId, "Adolescents", "Stage2", DateTime.Parse(Stage2DateValue)); } } if (!String.IsNullOrWhiteSpace(Stage3DateValue)) { List <PatientDisclosure> patientDisclosures = disclosure.GetPatientDisclosure(patientId, "Adolescents", "Stage3"); if (patientDisclosures.Count > 0) { patientDisclosures[0].DisclosureDate = DateTime.Parse(Stage3DateValue); disclosure.UpdatePatientDisclosure(patientDisclosures[0]); } else { disclosure.AddPatientDisclosure(patientId, patientMasterVisitId, "Adolescents", "Stage3", DateTime.Parse(Stage3DateValue)); } } if (!String.IsNullOrWhiteSpace(SexPartnerDateValue)) { List <PatientDisclosure> patientDisclosures = disclosure.GetPatientDisclosure(patientId, "Adolescents", "SexPartner"); if (patientDisclosures.Count > 0) { patientDisclosures[0].DisclosureDate = DateTime.Parse(SexPartnerDateValue); disclosure.UpdatePatientDisclosure(patientDisclosures[0]); } else { disclosure.AddPatientDisclosure(patientId, patientMasterVisitId, "Adolescents", "SexPartner", DateTime.Parse(SexPartnerDateValue)); } } List <INHProphylaxis> inhListsProphylaxes = inhProphylaxis.GetPatientProphylaxes(patientId); if (inhListsProphylaxes.Count > 0) { inhListsProphylaxes[0].StartDate = IsINHStartDateValue; inhListsProphylaxes[0].CompletionDate = IsCompletionDate; inhListsProphylaxes[0].Complete = Boolean.Parse(INHCompletion); inhProphylaxis.updateINHProphylaxis(inhListsProphylaxes[0]); } else { INHProphylaxis prophylaxis = new INHProphylaxis() { PatientId = patientId, PatientMasterVisitId = patientMasterVisitId, StartDate = IsINHStartDateValue, Complete = Boolean.Parse(INHCompletion), CompletionDate = IsCompletionDate }; inhProphylaxis.addINHProphylaxis(prophylaxis); } var lookup = new LookupLogic(); for (var i = 0; i < data.Count; i++) { PatientVaccination patientVaccine = new PatientVaccination() { PatientId = patientId, PatientMasterVisitId = patientMasterVisitId, Vaccine = lookup.GetItemIdByGroupAndDisplayName(data[i].vaccineType, data[i].vaccineStage)[0].ItemId,// LookupLogic.GetLookUpMasterId(data[i].vaccineType), VaccineStage = data[i].vaccineStage }; var vaccineExistsChild = patientVaccination.VaccineExists(patientId, patientVaccine.Vaccine, data[i].vaccineStage); if (vaccineExistsChild.Count == 0) { patientVaccination.addPatientVaccination(patientVaccine); } } for (var i = 0; i < dataAdult.Count; i++) { int vaccine = 0; if (dataAdult[i].ToString() == "FluVaccine" || dataAdult[i].ToString() == "HBV") { vaccine = lookup.GetItemIdByGroupAndDisplayName(dataAdult[i].ToString(), dataAdult[i].ToString())[0] .ItemId; //LookupLogic.GetLookUpMasterId(dataAdult[i].ToString()); } if (dataAdult[i].ToString() != "") { PatientVaccination patientVaccine = new PatientVaccination() { PatientId = patientId, PatientMasterVisitId = patientMasterVisitId, Vaccine = vaccine, VaccineStage = dataAdult[i].ToString() }; var vaccineExists = patientVaccination.VaccineExists(patientId, vaccine, dataAdult[i].ToString()); if (vaccineExists.Count == 0) { patientVaccination.addPatientVaccination(patientVaccine); } } } Msg = "Successfully Added OnIime Event Tracker"; } catch (SoapException ex) { Msg = ex.Message + ' ' + ex.InnerException; } return(Msg); }
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)); }