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()); }