public override Tuple <Schema.Patient, string> GetFromPersonIdentityService(Schema.Patient p) { var strPinVerificationSuffix = PinVerificationSuffix; try { if (p.strPersonID.Length != 11 || p.strPersonID.Any(c => !Char.IsDigit(c))) { return(new Tuple <Schema.Patient, string>(null, string.Format("strPinWrongFormat{0}", strPinVerificationSuffix))); } if (!p.datDateofBirth.HasValue) { return(new Tuple <Schema.Patient, string>(null, "strPinDOB")); } var ret = _getFromPersonIdentityServiceInternal(p); return(ret); } catch (Exception ex) { string e = ex.Message; } return(new Tuple <Schema.Patient, string>(null, string.Format("strPinNotResponding{0}", strPinVerificationSuffix))); }
public override Tuple <Schema.Patient, string> GetFromPersonIdentityService(Schema.Patient p) { for (int i = 0; i < 3; i++) { try { var ret = _getFromPersonIdentityServiceInternal(p); if (ret == null) { return(new Tuple <Schema.Patient, string>(null, "strSearchCriteriaIsWrong")); } return(new Tuple <Schema.Patient, string>(ret, null)); } catch (Exception) { } } return(new Tuple <Schema.Patient, string>(null, "strPersonServiceIsUnavailable")); }
/*public class PersonsComparer : IEqualityComparer<Person> * { * public bool Equals(Person x, Person y) * { * return x.Pin.CompareTo(y.Pin) == 0; * } * * public int GetHashCode(Person obj) * { * return obj.Pin.GetHashCode(); * } * }*/ private Schema.Patient _getFromPersonIdentityServiceInternal(Schema.Patient p) { IdentityServiceClient client = null; //IIdentityService client = null; try { /*var b = new WSHttpBinding(SecurityMode.TransportWithMessageCredential); * b.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; * b.Security.Message.ClientCredentialType = MessageCredentialType.UserName; * * var factory = new ChannelFactory<IIdentityService>(b); * factory.Credentials.UserName.UserName = "******"; * factory.Credentials.UserName.Password = "******"; * //factory.Credentials.Peer.PeerAuthentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerTrust; * //factory.Credentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.TrustedPeople, X509FindType.FindBySubjectName, "localhost"); * * client = factory.CreateChannel(new EndpointAddress(new Uri("https://eservice.e-health.gov.az/EHealthWcf/IdentityService.svc"))); * ServicePointManager.ServerCertificateValidationCallback = * ((sender, certificate, chain, sslPolicyErrors) => * { * return true; * }); */ //client = new IdentityServiceClient("BasicHttpBinding_IIdentityService", "https://eservice.e-health.gov.az/EHealthWcf/IdentityService.svc"); client = new IdentityServiceClient(); var encryptedUser = Config.GetSetting("AzPinServiceUsr"); //"essiduser"; var enryptedPassword = Config.GetSetting("AzPinServicePwd");; //"ess1dUs3R"; var usr = Cryptor.Decrypt(encryptedUser); var pwd = Cryptor.Decrypt(enryptedPassword, usr); client.ClientCredentials.UserName.UserName = usr; client.ClientCredentials.UserName.Password = pwd; Person prs = null; if (p.idfsSearchMethod == 1) { var prsList = client.GetPersonByParams(p.strFirstName, p.strLastName, p.strSecondName, p.datDateofBirth /*.HasValue ? p.datDateofBirth.Value.ToString("yyyy-MM-ddT00:00:00") : null*/); if (prsList != null && prsList.Select(i => i.Pin).Distinct().Count() == 1) { prs = prsList[0]; if (prs != null) { try { prs = client.GetPersonByPin(prs.Pin); } catch (Exception) { } } } } else if (p.idfsSearchMethod == 2) { IdentityServiceDocumentType docType = IdentityServiceDocumentType.Passport; switch (p.idfsDocumentType) { case 1: docType = IdentityServiceDocumentType.Passport; break; case 2: docType = IdentityServiceDocumentType.IDCardForAdult; break; case 3: docType = IdentityServiceDocumentType.IDcardForChild; break; case 4: docType = IdentityServiceDocumentType.TemporaryResidencePermit; break; case 5: docType = IdentityServiceDocumentType.PermanentResidencePermit; break; case 6: docType = IdentityServiceDocumentType.BirthCertificate; break; } prs = client.GetPersonByDocumentNumber(p.strDocumentNumber, docType, docType == IdentityServiceDocumentType.BirthCertificate ? p.datDocumentDate : null); if (prs != null) { try { prs = client.GetPersonByPin(prs.Pin); } catch (Exception) { } } } else if (p.idfsSearchMethod == 3) { prs = client.GetPersonByPin(p.strPersonID); } else if (p.idfsSearchMethod == 4) { prs = new Person() { Pin = "0YR9DE3", Name = "İSMAYILOV", SurName = "RAMİL", FatherName = "TOFİQ OĞLU", DateOfBirth = new DateTime(1986, 1, 19), Sex = "M" }; } if (prs != null) { using (DbManagerProxy manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance)) { FilterParams filters = new FilterParams(); filters.Add("strPersonID", "=", prs.Pin); var items = Schema.PatientListItem.Accessor.Instance(null).SelectListT(manager, filters); if (items != null && items.Count == 1) { var proot = Schema.Patient.Accessor.Instance(null).SelectByKey(manager, items[0].idfHumanActual); p = proot; } } p.PersonIDType = p.PersonIDTypeLookup.FirstOrDefault(i => i.idfsBaseReference != 0 && i.idfsBaseReference != (long)PersonalIDType.Unknown); p.strPersonID = prs.Pin; p.strFirstName = prs.Name; p.strLastName = prs.SurName; p.strSecondName = prs.FatherName; p.datDateofBirth = prs.DateOfBirth; p.Gender = p.GenderLookup.FirstOrDefault(c => c.idfsBaseReference == (prs.Sex == "M" ? (long)GenderType.Male : (prs.Sex == "F" ? (long)GenderType.Female : 0))); return(p); } } catch (FaultException fex) { switch (fex.Code.Name) { case "2.1": case "2.2": case "2.3": return(null); case "0": case "1": default: LogError.Log("ErrorLog_PinService_", fex, stream => { stream.WriteLine(String.Format("SearchMethod = {0}, DocumentType = {1}, PersonID = '{2}', FirstName = '{3}', LastName = '{4}', SecondName = '{5}', DateofBirth = '{6}'", p.idfsSearchMethod, p.idfsDocumentType, p.strPersonID, p.strFirstName, p.strLastName, p.strSecondName, p.datDateofBirth.HasValue ? p.datDateofBirth.Value.ToString("yyyy-MM-ddT00:00:00") : "")); stream.WriteLine(String.Format("Code = {0}, Subcode = {1}, Reason = {2}", fex.Code.Name, fex.Code.SubCode == null ? "" : fex.Code.SubCode.Name, fex.Reason.ToString())); }); if (fex.InnerException != null) { LogError.Log("ErrorLog_PinService_", fex.InnerException); } throw; } } catch (Exception ex) { LogError.Log("ErrorLog_PinService_", ex, stream => { stream.WriteLine(String.Format("SearchMethod = {0}, DocumentType = {1}, PersonID = '{2}', FirstName = '{3}', LastName = '{4}', SecondName = '{5}', DateofBirth = '{6}'", p.idfsSearchMethod, p.idfsDocumentType, p.strPersonID, p.strFirstName, p.strLastName, p.strSecondName, p.datDateofBirth.HasValue ? p.datDateofBirth.Value.ToString("yyyy-MM-ddT00:00:00") : "")); }); if (ex.InnerException != null) { LogError.Log("ErrorLog_PinService_", ex.InnerException); } throw; } finally { if (client != null && client.State != System.ServiceModel.CommunicationState.Closed) { client.Close(); } } return(null); }
private Tuple <Schema.Patient, string> _getFromPersonIdentityServiceInternal(Schema.Patient p) { var strPinVerificationSuffix = PinVerificationSuffix; string pin = p.strPersonID; string form = p.Parent is Schema.HumanCase ? "H02" : "H04"; string caseID = p.Parent is Schema.HumanCase ? (p.Parent as Schema.HumanCase).strCaseID : (p.Parent is Schema.ContactedCasePerson ? ((p.Parent as Schema.ContactedCasePerson).Parent as Schema.HumanCase).strCaseID : ""); DateTime?dtResponse = null; string resultCode = ""; Georgia.CommonDataWebSoapClient client = new Georgia.CommonDataWebSoapClient(); try { string codedUsername = Config.GetSetting("GgPinServiceUsr"); string codedPassword = Config.GetSetting("GgPinServicePwd"); string username = Cryptor.Decrypt(codedUsername); string password = Cryptor.Decrypt(codedPassword, username); var token = client.Login(username, password); if (token == null) { throw new Exception("PIN Service unreachable"); } var person = client.GetPersonInfoEx(token.Value, Guid.Empty, p.strPersonID, p.datDateofBirth.Value.Year); if (person == null) { resultCode = "NO_RECORDS_FOUND"; return(new Tuple <Schema.Patient, string>(null, string.Format("strPinNoRecordsFound{0}", strPinVerificationSuffix))); } dtResponse = DateTime.Now; resultCode = "OK"; using (DbManagerProxy manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance)) { FilterParams filters = new FilterParams(); filters.Add("strPersonID", "=", p.strPersonID); var items = Schema.PatientListItem.Accessor.Instance(null).SelectListT(manager, filters); if (items != null && items.Count == 1) { var proot = Schema.Patient.Accessor.Instance(null).SelectByKey(manager, items[0].idfHumanActual); p = proot; } } p.PersonIDType = p.PersonIDTypeLookup.FirstOrDefault(i => i.idfsBaseReference == (long)PersonalIDType.PIN_GG); p.strPersonID = person.PrivateNumber; p.strFirstName = person.FirstName; p.strLastName = person.LastName; p.Gender = p.GenderLookup.FirstOrDefault(c => c.idfsBaseReference == (person.GenderID.Equals(PersonGendersEnum.Male) ? (long)GenderType.Male : (person.GenderID.Equals(PersonGendersEnum.Female) ? (long)GenderType.Female : 0))); p.bPINMode = true; DateTime xx; if ((person.BirthDate != null) && (DateTime.TryParseExact(person.BirthDate.ToString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out xx))) { p.datDateofBirth = xx; //person.BirthDate; } return(new Tuple <Schema.Patient, string>(p, null)); } catch (Exception ex) { LogError.Log("ErrorLog_PinService_", ex, stream => { stream.WriteLine(String.Format("PIN = {0}, Form = {1}, CaseID = {2}, UserID = {3}, UserName = {4}, UserOrganization = {5}, EIDSSDateTime = {6}, PINServiceDateTime = {7}, Result = {8}", pin, form, caseID, EidssUserContext.Instance.CurrentUser.LoginName, EidssUserContext.Instance.CurrentUser.FullName, EidssUserContext.Instance.CurrentUser.OrganizationEng, DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"), dtResponse.HasValue ? dtResponse.Value.ToString("yyyy-MM-ddTHH:mm:ss") : "", resultCode )); }); resultCode = "Exception:" + ex.Message; throw; } finally { if (client != null && client.State != System.ServiceModel.CommunicationState.Closed) { client.Close(); } LogError.Log("Log_PinService_", null, stream => { stream.WriteLine(String.Format("PIN = {0}, form = {1}, CaseID = {2}, UserID = {3}, UserName = {4}, UserOrganization = {5}, EIDSSDateTime = {6}, PINServiceDateTime = {7}, Result = {8}", pin, form, caseID, EidssUserContext.Instance.CurrentUser.LoginName, EidssUserContext.Instance.CurrentUser.FullName, EidssUserContext.Instance.CurrentUser.OrganizationEng, DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"), dtResponse.HasValue ? dtResponse.Value.ToString("yyyy-MM-ddTHH:mm:ss") : "", resultCode )); }, "{0}{3}.txt"); } }
public virtual Tuple <Schema.Patient, string> GetFromPersonIdentityService(Schema.Patient p) { throw new NotImplementedException(); }