void oPControl_Store(object sender, NewOperationStoreEventArgs e) { if (!Directory.Exists(textBoxExportPath.Text)) { MessageBox.Show("The Export directory does not exist!"); e.StoredOk = false; return; } long pId; try { pId = Int64.Parse(textBoxPatientId.Text); } catch (FormatException) { MessageBox.Show("PatientId is not valid!"); e.StoredOk = false; return; } OperationData op = e.Operation; op.PatientId = Int64.Parse(textBoxPatientId.Text); JsonContainer jsonContainer = new JsonContainer(); jsonContainer.addOperation(op); string jsonString = SpdJsonTools.GenerateJson(jsonContainer); try { TextFileHelper.WriteFile( textBoxExportPath.Text + Path.DirectorySeparatorChar + "SPD.Operation." + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second + ".json", jsonString); } catch (Exception ex) { MessageBox.Show("Storing not possible:\n" + ex.Message); e.StoredOk = false; return; } PatientData pd = null; try { pd = this.patComp.FindPatientById(op.PatientId); } catch (Exception) {} if (pd == null) { pd = new PatientData(); pd.Id = op.PatientId; pd.Address = string.Empty; pd.FirstName = string.Empty; pd.Phone = string.Empty; pd.SurName = string.Empty; } this.oPControl.CurrentPatient = pd; e.TakeFromDB = false; this.oPControl.Clear(); this.textBoxPatientId.Clear(); SPD.GUI.OPWriter.Properties.Settings.Default.exportPath = textBoxExportPath.Text; SPD.GUI.OPWriter.Properties.Settings.Default.Save(); }
/// <summary> /// Parses the json. /// </summary> /// <param name="jsonString">The json string.</param> /// <returns>the JsonContainer od null if an Error occured!!</returns> public static JsonContainer ParseJson(string jsonString) { try { JsonContainer jsonContainer = new JsonContainer(); Hashtable elements = (Hashtable)JSON.JsonDecode(jsonString); if (elements.ContainsKey(patients)) { jsonContainer.Patients = parsePatients((ArrayList)elements[patients]); jsonContainer.FurtherTreatments = parseFurtherTreatments((ArrayList)elements[patients]); } if (elements.ContainsKey(operations)) { jsonContainer.Operations = parseOperations((ArrayList)elements[operations]); } if (elements.ContainsKey(visits)) { jsonContainer.Visits = parseVisits((ArrayList)elements[visits]); } if (elements.ContainsKey(diagnoseGroups)) { jsonContainer.DiagnoseGroups = parseDiagnoseGroups((ArrayList)elements[diagnoseGroups]); } if (elements.ContainsKey(nextActions)) { jsonContainer.NextActions = parseNextActions((ArrayList)elements[nextActions]); } if (elements.ContainsKey(patientDiagnoseGroups)) { jsonContainer.PatientDiagnoseGroups = parsePatientDiagnoseGroups((ArrayList)elements[patientDiagnoseGroups]); } if (elements.ContainsKey(photos)) { jsonContainer.Photos = parsePhotos((ArrayList)elements[photos]); } return jsonContainer; } catch (Exception) { return null; } }
/// <summary> /// Merges the json containers. /// </summary> /// <param name="jsonContainers">The json containers.</param> /// <returns></returns> public static JsonContainer MergeJsonContainers(IList<JsonContainer> jsonContainers) { JsonContainer mergedJsonContainer = new JsonContainer(); foreach (JsonContainer jsonContainer in jsonContainers) { mergedJsonContainer.addOperations(jsonContainer.Operations); mergedJsonContainer.addImages(jsonContainer.Images); mergedJsonContainer.addNextActions(jsonContainer.NextActions); mergedJsonContainer.addPatients(jsonContainer.Patients); mergedJsonContainer.addVisits(jsonContainer.Visits); } return mergedJsonContainer; }
/// <summary> /// Generates the json. /// </summary> /// <param name="jsonContainer">The json container.</param> /// <returns></returns> public static string GenerateJson(JsonContainer jsonContainer) { Hashtable elements = new Hashtable(); if (jsonContainer.Patients.Count != 0) { elements.Add(patients, generatePatientsJson(jsonContainer.Patients, jsonContainer.FurtherTreatments)); } if (jsonContainer.Operations.Count != 0) { elements.Add(operations, generateOpJson(jsonContainer.Operations)); } if (jsonContainer.Visits.Count != 0) { elements.Add(visits, generateVisitsJson(jsonContainer.Visits)); } if (jsonContainer.DiagnoseGroups.Count != 0) { elements.Add(diagnoseGroups, generateDiagnoseGroupsJson(jsonContainer.DiagnoseGroups)); } if (jsonContainer.NextActions.Count != 0) { elements.Add(nextActions, generateNextActionsJson(jsonContainer.NextActions)); } if (jsonContainer.Photos.Count != 0) { elements.Add(photos, generatePhotosJson(jsonContainer.Photos)); } if (jsonContainer.PatientDiagnoseGroups.Count != 0) { elements.Add(patientDiagnoseGroups, generatePatientDiagnoseGroupsJson(jsonContainer.PatientDiagnoseGroups)); } return JSON.JsonEncode(elements); }
private void buttonbuttonOpenFileOpenDialog_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = true; ofd.Filter = "SPD JSON Files (*.json)|*.json|All files (*.*)|*.*"; DialogResult dr = ofd.ShowDialog(); if (dr != DialogResult.OK) { return; } if (ofd.SafeFileNames == null || ofd.SafeFileNames.Length < 1) { return; } IDictionary<string, string> fileContents = new Dictionary<string, string>(); foreach (string filename in ofd.FileNames) { if (File.Exists(filename)) { try { fileContents.Add(filename, TextFileHelper.ReadFile(filename)); } catch (Exception ex) { MessageBox.Show("Cannot read File: " + filename + "\nBecause" + ex.Message); } } } IList<JsonContainer> jsonContainers = new List<JsonContainer>(); foreach (string filename in fileContents.Keys) { JsonContainer json = SpdJsonTools.ParseJson(fileContents[filename]); if (json == null) { MessageBox.Show("ERROR in File: " + filename + "\nThis file cannot be parsed!"); } else { jsonContainers.Add(json); } } mergedJsonContainer = SpdJsonTools.MergeJsonContainers(jsonContainers); foreach (OperationData op in mergedJsonContainer.Operations) { PatientData pd = this.patComp.FindPatientById(op.PatientId); if (pd == null) { checkedListBoxImportOperations.Items.Add("Operation: ERROR!!! Patient with ID:" + op.PatientId + " not found!", false); } else { checkedListBoxImportOperations.Items.Add("Operation: PatientId:" + op.PatientId + " Name:" + pd.FirstName + " " + pd.SurName + " Diagnoses:" + op.Diagnoses + " Performed: " + op.Performed, true); } } //TODO: patient, next Action, Visits, images, Group,... }