public bool InsertStandardDataType(StandardDataTypeModel model)
        {
            AutomationStandardsContext db     = new AutomationStandardsContext();
            StandardDataType           Result = new StandardDataType();

            Result.DataTypeName = model.StandardDataTypeName;
            Result.SQLDataType  = model.SQLDataType;

            db.StandardDataType.Add(Result);

            try
            {
                db.SaveChanges();
                model.StandardDataTypeID = Result.DataTypeID;
                return(true);
            }
            catch (DbEntityValidationException ex)
            {
                string body = "";
                foreach (var eve in ex.EntityValidationErrors)
                {
                    body += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    body += "<br>";
                    foreach (var ve in eve.ValidationErrors)
                    {
                        body += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                    }
                }

                //GlobalFunctions gf = new //GlobalFunctions();
                //gf.SendErrorModelEmail(this.GetType().Name, body);
                return(false);
            }
        }
Beispiel #2
0
        private string DetermineActualDataType(StandardDataType modelType, StandardDataType newType, bool isCdaR1, ErrorLogger errorLogger
                                               )
        {
            StandardDataType convertedModelType = modelType;

            if (cdaR1MappingsToOld.ContainsKey(modelType))
            {
                convertedModelType = cdaR1MappingsToOld.SafeGet(modelType);
            }
            string unspecializedModelType = convertedModelType.TypeName.UnspecializedName;
            string unspecializedNewType   = newType.TypeName.UnspecializedName;

            // allow ANY handlers and collection handlers deal with type changes on their own
            if (StandardDataType.ANY.Type.Equals(unspecializedModelType) || StandardDataType.IsSetOrList(unspecializedModelType))
            {
                return(modelType.Type);
            }
            if (IsValidTypeChange(unspecializedModelType, unspecializedNewType))
            {
                return(MapCdaR1Type(newType, isCdaR1));
            }
            else
            {
                string message = System.String.Format("Not able to handle type change from {0} to {1}. Type has been left unchanged.", convertedModelType
                                                      .Type, newType.Type);
                errorLogger.LogError(Hl7ErrorCode.UNSUPPORTED_TYPE_CHANGE, ErrorLevel.WARNING, message);
                return(modelType.Type);
            }
        }
Beispiel #3
0
        // Note that the behaviour for this datatype has not been fully defined by CHI. It is likely that the code below will need to be adjusted at some point.
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override string ParseNonNullNode(ParseContext context, XmlNode node, BareANY parseResult, Type expectedReturnType
                                                   , XmlToModelResult xmlToModelResult)
        {
            StandardDataType type = StandardDataType.GetByTypeName(context);

            ValidateUnallowedAttributes(type, (XmlElement)node, xmlToModelResult, "compression");
            ValidateUnallowedAttributes(type, (XmlElement)node, xmlToModelResult, "language");
            ValidateUnallowedAttributes(type, (XmlElement)node, xmlToModelResult, "reference");
            ValidateUnallowedAttributes(type, (XmlElement)node, xmlToModelResult, "integrityCheck");
            ValidateUnallowedAttributes(type, (XmlElement)node, xmlToModelResult, "thumbnail");
            ValidateMaxChildCount(context, node, 1);
            if (!Ca.Infoway.Messagebuilder.Domainvalue.Basic.MediaType.XML_TEXT.CodeValue.Equals(GetAttributeValue(node, "mediaType")
                                                                                                 ))
            {
                xmlToModelResult.AddHl7Error(CreateHl7Error("Attribute mediaType must be included with a value of \"text/xml\" for ED.SIGNATURE"
                                                            , (XmlElement)node));
            }
            string  result        = null;
            XmlNode signatureNode = GetNamedChildNode(node, "signature");

            if (signatureNode == null || signatureNode.NodeType != System.Xml.XmlNodeType.Element)
            {
                xmlToModelResult.AddHl7Error(CreateHl7Error("Expected ED.SIGNATURE node to have a child element named signature", (XmlElement
                                                                                                                                   )node));
            }
            else
            {
                result = (string)this.stElementParser.Parse(context, signatureNode, xmlToModelResult).BareValue;
            }
            return(result);
        }
Beispiel #4
0
        private string DetermineActualType(Relationship relationship, BareANY hl7Value, Hl7Errors errors, string propertyPath)
        {
            StandardDataType newTypeEnum = (hl7Value == null ? null : hl7Value.DataType);

            return(this.polymorphismHandler.DetermineActualDataType(relationship.Type, newTypeEnum, this.isCda, !this.isR2, CreateErrorLogger
                                                                        (propertyPath, errors)));
        }
Beispiel #5
0
 private void ValidateRootLength(string root, VersionNumber version, StandardDataType type, FormatContext context)
 {
     if (iiValidationUtils.IsRootLengthInvalid(root, type, version))
     {
         RecordError(iiValidationUtils.GetInvalidRootLengthErrorMessage(root, type, version), context);
     }
 }
Beispiel #6
0
        private PlatformDate ParseNonNullNode(ParseContext context, XmlElement element, XmlToModelResult xmlToModelResult)
        {
            // TM - for V02R01, "width" property is allowed (PQ.TIME) - not including this here, as MB does not officially support that release
            PlatformDate result       = null;
            string       unparsedDate = GetAttributeValue(element, "value");

            if (StringUtils.IsBlank(unparsedDate))
            {
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Timestamp value must be non-blank.", element));
            }
            else
            {
                try
                {
                    result = ParseDate(unparsedDate, GetAllDateFormats(StandardDataType.GetByTypeName(GetType(context)), context.GetVersion()
                                                                       ), context);
                    CheckForMissingTimezone(context, xmlToModelResult, result, unparsedDate, element);
                }
                catch (ArgumentException)
                {
                    result = TryEveryFormat(context, unparsedDate, element, xmlToModelResult);
                    if (result == null)
                    {
                        string message = "The timestamp " + unparsedDate + " in element " + XmlDescriber.DescribeSingleElement(element) + " cannot be parsed.";
                        xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, message, element));
                    }
                }
            }
            return(result);
        }
Beispiel #7
0
 private void ValidateSpecializationType(StandardDataType specializationType, bool valueOmitted, FormatContext context)
 {
     if (specializationType == StandardDataType.TS || specializationType == null)
     {
         if (Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(Runtime.GetProperty(TsDateFormats.ABSTRACT_TS_IGNORE_SPECIALIZATION_TYPE_ERROR_PROPERTY_NAME
                                                                                )))
         {
         }
         else
         {
             // user has specified that this validation error should be suppressed
             if (valueOmitted)
             {
             }
             else
             {
                 // RM16399 - there are some cases where it is valid to omit a specialization type (such as when not providing a TS value)
                 // do nothing; other potential errors will be caught by the default concrete TS formatter
                 context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("No specializationType provided. Value should be one of TS.FULLDATE / TS.FULLDATETIME / TS.FULLDATEPARTTIME. TS.FULLDATETIME will be assumed."
                                                                                                                           , specializationType.Type), context.GetPropertyPath()));
             }
         }
     }
     else
     {
         if (specializationType != StandardDataType.TS_FULLDATE && specializationType != StandardDataType.TS_FULLDATETIME && specializationType
             != StandardDataType.TS_FULLDATEPARTTIME)
         {
             context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("Invalid specializationType: {0}. Value should be one of TS.FULLDATE / TS.FULLDATETIME / TS.FULLDATEPARTTIME. TS.FULLDATETIME will be assumed."
                                                                                                                       , specializationType.Type), context.GetPropertyPath()));
         }
     }
 }
Beispiel #8
0
        private bool IsValidSpecializationType(string specializationType)
        {
            StandardDataType type = StandardDataType.GetByTypeName(specializationType);

            return(StandardDataType.TS_FULLDATE.Equals(type) || StandardDataType.TS_FULLDATETIME.Equals(type) || StandardDataType.TS_FULLDATEPARTTIME
                   .Equals(type));
        }
Beispiel #9
0
        private void ValidateDatePattern(string datePattern, FormatContext context)
        {
            StandardDataType standardDataType = StandardDataType.GetByTypeName(context);
            VersionNumber    version          = (context == null ? null : context.GetVersion());

            string[] allowedDateFormats = TsDateFormats.GetAllDateFormats(standardDataType, version);
            if (ArrayContains(allowedDateFormats, datePattern))
            {
                // check if this pattern is missing a timezone
                if (!IsCerx(standardDataType, version) && TsDateFormats.datetimeFormatsRequiringWarning.Contains(datePattern))
                {
                    context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("Date format {0} supplied for value of type {1} should also have a timezone (ZZZZZ)"
                                                                                                                              , datePattern, context == null ? "TS" : context.Type), context.GetPropertyPath()));
                }
            }
            else
            {
                // MBR-368: a temporary work-around for producing AB PIN compliant date time renderings
                // with out error messages -- required until the runtime's knowledge of datatypes has been
                // corrected to distinguish between CeRx v3 (ie., V01R03) and CeRx v4 (ie., V01R04)
                if (!SpecificationVersion.IsExactVersion(SpecificationVersion.V01R04_1_AB, version))
                {
                    context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("Invalid date format {0} supplied for value of type {1}"
                                                                                                                              , datePattern, context == null ? "TS" : context.Type), context.GetPropertyPath()));
                }
            }
        }
Beispiel #10
0
        public virtual string DetermineActualDataTypeFromXsiType(string modelType, string newTypeFromXsiType, bool isCda, bool isR1
                                                                 , ErrorLogger errorLogger)
        {
            StandardDataType newTypeEnum = EnumPattern.ValueOf <StandardDataType>(newTypeFromXsiType);

            return(DetermineActualDataType(modelType, newTypeEnum, isCda, isR1, errorLogger));
        }
Beispiel #11
0
 private bool IsCenterProhibited(bool isCeRx, StandardDataType innerType)
 {
     // only allowed for *CeRx* types: IVL<TS.DATE> and IVL<TS.FULLDATE>
     // also allowed for types (of any version): URG<TS.DATE>
     return(!(isCeRx && !this.isUncertainRangeValidation && (innerType == StandardDataType.TS_DATE || innerType == StandardDataType
                                                             .TS_FULLDATE)) && !(this.isUncertainRangeValidation && innerType == StandardDataType.TS_DATE));
 }
Beispiel #12
0
 private string CreateWrongNumberOfElementsProvidedErrorMessage(bool isCeRx, string type, StandardDataType ivlType, StandardDataType
                                                                innerType, StandardDataType baseInnerType)
 {
     return(GetIntervalOrRange() + "s of type " + type + " must " + (ivlType == StandardDataType.IVL || ivlType == StandardDataType
                                                                     .URG ? "provide exactly 2 of" : "only provide") + ": " + (IsLowProhibited(ivlType) ? string.Empty : "low ") + (IsHighProhibited
                                                                                                                                                                                        (ivlType) ? string.Empty : "high ") + (IsCenterProhibited(isCeRx, innerType) ? string.Empty : "center ") + (IsWidthProhibited
                                                                                                                                                                                                                                                                                                        (ivlType, innerType, baseInnerType) ? string.Empty : "width "));
 }
Beispiel #13
0
        internal virtual bool IsValidTypeChange(string currentType, string newType)
        {
            // assumes types come in as IVL<TS> and *not* IVL_TS (which is what xsi:type would have for a value)
            StandardDataType inType  = StandardDataType.GetByTypeName(currentType);
            StandardDataType outType = StandardDataType.GetByTypeName(newType);

            return(IsValidTypeChange(inType, outType));
        }
Beispiel #14
0
 public virtual string MapCdaR1Type(StandardDataType newType, bool isCdaR1)
 {
     if (isCdaR1 && cdaR1MappingsToNew.ContainsKey(newType))
     {
         return(cdaR1MappingsToNew.SafeGet(newType).Type);
     }
     return(newType.Type);
 }
Beispiel #15
0
 private string GetDefaultDatePattern(StandardDataType standardDataType, VersionNumber version)
 {
     if (SpecificationVersion.IsVersion(standardDataType, version, Hl7BaseVersion.CERX))
     {
         return(DATE_FORMAT_YYYYMMDDHHMMSS);
     }
     return(DATE_FORMAT_YYYYMMDDHHMMSS_SSSZZZZZ);
 }
Beispiel #16
0
 private void ValidateRootLength(XmlElement element, string root, XmlToModelResult xmlToModelResult, VersionNumber version
                                 , StandardDataType type)
 {
     if (iiValidationUtils.IsRootLengthInvalid(root, type, version))
     {
         RecordError(iiValidationUtils.GetInvalidRootLengthErrorMessage(root, type, version), element, xmlToModelResult);
     }
 }
Beispiel #17
0
 public virtual bool CanAdapt(Type fromDataType, string toDataTypeName)
 {
     if (IsCOLLECTIONType(fromDataType) && !StandardDataType.IsSetOrList(toDataTypeName))
     {
         return(true);
     }
     return(false);
 }
Beispiel #18
0
 public virtual bool CanAdapt(Type fromDataType, string toDataTypeName)
 {
     if (IsCOLLECTIONType(fromDataType) && StandardDataType.SET.Equals(StandardDataType.GetByTypeName
                                                                           (toDataTypeName)) && ContainerOfTn(toDataTypeName))
     {
         return(true);
     }
     return(false);
 }
Beispiel #19
0
        public virtual bool IsSpecializationTypeRequired(VersionNumber version, string type, bool isCda)
        {
            StandardDataType standardDataType = StandardDataType.GetByTypeName(type);

            // AB does not treat II as abstract; for CeRx, II is concrete; Newfoundland is excepted to allow our legacy tests to pass
            return(IsIiBusAndVer(type) || (IsII(type) && !(isCda || SpecificationVersion.IsVersion(standardDataType, version, Hl7BaseVersion
                                                                                                   .CERX) || "NEWFOUNDLAND".Equals(version == null ? null : version.VersionLiteral) || SpecificationVersion.IsExactVersion(
                                                               SpecificationVersion.V02R02_AB, version))));
        }
Beispiel #20
0
 protected virtual void ValidateUnallowedAttributes(StandardDataType type, XmlElement node, XmlToModelResult result, string
                                                    attribute)
 {
     if (StringUtils.IsNotBlank(GetAttributeValue(node, attribute)))
     {
         result.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, type.Type + " should not include the '" + attribute + "' property. ("
                                         + XmlDescriber.DescribeSingleElement(node) + ")", node));
     }
 }
Beispiel #21
0
        internal virtual bool IsValidTypeChange(StandardDataType currentType, StandardDataType newType)
        {
            // bug fix: if the new type ends up being the root type of the current (model) type, that is valid
            if (currentType != null && currentType.Equals(newType))
            {
                return(true);
            }
            IList <StandardDataType> allowedTypes = allowedMappings.SafeGet(currentType);

            return(allowedTypes != null && allowedTypes.Contains(newType));
        }
Beispiel #22
0
        protected sealed override string GetValue(TelecommunicationAddress uri, FormatContext context, BareANY bareAny)
        {
            string           type = context.Type;
            StandardDataType specializationType = bareAny.DataType;
            VersionNumber    version            = context.GetVersion();
            Hl7Errors        errors             = context.GetModelToXmlResult();

            TEL_VALIDATION_UTILS.ValidateTelecommunicationAddress(uri, type, specializationType.Type, version, null, context.GetPropertyPath
                                                                      (), errors);
            return(uri.ToString());
        }
Beispiel #23
0
 private void ValidateRootAsOid(string root, VersionNumber version, StandardDataType type, FormatContext context)
 {
     if (StringUtils.IsNotBlank(root))
     {
         if (!iiValidationUtils.IsOid(root))
         {
             RecordError(iiValidationUtils.GetRootMustBeAnOidErrorMessage(root), context);
         }
         ValidateRootLength(root, version, type, context);
     }
 }
Beispiel #24
0
 private void ValidateRootAsOid(string root, XmlElement element, XmlToModelResult xmlToModelResult, VersionNumber version,
                                StandardDataType type)
 {
     if (StringUtils.IsNotBlank(root))
     {
         if (!iiValidationUtils.IsOid(root))
         {
             RecordError(iiValidationUtils.GetRootMustBeAnOidErrorMessage(root), element, xmlToModelResult);
         }
         ValidateRootLength(element, root, xmlToModelResult, version, type);
     }
 }
Beispiel #25
0
 private void ChangeDatatypeIfNecessary(string type, Relationship relationship, BareANY @object)
 {
     // if the type parsed was different from the relationship type, preserve that info in the parsed object
     if (@object != null && !relationship.Type.Equals(type))
     {
         StandardDataType newDataType = StandardDataType.GetByTypeName(type);
         if (newDataType != null)
         {
             @object.DataType = newDataType;
         }
     }
 }
Beispiel #26
0
        private Type GetUnitTypeByHl7Type(string typeAsString, XmlElement element, string propertyPath, Hl7Errors errors, bool isR2
                                          )
        {
            StandardDataType type = StandardDataType.GetByTypeName(typeAsString);

            if (StandardDataType.PQ_BASIC.Equals(type))
            {
                return(typeof(x_BasicUnitsOfMeasure));
            }
            else
            {
                if (StandardDataType.PQ_DRUG.Equals(type))
                {
                    return(typeof(x_DrugUnitsOfMeasure));
                }
                else
                {
                    if (StandardDataType.PQ_TIME.Equals(type))
                    {
                        return(typeof(x_TimeUnitsOfMeasure));
                    }
                    else
                    {
                        if (StandardDataType.PQ_LAB.Equals(type))
                        {
                            return(typeof(x_LabUnitsOfMeasure));
                        }
                        else
                        {
                            if (StandardDataType.PQ_HEIGHTWEIGHT.Equals(type))
                            {
                                return(typeof(x_HeightOrWeightObservationUnitsOfMeasure));
                            }
                            else
                            {
                                if (StandardDataType.PQ_DISTANCE.Equals(type))
                                {
                                    return(typeof(x_DistanceObservationUnitsOfMeasure));
                                }
                                else
                                {
                                    if (!isR2)
                                    {
                                        CreateWarning(System.String.Format("Type \"{0}\" is not a valid PQ type", typeAsString), element, propertyPath, errors);
                                    }
                                    return(typeof(Ca.Infoway.Messagebuilder.Domainvalue.UnitsOfMeasureCaseSensitive));
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #27
0
        private void PerformStandardValidations(ParseContext context, XmlElement element, XmlToModelResult result)
        {
            StandardDataType type = StandardDataType.GetByTypeName(context);

            if (type == StandardDataType.CS)
            {
                ValidateUnallowedAttributes(type, element, result, AbstractCodeTypeElementParser.CODE_SYSTEM_ATTRIBUTE_NAME);
            }
            ValidateUnallowedAttributes(type, element, result, "codeSystemName");
            ValidateUnallowedAttributes(type, element, result, "codeSystemVersion");
            ValidateUnallowedChildNode(context.Type, element, result, "qualifier");
        }
Beispiel #28
0
 private bool IsCodedType(FormatContext context)
 {
     if (context != null && context.Type != null)
     {
         StandardDataType dataType = StandardDataType.GetByTypeName(context);
         if (dataType != null)
         {
             return(dataType.Coded);
         }
     }
     return(false);
 }
Beispiel #29
0
        protected virtual void AddSpecializationType(IDictionary <string, string> attributes, string typeAsString)
        {
            StandardDataType type               = StandardDataType.GetByTypeName(typeAsString);
            string           xsiType            = Xmlify(type.TypeName.UnspecializedName);
            string           specializationType = Xmlify(type.Type);

            attributes[XSI_TYPE] = xsiType;
            if (!StringUtils.Equals(xsiType, specializationType))
            {
                attributes[SPECIALIZATION_TYPE] = specializationType;
            }
        }
Beispiel #30
0
        public virtual string DetermineActualDataType(string modelType, StandardDataType newTypeEnum, bool isCda, bool isR1, ErrorLogger
                                                      errorLogger)
        {
            StandardDataType modelTypeEnum = StandardDataType.GetByTypeName(modelType);

            if (!isCda || modelTypeEnum == null || newTypeEnum == null || StandardDataType.IsSetOrList(modelType) || NewTypeIsRootOfCurrent
                    (modelTypeEnum, newTypeEnum))
            {
                return(modelType);
            }
            return(DetermineActualDataType(modelTypeEnum, newTypeEnum, isCda && isR1, errorLogger));
        }