public static List <ServiceAreaIdentifierMapping> ServiceAreaIdentifiers(int serviceId) { List <ServiceAreaIdentifierMapping> serviceAreaIdentifierMappingList = new List <ServiceAreaIdentifierMapping>(); try { var serviceareIdentifiersManager = new ServiceAreaIdentifiersManager(); var identifierManager = new IdentifierManager(); var identifiers = serviceareIdentifiersManager.GetIdentifiersByServiceArea(serviceId); if (identifiers.Count > 0) { for (int i = 0; i < identifiers.Count; i++) { var resultIdentifiers = identifierManager.GetIdentifiersById(identifiers[i].IdentifierId); if (resultIdentifiers.Count > 0) { for (int j = 0; j < resultIdentifiers.Count; j++) { var details = new ServiceAreaIdentifierMapping(); details.ID = resultIdentifiers[j].Id; details.DataType = resultIdentifiers[j].DataType; details.Label = resultIdentifiers[j].DisplayName; details.Prefix = resultIdentifiers[j].PrefixType; details.Required = identifiers[i].RequiredFlag; details.Code = resultIdentifiers[j].Code; details.IdentifierName = resultIdentifiers[j].Name; details.IdentifierValueSeparator = resultIdentifiers[j].IdentifierValueSeparator; details.ValidatorRegex = resultIdentifiers[j].ValidatorRegex; details.FailedValidationMessage = resultIdentifiers[j].FailedValidationMessage; details.MinLength = resultIdentifiers[j].MinLength; details.MaxLength = resultIdentifiers[j].MaxLength; serviceAreaIdentifierMappingList.Add(details); } } } } return(serviceAreaIdentifierMappingList); } catch (Exception e) { Console.WriteLine(e); throw; } }
public static List <FormDetails> ServiceDynamicFields(int serviceId) { List <FormDetails> formDetails = new List <FormDetails>(); try { var serviceareIdentifiersManager = new ServiceAreaIdentifiersManager(); var identifierManager = new IdentifierManager(); var identifiers = serviceareIdentifiersManager.GetIdentifiersByServiceArea(serviceId); if (identifiers.Count > 0) { for (int i = 0; i < identifiers.Count; i++) { var resultIdentifiers = identifierManager.GetIdentifiersById(identifiers[i].IdentifierId); if (resultIdentifiers.Count > 0) { for (int j = 0; j < resultIdentifiers.Count; j++) { var details = new FormDetails(); details.ID = resultIdentifiers[j].Id; details.DataType = resultIdentifiers[j].DataType; details.Label = resultIdentifiers[j].DisplayName; details.Prefix = resultIdentifiers[j].PrefixType; details.Required = identifiers[i].RequiredFlag; details.Code = resultIdentifiers[j].Code; details.IdentifierName = resultIdentifiers[j].Name; formDetails.Add(details); } } } } return(formDetails); } catch (Exception e) { Console.WriteLine(e); throw; } }
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)); }