示例#1
0
        public DateTimeValue(string datetime)
        {
            if (!FhirDateTime.IsValidValue(datetime))
            {
                throw Error.Argument("datetime", "The string [" + datetime + "] cannot be translated to a DateTimeValue");
            }
            var fdt = new FhirDateTime(datetime);

            Value = fdt.ToDateTimeOffset(TimeSpan.Zero);
        }
示例#2
0
        //Check all DateTime values in the list and find the earliest value.
        private DateTime ResolveTargetEventDateTime(Timing Timing, bool TargetLowest, int searchParameterId)
        {
            DateTime TargetEventDateTime;

            if (TargetLowest)
            {
                TargetEventDateTime = DateTime.MaxValue.ToUniversalTime();
            }
            else
            {
                TargetEventDateTime = DateTime.MinValue.ToUniversalTime();
            }

            foreach (var EventDateTime in Timing.EventElement)
            {
                if (!string.IsNullOrWhiteSpace(EventDateTime.Value))
                {
                    if (FhirDateTime.IsValidValue(EventDateTime.Value))
                    {
                        PartialDateTime?PartialDateTimeType = EventDateTime.ToPartialDateTime();
                        if (PartialDateTimeType.HasValue)
                        {
                            IndexDateTime?DateTimeIndexOffSetValue = ParsePartialDateTime(PartialDateTimeType.Value, searchParameterId);
                            if (DateTimeIndexOffSetValue is object)
                            {
                                if (TargetLowest)
                                {
                                    if (DateTimeIndexOffSetValue.Low.HasValue)
                                    {
                                        if (TargetEventDateTime > DateTimeIndexOffSetValue.Low.Value)
                                        {
                                            TargetEventDateTime = DateTimeIndexOffSetValue.Low.Value;
                                        }
                                    }
                                }
                                else
                                {
                                    if (DateTimeIndexOffSetValue.High.HasValue)
                                    {
                                        if (TargetEventDateTime < DateTimeIndexOffSetValue.High.Value)
                                        {
                                            TargetEventDateTime = DateTimeIndexOffSetValue.High.Value;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(TargetEventDateTime);
        }
示例#3
0
        public DateValue(string date)
        {
            if (!Date.IsValidValue(date))
            {
                if (!FhirDateTime.IsValidValue(date))
                {
                    throw Error.Argument("date", "The string [" + date + "] is not a valid FHIR date string and isn't a FHIR datetime either");
                }

                // This was a time, so we can just use the date portion of this
                date = (new FhirDateTime(date)).ToDateTimeOffset(TimeSpan.Zero).Date.ToString("yyyy-MM-dd");
            }
            Value = date;
        }
        //Check all DateTime values in the list and find the earliest value.
        private static DateTimeOffset ResolveTargetEventDateTime(Timing Timing, bool TargetLowest)
        {
            DateTimeOffset TargetEventDateTime;

            if (TargetLowest)
            {
                TargetEventDateTime = DateTimeOffset.MaxValue.ToUniversalTime();
            }
            else
            {
                TargetEventDateTime = DateTimeOffset.MinValue.ToUniversalTime();
            }

            foreach (var EventDateTime in Timing.EventElement)
            {
                if (!string.IsNullOrWhiteSpace(EventDateTime.Value))
                {
                    if (FhirDateTime.IsValidValue(EventDateTime.Value))
                    {
                        PartialDateTime?PartialDateTimeType = EventDateTime.ToPartialDateTime();
                        if (PartialDateTimeType.HasValue)
                        {
                            DateTimeIndex DateTimeIndexOffSetValue = ParsePartialDateTime(PartialDateTimeType.Value);

                            DateTimeOffset DateTimeOffSetValue = PartialDateTimeType.Value.ToUniversalTime().ToLocalTime();
                            if (TargetLowest)
                            {
                                if (TargetEventDateTime > DateTimeIndexOffSetValue.Low.Value)
                                {
                                    TargetEventDateTime = DateTimeIndexOffSetValue.Low.Value;
                                }
                            }
                            else
                            {
                                if (TargetEventDateTime < DateTimeIndexOffSetValue.High.Value)
                                {
                                    TargetEventDateTime = DateTimeIndexOffSetValue.High.Value;
                                }
                            }
                        }
                    }
                }
            }
            return(TargetEventDateTime);
        }
示例#5
0
        public OperationOutcome ValidateContent(List <DocumentReference.ContentComponent> contents)
        {
            if (contents == null || contents.Count == 0)
            {
                return(OperationOutcomeFactory.CreateInvalidResource("content"));
            }

            foreach (var content in contents)
            {
                //attachment
                if (content.Attachment == null)
                {
                    return(OperationOutcomeFactory.CreateInvalidResource("attachment"));
                }

                //attachment.contentType
                //TODO validate content type format
                var contentType = content.Attachment.ContentType;
                if (string.IsNullOrEmpty(contentType))
                {
                    return(OperationOutcomeFactory.CreateInvalidResource("contenttype"));
                }

                //attachment.url
                var url = content.Attachment.Url;
                if (string.IsNullOrEmpty(url) || !FhirUri.IsValidValue(url))
                {
                    return(OperationOutcomeFactory.CreateInvalidResource("url"));
                }

                //attachment.creation can be empty
                var      creation = content.Attachment.Creation;
                DateTime validCreation;
                if (!string.IsNullOrEmpty(creation) && (!FhirDateTime.IsValidValue(creation) || !DateTime.TryParse(creation, out validCreation)))
                {
                    return(OperationOutcomeFactory.CreateInvalidResource("creation", $"The attachment creation date value is not a valid dateTime type: {creation}."));
                }
            }

            return(null);
        }
示例#6
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(ValidationResult.Success);
            }

            if (value.GetType() != typeof(string))
            {
                throw new ArgumentException("DateTimePatternAttribute can only be applied to string properties");
            }

            if (FhirDateTime.IsValidValue(value as string))
            {
                return(ValidationResult.Success);
            }
            else
            {
                return(DotNetAttributeValidation.BuildResult(validationContext, "{0} is not a correctly formatted DateTime", value as string));
            }
        }
示例#7
0
        public OperationOutcome ValidPointer(DocumentReference pointer)
        {
            //master identifier
            if (pointer.MasterIdentifier != null)
            {
                var masterIdentifierCheck = _validationHelper.ValidIdentifier(pointer.MasterIdentifier, "masterIdentifier");

                if (!masterIdentifierCheck.valid)
                {
                    return(OperationOutcomeFactory.CreateInvalidResource(masterIdentifierCheck.issue, "If the masterIdentifier is supplied then the value and system properties are mandatory"));
                }
            }

            //status
            if (!GetValidStatus(pointer.Status).HasValue)
            {
                return(OperationOutcomeFactory.CreateInvalidResource("status", "The status of a new DocumentReference can only be \"current\""));
            }

            //type
            if (pointer.Type == null)
            {
                return(OperationOutcomeFactory.CreateInvalidResource(null));
            }
            else if (!_validationHelper.ValidCodableConcept(pointer.Type, FhirConstants.SystemPointerType, true, true, true, true, FhirConstants.VsRecordType))
            {
                return(OperationOutcomeFactory.CreateInvalidResource("type"));
            }

            //subject
            if (pointer.Subject != null)
            {
                var validNhsNumber = ValidatePatientReference(pointer.Subject);

                if (validNhsNumber != null)
                {
                    return(validNhsNumber);
                }
            }
            else
            {
                return(OperationOutcomeFactory.CreateInvalidResource(null));
            }

            //validate orgcode is real done outside of here
            //author
            if (pointer.Author != null && pointer.Author.Count == 1)
            {
                var validAuthor = ValidateOrganisationReference(pointer.Author.First(), "author");

                if (validAuthor != null)
                {
                    return(validAuthor);
                }
            }
            else
            {
                return(OperationOutcomeFactory.CreateInvalidResource(null));
            }


            //validate orgcode for match against fromASID and is real done outside of here
            //custodian
            if (pointer.Custodian != null)
            {
                var validCustodian = ValidateOrganisationReference(pointer.Custodian, "custodian");

                if (validCustodian != null)
                {
                    return(validCustodian);
                }
            }
            else
            {
                return(OperationOutcomeFactory.CreateInvalidResource(null));
            }

            //indexed
            DateTime validIndexed;

            if (pointer.Indexed == null)
            {
                return(OperationOutcomeFactory.CreateInvalidResource(null));
            }
            else if (!pointer.Indexed.HasValue || !FhirDateTime.IsValidValue(pointer.Indexed.Value.ToString(DateTimeFormat)) || !DateTime.TryParse(pointer.Indexed.Value.ToString(DateTimeFormat), out validIndexed))
            {
                return(OperationOutcomeFactory.CreateInvalidResource("indexed"));
            }

            //relatesTo
            //Only require basic checks here
            //Additional checks are carried out in NrlsMaintain.ValidateConditionalUpdate
            var relatesTo = GetValidRelatesTo(pointer.RelatesTo);

            if (pointer.RelatesTo != null && pointer.RelatesTo.Count > 0 && relatesTo.element == null)
            {
                return(OperationOutcomeFactory.CreateInvalidResource(relatesTo.issue));
            }

            //attachment
            if (pointer.Content != null)
            {
                var validContent = ValidateContent(pointer.Content);

                if (validContent != null)
                {
                    return(validContent);
                }
            }
            else
            {
                return(OperationOutcomeFactory.CreateInvalidResource(null));
            }

            return(OperationOutcomeFactory.CreateOk());
        }