/// <summary> /// Process the Properties on a Type of a Section property. /// </summary> private static void ProcessSectionProperties(DataEntrySection dataEntrySection, Type sectionType, string parentSubSectionName, string parentPath, string implementation) { foreach (var property in sectionType.GetProperties()) { // Inspect the Property var propertyType = property.PropertyType; var fieldAttr = GetFieldAttribute(property); var propertyTypeDataContractAttr = GetDataContractAttribute(propertyType); var subsectionAttr = GetSubSectionAttribute(property); var isCodeValue = propertyType == typeof(CodeValue); string subSection = null; // If a SubSection is specified and we aren't already processing a SubSection. if (subsectionAttr != null && string.IsNullOrWhiteSpace(parentSubSectionName)) { subSection = string.IsNullOrWhiteSpace(subsectionAttr.Name) ? property.Name.ToEnglish() : subsectionAttr.Name; } // If the property is attributed as a Field if (fieldAttr != null) { ProcessSectionField(dataEntrySection, property, fieldAttr, parentSubSectionName ?? subSection, parentPath, implementation); continue; } // If the property type is a DataContract Process its properties. // Hack: Skip Code Values that have not been propperly attributed if (propertyTypeDataContractAttr != null && !isCodeValue) { // Process the Properties of the DataContract type ProcessSectionProperties(dataEntrySection, propertyType, parentSubSectionName ?? subSection, BuildPath(parentPath, property.Name), implementation); } } }
public void CreateExtendedField() { var agencyId = Guid.NewGuid(); dataEntrySectionObj = new DataEntrySection(); var result = dataEntrySectionObj.CreateConcreteField("data", "", ControlType.Dropdown); }
/// <summary> /// Inject DataEntrySection Metadata into a Section DTO. /// </summary> /// <param name="dto"></param> /// <param name="meta"></param> private void InjectMetadata(DTO.Section dto, DataEntrySection meta) { dto.IsCollection = meta.IsCollection; dto.Name = meta.Name; dto.Path = meta.Path; dto.SectionType = meta.SectionType; }
private void UpdateMetadata(DataEntrySection sourceSection, DataEntrySection destinationSection) { destinationSection.Description = sourceSection.Description; destinationSection.IsCollection = sourceSection.IsCollection; destinationSection.Label = sourceSection.Label; destinationSection.Name = sourceSection.Name; destinationSection.OrderBy = sourceSection.OrderBy; destinationSection.Path = sourceSection.Path; // This is how we matched sections so they should already be the same. destinationSection.PropertyName = sourceSection.PropertyName; destinationSection.SectionType = sourceSection.SectionType; destinationSection.TypeName = sourceSection.TypeName; // Fields to Update var fieldsToUpdate = sourceSection.Fields.Where(x => destinationSection.Fields.Any(y => y.Path == x.Path)).ToList(); fieldsToUpdate.ForEach(sourceField => { var destinationField = destinationSection.Fields.First(x => x.Path == sourceField.Path); UpdateMetadata(sourceField, destinationField); }); // Field to Add var fieldsToAdd = sourceSection.Fields.Where(x => destinationSection.Fields.All(y => y.Path != x.Path)).ToList(); fieldsToAdd.ForEach(destinationSection.Fields.Add); }
/// <summary> /// Load the information in the DataEntrySection into a Template Section. /// </summary> private static void LoadFromMeta(Section section, DataEntrySection dataEntrySection) { section.Description = dataEntrySection.Description; section.Label = dataEntrySection.Label; section.MaxCount = 0; // Currently Only Limited in the Designer. section.OrderBy = dataEntrySection.OrderBy; foreach (var fieldGroup in dataEntrySection.Fields.GroupBy(x => x.SubSectionName)) { var subSection = fieldGroup.Key == null ? null : section.CreateSubSection(fieldGroup.Key); foreach (var dataEntryField in fieldGroup.OrderBy(x => x.OrderBy)) { var field = section.CreateField(dataEntryField.Id, dataEntryField.Label, subSection); //field.AgencyValidation = Agency Validation is not part of the Metadata field.ColumnSpan = dataEntryField.ColumnSpan; field.DefaultValue = dataEntryField.DefaultValue; field.Description = dataEntryField.Description; field.Label = dataEntryField.Label; field.MasterIndexSearchable = dataEntryField.MasterIndexSearchable; // This Shouldn't be in the Template field.OrderBy = dataEntryField.OrderBy; field.ReportDisplayType = FieldReportDisplayType.Unset; field.SetCurrentDate = dataEntryField.SetCurrentDate; // This Shouldn't be in the Meta? } } }
/// <summary> /// Get the Layout Information for a Section. /// </summary> private SectionLayout GetSectionLayout(Section section, DataEntrySection dataEntrySection) { // Create the Section Layout var sectionLayout = new SectionLayout() { // The Name is what is Used to correlate sections across systems. // This is because the metadata has different IDs across all systems. DataEntrySectionName = dataEntrySection.Name, Description = section.Description, Fields = new List <FieldLayout>(), Label = section.Label, OrderBy = section.OrderBy, SubSections = new List <SubSectionLayout>() }; // Process SubSections foreach (var subSection in section.SubSections) { sectionLayout.SubSections.Add(GetSubSectionLayout(subSection, dataEntrySection)); } // Process Fields foreach (var field in section.Fields) { // Lookup the SubSection Name var subSectionName = field.SubSectionId == Guid.Empty ? null : section.GetSubSection(field.SubSectionId).Label; // Lookup the Metadata var dataEntryField = dataEntrySection.GetField(field.DataEntryFieldId); // Get the Field Layout. sectionLayout.Fields.Add(GetFieldLayout(field, dataEntryField, subSectionName)); } return(sectionLayout); }
/// <summary> /// Get the Layout information for a SubSection. /// </summary> private SubSectionLayout GetSubSectionLayout(SubSection subSection, DataEntrySection dataEntrySection) { return(new SubSectionLayout { Label = subSection.Label, OrderBy = subSection.OrderBy }); }
public void GetField() { var agencyId = Guid.NewGuid(); dataEntrySectionObj = new DataEntrySection(); var result = dataEntrySectionObj.GetField("data", FieldType.Unset); result.Should().BeNull(); }
public void CreateExtendedField_1() { var agencyId = Guid.NewGuid(); dataEntrySectionObj = new DataEntrySection(); var result = dataEntrySectionObj.CreateExtendedField("data", "data", ControlType.Dropdown); result.Should().BeOfType(typeof(DataEntryField)); result.Should().NotBeNull(); }
private static void BuildFields(Section section, DataEntrySection dataEntrySection) { foreach (var dataEntryField in dataEntrySection.Fields.OrderBy(x => x.OrderBy)) { var field = section.CreateField(dataEntryField.Name, dataEntryField.Path, dataEntryField.FieldType, dataEntryField.ControlType); if (!string.IsNullOrEmpty(dataEntryField.Label)) { field.Label = dataEntryField.Label; } field.OrderBy = dataEntryField.OrderBy; field.Category = dataEntryField.Category; field.ColumnSpan = dataEntryField.ColumnSpan; } }
public void ClassLevelSetUp() { _metadataUnitOfWork = new Mock <IMetadataUnitOfWork>(); _dataEntryMetadataQueryService = new DataEntryMetadataQueryService(_metadataUnitOfWork.Object, Mock.Of <ILog>(), Mock.Of <IServiceAuthorizationPolicy>(), Mock.Of <IServiceIdentityProvider>()); _dataEntrySection = new DataEntrySection { Description = "Description", IsCollection = true, Label = "Label", Name = "Name", Path = "path", TypeName = "Type Name", PropertyName = "Property Name", SectionType = SectionType.Drug, OrderBy = 1 }; }
private static void ProcessDataContractSections(DataEntryContract contract, Type type, string implementation) { foreach (var property in type.GetProperties()) { // Get the type of the Section var sectionType = PropertyTypeIsCollectionOfSections(property) ? GenericParameterType(property.PropertyType) : property.PropertyType; // Get the Section Attribute from the Property Type var sectionAttribute = GetSectionAttribute(sectionType); // Only Process Section Types if (sectionAttribute == null) { continue; } // Get the Section Attribute var sectionAttr = GetSectionAttribute(sectionType); // If the property is not a section continue if (sectionAttr == null) { continue; } // Create a DataEntrySection var dataEntrySection = new DataEntrySection() { OrderBy = contract.Sections.Count, Name = property.Name, Path = property.Name.ToPascalCase(), Label = GetLabel(property) ?? property.Name.ToEnglish(), Description = GetDescription(sectionType), IsCollection = IsCollection(property.PropertyType), PropertyName = property.Name, SectionType = sectionAttr.SectionType, TypeName = sectionType.FullName }; // Add the section to the contract contract.Sections.Add(dataEntrySection); // Process the properties on the Section's Type. ProcessSectionProperties(dataEntrySection, sectionType, null, null, implementation); } }
public void CreateCustomField() { var metadataUnitOfWork = new Mock <IMetadataUnitOfWork>(); var dataEntryMetadataCommandService = new DataEntryMetadataCommandService(metadataUnitOfWork.Object, Mock.Of <ILog>(), Mock.Of <IServiceAuthorizationPolicy>(), Mock.Of <IServiceIdentityProvider>()); var dataEntrySection = new DataEntrySection(); metadataUnitOfWork.Setup(mock => mock.Find <DataEntrySection>(It.IsAny <Guid>(), TrackingMode.Automatic, ThrowIf.Anything)).Returns(dataEntrySection); var customDataEntryFieldDetails = new DTO.CustomDataEntryFieldDetails(); customDataEntryFieldDetails.Name = "Custom Field"; customDataEntryFieldDetails.ControlType = ControlType.Text; var customFieldId = dataEntryMetadataCommandService.CreateCustomField(It.IsAny <Guid>(), It.IsAny <Guid>(), customDataEntryFieldDetails); customFieldId.Should().NotBeEmpty(); metadataUnitOfWork.VerifyAll(); }
private static void ProcessSectionFields(DataEntrySection sectionContract, SectionAttribute sectionAttribute, Type sectionType) { // Get the Section Properties foreach (var property in sectionType.GetProperties()) { var fieldAttribute = GetFieldAttribute(property); var fieldGroupAttribute = GetFieldGroupAttribute(property.PropertyType); if (fieldAttribute != null && fieldGroupAttribute == null) // Regular Field { ProcessField(sectionContract, property, fieldAttribute); continue; } if (fieldGroupAttribute != null) { ProcessFieldGroup(sectionContract, property, fieldGroupAttribute, property.Name.ToPascalCase()); continue; } } }
private static void ProcessSectionProperty(DataEntryContract contract, PropertyInfo property, Type sectionType, SectionAttribute sectionAttribute) { // Create the Section Metadata var sectionContract = new DataEntrySection() { OrderBy = contract.Sections.Count, Name = property.Name, Path = property.Name.ToPascalCase(), Label = GetLabel(property) ?? MakeEnglish(property.Name), Description = GetDescription(sectionType), AllowMultiple = IsCollection(property.PropertyType), PropertyName = property.Name, SectionType = sectionAttribute.SectionType, TypeName = sectionType.FullName }; // Process the Field Metadata ProcessSectionFields(sectionContract, sectionAttribute, sectionType); contract.Sections.Add(sectionContract); }
private static void ProcessField(DataEntrySection sectionContract, PropertyInfo property, FieldAttribute fieldAttribute, string parentPath = null) { sectionContract.Fields.Add(new DataEntryField() { OrderBy = sectionContract.Fields.Count, Category = GetCategory(property), ColumnSpan = fieldAttribute.ColumnSpan, ControlType = fieldAttribute.ControlType != ControlType.Unset ? fieldAttribute.ControlType : GetDefaultControlType(property.PropertyType), DefaultMask = GetMask(property), DefaultValue = GetDefaultValue(property), FieldType = FieldType.Concrete, Description = GetDescription(property), MaxLength = GetMaxLength(property), Name = property.Name, Label = GetLabel(property) ?? property.Name, Path = BuildPath(parentPath, property.Name) }); }
private static void ProcessFieldGroup(DataEntrySection sectionContract, PropertyInfo property, FieldGroupAttribute fieldGroupAttribute, string parentPath = null) { var propertyType = property.PropertyType; foreach (var groupProperty in propertyType.GetProperties()) { var childFieldGroupAttribute = GetFieldGroupAttribute(groupProperty.PropertyType); if (childFieldGroupAttribute == null) { // Property is a Field var fieldAttribute = GetFieldAttribute(groupProperty); if (fieldAttribute != null) // But Make Sure { ProcessField(sectionContract, groupProperty, fieldAttribute, parentPath); } } else { // Property is a Field Group ProcessFieldGroup(sectionContract, groupProperty, childFieldGroupAttribute, BuildPath(parentPath, groupProperty.Name)); } } }
/// <summary> /// Process a Field Property of a DataEntrySection /// </summary> private static void ProcessSectionField(DataEntrySection dataEntrySection, PropertyInfo property, FieldAttribute fieldAttr, string subSectionName, string parentPath, string implementation) { var name = property.Name; var controlType = fieldAttr.ControlType != ControlType.Unset ? fieldAttr.ControlType : GetDefaultControlType(property.PropertyType); var path = BuildPath(parentPath, name); // Create a New Concrete Field var field = dataEntrySection.CreateConcreteField(property.Name, path, controlType); // Set new Field Properties field.SubSectionName = subSectionName; field.OrderBy = dataEntrySection.Fields.Count; field.Cascades = GetCascades(property); field.Category = GetCategory(property, implementation); field.ColumnSpan = fieldAttr.ColumnSpan; field.DefaultMask = GetMask(property); field.DefaultValue = GetDefaultValue(property); field.Description = GetDescription(property); field.MaxLength = GetMaxLength(property); field.Label = GetLabel(property) ?? property.Name; field.MasterIndexSearchable = GetMasterIndexSearchable(property); }
/// <summary> /// Apply Layout Information to an Existing Section. /// </summary> /// <param name="sectionLayout">The Section Layout Information.</param> /// <param name="section">The Section to apply the layout to.</param> /// <param name="sectionMetadata">Local Metadata for the Section.</param> private void ApplySectionLayout(SectionLayout sectionLayout, Section section, DataEntrySection sectionMetadata) { // Load the Section Information section.Description = sectionLayout.Description; section.OrderBy = sectionLayout.OrderBy; // Process SubSections foreach (var subSectionLayout in sectionLayout.SubSections) { // Make sure the SubSections Exist if (section.GetSubSection(subSectionLayout.Label) == null) { section.CreateSubSection(subSectionLayout.Label); } } // Process Fields foreach (var fieldLayout in sectionLayout.Fields) { // Find the appropriate SubSection if any. var subSection = string.IsNullOrWhiteSpace(fieldLayout.SubSectionName) ? null : section.GetSubSection(fieldLayout.SubSectionName); // Lookup the Field Metadata var fieldMeta = sectionMetadata.GetFieldByPath(fieldLayout.Path); if (fieldMeta == null) { _log.Error("WARNING: No Metadata can be found in Section {0} for field with path {1}!", section.Label, fieldLayout.Path); continue; } // Find or Create the Field var field = section.GetFieldByMetaId(fieldMeta.Id) ?? section.CreateField(fieldMeta.Id, fieldLayout.Label, subSection); // Load the Layout Information into the Field. field.AgencyValidation = fieldLayout.AgencyValidation; field.ColumnSpan = fieldLayout.ColumnSpan; field.DefaultValue = fieldLayout.DefaultValue; field.Description = fieldLayout.Description; field.Label = fieldLayout.Label; field.MasterIndexSearchable = fieldMeta.MasterIndexSearchable; // Pulled From Meta (This should be injected at runtime instead). field.OrderBy = fieldLayout.OrderBy; // field.ReportDisplayType = This is not yet supported in the Layout. field.SetCurrentDate = fieldMeta.SetCurrentDate; // This is pulled from the Meta, This should have been part of DefaultValue. } }