private void SaveReportToDatabase() { // check the length of specimen var SpecField = FieldList.Where(f => f.FieldNumber == ".012").FirstOrDefault(); if (SpecField != null) { if (SpecField.IsFieldDirty()) { List<string> vals = SpecField.GetListContent(); foreach (string val in vals) { if (val.Length >= 75) { MessageBox.Show("Specimen must be less than 75 characters.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } } } } // check for illegal characters if (ContainsIllegalCharacters()) { MessageBox.Show("Please remove ^ from your data.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } // go through each field in the field list and update if they are modified foreach (ReportField field in FieldList) { if (field.IsFieldDirty()) { UpdateChangeList(field.FieldNumber, field.GetListContent()); } } // only call the rpc if there something to change if ((ChangeList == null) || (ChangeList.Fields == null) || (ChangeList.Fields.Count == 0)) { MessageBox.Show("There are no changes to be saved.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } else { // separate the save of path/resident/practitioner from the rest var PathField = ChangeList.Fields.Where(pf => pf.FieldNumber == ".02").FirstOrDefault(); var ResField = ChangeList.Fields.Where(pf => pf.FieldNumber == ".021").FirstOrDefault(); var PracField = ChangeList.Fields.Where(pf => pf.FieldNumber == ".07").FirstOrDefault(); PathologyCaseReportFieldsType headerChanges = new PathologyCaseReportFieldsType(); if (PathField != null) { headerChanges.Fields.Add(PathField); ChangeList.Fields.Remove(PathField); } if (ResField != null) { headerChanges.Fields.Add(ResField); ChangeList.Fields.Remove(ResField); } if (PracField != null) { headerChanges.Fields.Add(PracField); ChangeList.Fields.Remove(PracField); } try { // try to save the headers first if (headerChanges.Fields.Count > 0) { DataSource.SaveReportChanges(this.CaseURN, headerChanges); // save is successful so update the records before and current values foreach (ReportField field in FieldList) { if (((PathField != null) && (field.FieldNumber == PathField.FieldNumber)) || ((ResField != null) && (field.FieldNumber == ResField.FieldNumber)) || ((PracField != null) && (field.FieldNumber == PracField.FieldNumber))) { field.SaveValue(); } } } } catch (Exception ex1) { // readd the changes if not saved yet if (PathField != null) ChangeList.Fields.Add(PathField); if (ResField != null) ChangeList.Fields.Add(ResField); if (PracField != null) ChangeList.Fields.Add(PracField); Log.Error("Could not save changes to the users in the report header.", ex1); throw; } try { // try to save the body of the main report if (ChangeList.Fields.Count > 0) this.saveResult = DataSource.SaveReportChanges(this.CaseURN, this.ChangeList); // save is successful so update the records before and current values foreach (ReportField field in FieldList) { field.SaveValue(); } // clear the change list ChangeList.Fields.Clear(); } catch (Exception ex2) { Log.Error("Failed to save report data.", ex2); throw; } } }
public ReportViewModel(IWorkListDataSource dataSource, CaseListItem caseItem, bool isGlobalReadOnly = false, ReadingSiteType siteType = ReadingSiteType.interpretation) { DataSource = dataSource; // editor property this.IsEditorReadOnly = isGlobalReadOnly; this.CurrentSiteType = siteType; // case's properties this.CaseURN = caseItem.CaseURN; this.SiteAbbr = caseItem.SiteAbbr; this.SiteCode = caseItem.SiteCode; this.AccessionNumber = caseItem.AccessionNumber; ChangeList = new PathologyCaseReportFieldsType(); // patient's info this.PatientName = caseItem.PatientName; this.PatientID = caseItem.PatientID; this.Patient = DataSource.GetPatient(caseItem.SiteCode, caseItem.PatientICN); // retrieve the Esignature status at the case's primary site GetESignatureStatus(); // consultations this.ConsultationList = caseItem.ConsultationList; // CCOW set patient context IContextManager contextManager = ViewModelLocator.ContextManager; contextManager.SetCurrentPatient(this.Patient); this.CCOWContextState = contextManager.GetPatientContextState(this.Patient); // get notified of CCOW context state change events contextManager.PropertyChanged += new PropertyChangedEventHandler(contextManager_PropertyChanged); // retrieve report data report = dataSource.GetReport(caseItem); // retrieve supplementary reports DateTime srDisplayDateStart; if (!DateTime.TryParse(DateSpecReceived, out srDisplayDateStart)) { srDisplayDateStart = DateTime.Today; } SRViewModel = new SupplementaryReportViewModel(DataSource, SiteCode, AccessionNumber, this.CaseURN, this.ConsultationList, this.IsEditorReadOnly, this.CurrentSiteType); SRViewModel.SRDateStart = srDisplayDateStart; SRViewModel.Practitioner = Practitioner; SRViewModel.EsigStatus = this.EsigStatus; //srViewModel.LocalEsigStatus = this.LocalEsigStatus; // initialized codeing tab ReportCodingVM = new ReportCodingViewModel(this.DataSource, this.CaseURN, this.SiteCode, this.IsEditorReadOnly, this.CurrentSiteType); LaunchCPRSReportCommand = new RelayCommand(LaunchCPRSReport, () => this.State == ReportState.Verified); SaveReportCommand = new RelayCommand(SaveMainReportToDatabase, () => CanSaveMainReport); CompleteReportCommand = new RelayCommand(CompleteReport, () => CanCompleteMainReport); VerifyReportCommand = new RelayCommand(VerifyReport, () => CanVerifyMainReport); SearchUserCommand = new RelayCommand<string>((s) => SearchUser(s), (s) => CanSearchUser); if ((this.report == null) || (this.report.FieldList == null) || (this.report.FieldList.Count <= 0)) { Log.Error("Missing report template."); MessageBox.Show("Cannot retrieve data fields for the main report. Please contact system administrator.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } // check the condition and set the GUI as read only or not SetMainReportReadOnly(); }
public PathologySaveCaseReportResultType SaveReportChanges(string caseURN, PathologyCaseReportFieldsType changeList) { return vistaClient.SaveReportChanges(caseURN, changeList); }
/// <summary> /// Save changes to the main report to database /// </summary> /// <param name="caseURN">case id</param> /// <param name="changeList">list of changes</param> public PathologySaveCaseReportResultType SaveReportChanges(string caseURN, PathologyCaseReportFieldsType changeList) { Log.Debug("Saving report changes..."); if (string.IsNullOrWhiteSpace(caseURN)) { throw new MagVixFailureException("Missing parameter: caseURN."); } if ((changeList == null) || (changeList.Fields == null)) { throw new MagVixFailureException("Missing parameter: caseURN."); } string URI = String.Format("pathology/case/report/{0}", caseURN); PathologySaveCaseReportResultType result = null; IRestResponse response; try { string changes = ResponseParser.SerializeToXml<PathologyCaseReportFieldsType>(changeList); response = ExecutePost(URI, VixServiceTypes.Pathology, changes); ValidateRestResponse(response); result = ResponseParser.ParseSaveReportChanges(response.Content); return result; } catch (MagResponseParsingFailureException rpf) { throw new MagVixFailureException("Couldn't parse changes.", rpf); } catch (MagVixFailureException) { throw; } catch (Exception ex) { throw new MagVixFailureException("Could not complete request to save changes to the report.", ex); } }
/// <summary> /// Save changes to the main report to database /// </summary> /// <param name="caseURN">case id</param> /// <param name="changeList">list of changes</param> public PathologySaveCaseReportResultType SaveReportChanges(string caseURN, PathologyCaseReportFieldsType changeList) { if (vixClient != null) { return vixClient.SaveReportChanges(caseURN, changeList); } else { throw new MagVixFailureException("VIX client is null."); } }