public bool Save(bool bSaveNotification) { bool ret = false; using (DbManagerProxy manager = DbManagerFactory.Factory.Create(EidssUserContext.Instance)) { var acc = HumanCase.Accessor.Instance(null); HumanCase hc = null; if (string.IsNullOrEmpty(OfflineCaseID)) { hc = (Id != 0) ? acc.SelectByKey(manager, Id) : acc.CreateNewT(manager, null); } else { var find = find_by_offline_id(manager); if (find != 0) { hc = acc.SelectByKey(manager, find); } else { hc = acc.CreateNewT(manager, null); if (Id != 0) { MarkedToDelete = true; return(true); } } } if (hc == null) { throw new SoapException(string.Format("Case with id='{0}' is not found", Id != 0 ? Id.ToString() : OfflineCaseID), new XmlQualifiedName("id")); } hc.strCaseID = CaseID ?? ""; try { hc.uidOfflineCaseID = new Guid(OfflineCaseID); } catch {} hc.strLocalIdentifier = LocalID; //hc.strLocalIdentifier = LocalIdentifier; hc.datCompletionPaperFormDate = CompletionPaperFormDate; hc.datFacilityLastVisit = FacilityLastVisitDate; hc.datOnSetDate = OnsetDate; if (bSaveNotification) { hc.datNotificationDate = NotificationDate; } hc.TentativeDiagnosis = TentativeDiagnosis == null ? null : hc.TentativeDiagnosisLookup.SingleOrDefault(c => c.idfsDiagnosis == TentativeDiagnosis.Id); hc.datTentativeDiagnosisDate = TentativeDiagnosisDate; hc.FinalDiagnosis = FinalDiagnosis == null ? null : hc.FinalDiagnosisLookup.SingleOrDefault(c => c.idfsDiagnosis == FinalDiagnosis.Id); hc.datFinalDiagnosisDate = FinalDiagnosisDate; hc.intPatientAge = PatientAge.HasValue && PatientAge.Value > 0 ? PatientAge : null; hc.Patient.intPatientAgeFromCase = hc.intPatientAge; hc.Patient.strFirstName = FirstName; hc.Patient.strSecondName = MiddleName; hc.Patient.strLastName = LastName; hc.Patient.HumanAgeType = PatientAgeType == null ? null : hc.Patient.HumanAgeTypeLookup.SingleOrDefault(c => c.idfsBaseReference == PatientAgeType.Id); hc.Patient.Gender = PatientGender == null ? null : hc.Patient.GenderLookup.SingleOrDefault(c => c.idfsBaseReference == PatientGender.Id); hc.CaseProgressStatus = CaseStatus == null ? null : hc.CaseProgressStatusLookup.SingleOrDefault(c => c.idfsBaseReference == CaseStatus.Id); hc.RelatedToOutbreak = RelatedToOutbreak == null ? null : hc.RelatedToOutbreakLookup.SingleOrDefault(c => c.idfsBaseReference == RelatedToOutbreak.Id); hc.PatientLocationType = CurrentLocation == null ? null : hc.PatientLocationTypeLookup.SingleOrDefault(c => c.idfsBaseReference == CurrentLocation.Id); hc.Hospitalization = Hospitalization == null ? null : hc.HospitalizationLookup.SingleOrDefault(c => c.idfsBaseReference == Hospitalization.Id); hc.InitialCaseClassification = CaseClassification == null ? null : hc.InitialCaseClassificationLookup.SingleOrDefault(c => c.idfsReference == CaseClassification.Id); hc.FinalCaseClassification = FinalCaseStatus == null ? null : hc.FinalCaseClassificationLookup.SingleOrDefault(c => c.idfsReference == FinalCaseStatus.Id); hc.PatientState = PatientState == null ? null : hc.PatientStateLookup.SingleOrDefault(c => c.idfsBaseReference == PatientState.Id); hc.Patient.datDateofBirth = DateOfBirth; hc.Patient.Nationality = Citizenship == null ? null : hc.Patient.NationalityLookup.SingleOrDefault(c => c.idfsBaseReference == Citizenship.Id); hc.strNote = AdditionalComment; hc.Outcome = Outcome == null ? null : hc.OutcomeLookup.SingleOrDefault(c => c.idfsBaseReference == Outcome.Id); hc.Patient.CurrentResidenceAddress.Country = CurrentResidence == null || CurrentResidence.Country == null ? null : hc.Patient.CurrentResidenceAddress.CountryLookup.SingleOrDefault(c => c.idfsCountry == CurrentResidence.Country.Id); hc.Patient.CurrentResidenceAddress.Region = CurrentResidence == null || CurrentResidence.Region == null ? null : hc.Patient.CurrentResidenceAddress.RegionLookup.SingleOrDefault(c => c.idfsRegion == CurrentResidence.Region.Id); hc.Patient.CurrentResidenceAddress.Rayon = CurrentResidence == null || CurrentResidence.Rayon == null ? null : hc.Patient.CurrentResidenceAddress.RayonLookup.SingleOrDefault(c => c.idfsRayon == CurrentResidence.Rayon.Id); hc.Patient.CurrentResidenceAddress.Settlement = CurrentResidence == null || CurrentResidence.Settlement == null ? null : hc.Patient.CurrentResidenceAddress.SettlementLookup.SingleOrDefault(c => c.idfsSettlement == CurrentResidence.Settlement.Id); hc.Patient.CurrentResidenceAddress.strStreetName = CurrentResidence == null ? null : CurrentResidence.Street; hc.Patient.CurrentResidenceAddress.strPostCode = CurrentResidence == null ? null : CurrentResidence.ZipCode; hc.Patient.EmployerAddress.Country = EmployerAddress == null || EmployerAddress.Country == null ? null : hc.Patient.EmployerAddress.CountryLookup.SingleOrDefault(c => c.idfsCountry == EmployerAddress.Country.Id); hc.Patient.EmployerAddress.Region = EmployerAddress == null || EmployerAddress.Region == null ? null : hc.Patient.EmployerAddress.RegionLookup.SingleOrDefault(c => c.idfsRegion == EmployerAddress.Region.Id); hc.Patient.EmployerAddress.Rayon = EmployerAddress == null || EmployerAddress.Rayon == null ? null : hc.Patient.EmployerAddress.RayonLookup.SingleOrDefault(c => c.idfsRayon == EmployerAddress.Rayon.Id); hc.Patient.EmployerAddress.Settlement = EmployerAddress == null || EmployerAddress.Settlement == null ? null : hc.Patient.EmployerAddress.SettlementLookup.SingleOrDefault(c => c.idfsSettlement == EmployerAddress.Settlement.Id); hc.Patient.EmployerAddress.strStreetName = EmployerAddress == null ? null : EmployerAddress.Street; hc.Patient.EmployerAddress.strPostCode = EmployerAddress == null ? null : EmployerAddress.ZipCode; hc.Patient.strEmployerName = EmployerName; hc.strCurrentLocation = CurrentLocationName; if (bSaveNotification) { hc.idfSentByOffice = NotificationSentBy.Id; //hc.SentByOffice = NotificationSentBy == null ? null : // hc.SentByOfficeLookup.SingleOrDefault(c => c.idfInstitution == NotificationSentBy.Id); hc.idfSentByPerson = NotificationSentByPerson.Id; //hc.SentByPerson = NotificationSentByPerson == null ? null : // hc.SentByPersonLookup.SingleOrDefault(c => c.idfPerson == NotificationSentByPerson.Id); hc.strSentByFirstName = NotificationSentByFirstName; hc.strSentByPatronymicName = NotificationSentByPatronymicName; hc.strSentByLastName = NotificationSentByLastName; hc.idfReceivedByOffice = NotificationReceivedBy.Id; //hc.ReceivedByOffice = NotificationReceivedBy == null ? null : // hc.ReceivedByOfficeLookup.SingleOrDefault(c => c.idfInstitution == NotificationReceivedBy.Id); hc.strReceivedByFirstName = NotificationReceivedByFirstName; hc.strReceivedByPatronymicName = NotificationReceivedByPatronymicName; hc.strReceivedByLastName = NotificationReceivedByLastName; } hc.Patient.strHomePhone = PhoneNumber; hc.Validation += (sender, args) => { LastErrorDescription = GetErrorMessage(args); throw new SoapException(EidssMessages.GetValidationErrorMessage(args, "en"), new XmlQualifiedName(args.FieldName)); }; ret = acc.Post(manager, hc); if (!ret) { LastErrorDescription = "Unknown error is occured during posting case"; throw new SoapException("Unknown error is occured during posting case", new XmlQualifiedName("post")); } Id = hc.idfCase; CaseID = hc.strCaseID; } return(ret); }