Beispiel #1
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());
        }
        public OperationOutcome ValidPointer(DocumentReference pointer)
        {
            var profile = (pointer.Meta?.Profile?.Contains(FhirConstants.SystemNrlsPrefProfile)) == true ? FhirConstants.SystemNrlsPrefProfile :
                          FhirConstants.SystemNrlsProfile;

            //Base NRL Pointer Validation
            var profileCheck = _validationHelper.ValidateResource(pointer, profile);

            if (!profileCheck.Success)
            {
                var error = profileCheck.Issue.FirstOrDefault(x => x.Severity.HasValue && new OperationOutcome.IssueSeverity[] { OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueSeverity.Fatal }.Contains(x.Severity.Value));

                //NOTE: structure of property and diagnostics will not match NRL output
                return(OperationOutcomeFactory.CreateInvalidResource(error.Location.First(), error.Details.Text));
            }

            //Below checks cover what profile checker can't check


            //profile check
            var profiles = pointer.Meta?.Profile;

            if (profiles == null || profiles.Count() != 1 || profiles.FirstOrDefault(x => new string[] { FhirConstants.SystemNrlsProfile, FhirConstants.SystemNrlsPrefProfile }.Contains(x)) == null)
            {
                return(OperationOutcomeFactory.CreateInvalidResource("meta.Profile", $"There must be a single profile of the value {FhirConstants.SystemNrlsProfile} or {FhirConstants.SystemNrlsPrefProfile}"));
            }

            //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\""));
            }

            //subject
            //Just NHS Number Validation
            var validNhsNumber = ValidatePatientReference(pointer.Subject);

            if (validNhsNumber != null)
            {
                return(validNhsNumber);
            }

            //author
            //validate orgcode is done outside of here
            var validAuthor = ValidateOrganisationReference(pointer.Author.First(), "author");

            if (validAuthor != null)
            {
                return(validAuthor);
            }


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

            if (validCustodian != null)
            {
                return(validCustodian);
            }

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

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

            //Content
            var validContent = ValidateContent(pointer.Content);

            if (validContent != null)
            {
                return(validContent);
            }

            //Context
            //Checked in profile checker
            var period = pointer.Context.Period;

            if (period != null && string.IsNullOrEmpty(period.Start))
            {
                return(OperationOutcomeFactory.CreateInvalidResource("context.period", "When included the period element must have a valid start dateTime."));
            }
            //WARNING: practice setting valueset is stored locally

            return(OperationOutcomeFactory.CreateOk());
        }