public static void ExamDataSave(int examID, int patientID, NotesModel notes) { PropertyInfo[] notesFields = notes.GetType().GetProperties(); Field field; PropertyInfo pi; Dictionary<string, string> dicJson; ExamData data = new ExamData(); using(var db = new PosEntities()) { var dataConfigurationQuery = from dbConfig in db.ExamDataConfigurations select dbConfig; foreach(var config in dataConfigurationQuery) { dicJson = new Dictionary<string, string>(); if (config.FieldDataType == (int)PosConstants.FieldDataType.Json) { string[] examFields = config.Field.Replace(" ", "") .Split(','); foreach(string examField in examFields) { pi = notesFields.First(f => f.Name == examField); field = (Field) pi.GetValue(notes); dicJson.Add(field.Name, field.Value); } data = new ExamData() { PatientID = patientID, ExamID = examID, ExamDataConfigurationID = config.ExamDataConfigurationID, FieldName = config.Name, FieldValue = JsonConvert.SerializeObject(dicJson), FieldDataType = (int)PosConstants.FieldDataType.Json }; } db.ExamDatas.Add(data); } //finally saving db.SaveChanges(); } }
public static string GetXml(NotesModel notes, bool acceptDefaults, Dictionary<string, string> dict) { dict = (dict == null) ? new Dictionary<string, string>() : dict; StringWriter stringWriter = new StringWriter(); XmlWriterSettings settings = new XmlWriterSettings(); settings.CheckCharacters = false; XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings); xmlWriter.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\""); xmlWriter.WriteStartElement("patient"); //getting the properties from the model PropertyInfo[] notesFields = notes.GetType().GetProperties(); Field field; foreach (var pi in notesFields) { if (pi.PropertyType == typeof(Field)) { field = (Field)pi.GetValue(notes); if (field == null) { field = new Field() { Name = pi.Name, Value = String.Empty, ColourType = (int)PosConstants.ColourType.Normal }; } if (field.Value == null) field.Value = String.Empty; if (dict.ContainsKey(field.Name) && dict[field.Name] != field.Value.Trim()) { field.ColourType = (int)PosConstants.ColourType.Correct; } else if (acceptDefaults) { field.ColourType = (int)PosConstants.ColourType.Normal; } xmlWriter.WriteStartElement(field.Name); xmlWriter.WriteAttributeString("CustomColourType", field.ColourType.ToString()); xmlWriter.WriteCData(field.Value.Trim()); xmlWriter.WriteEndElement(); } } xmlWriter.WriteEndElement(); xmlWriter.Flush(); xmlWriter.Close(); stringWriter.Flush(); string xml = stringWriter.ToString(); stringWriter.Dispose(); return xml; }
private void GetNotesFromXml(NotesModel notes, string examText) { PropertyInfo[] notesFields = notes.GetType().GetProperties(); //looping through the xml and setting the Notes StringReader stringReader = new StringReader(examText); XmlReaderSettings settings = new XmlReaderSettings(); settings.CheckCharacters = false; XmlReader reader = XmlReader.Create(stringReader, settings); string fieldName = ""; string fieldValue = ""; string fieldAttr = ""; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: fieldName = reader.Name; fieldAttr = reader.GetAttribute("CustomColourType"); fieldAttr = fieldAttr == "" ? "0" : fieldAttr; break; case XmlNodeType.Text: fieldValue = reader.Value; break; case XmlNodeType.CDATA: fieldValue = reader.Value; break; case XmlNodeType.EndElement: if (fieldName != "") { //SetControlValue(fieldName, fieldValue, fieldAttr); PropertyInfo pi = notesFields.FirstOrDefault(p => p.Name == fieldName); SetPropertyValue(notes, pi, fieldValue, Convert.ToInt32(fieldAttr)); fieldName = ""; fieldValue = ""; fieldAttr = ""; } break; } } reader.Close(); stringReader.Close(); stringReader.Dispose(); }
private NotesViewModel GetBlankNotes(string userName) { NotesViewModel notesVM = new NotesViewModel(); NotesModel notes = new NotesModel() { NotesType = PosConstants.NotesType.New }; notesVM.Notes = notes; notesVM.Doctors = PosRepository.DoctorsGet(); notesVM.AutoComplete = PosRepository.AutoCorrectGet(userName); List<SelectListItem> examLookUp = PosRepository.ExamLookUpGet(); PropertyInfo[] notesFields = notes.GetType().GetProperties(); foreach (var pi in notesFields) { SetProperty(notes, pi, pi.Name, "", (int)PosConstants.ColourType.Normal, examLookUp); } return notesVM; }