public async SystemTasks.Task <IEnumerable <PointerViewModel> > GetPointers(RequestViewModel request)
        {
            var pointerViewModels = new List <PointerViewModel>();

            var pointerRequest = NrlsPointerRequest.Search(request.OrgCode, request.Id, null, request.Asid, null);

            var pointerResponse = await _docRefService.GetPointersBundle(pointerRequest);

            if (pointerResponse.ResourceType.Equals(ResourceType.OperationOutcome))
            {
                throw new HttpFhirException("Invalid Fhir Request", (OperationOutcome)pointerResponse, null);
            }

            var pointerBundle = pointerResponse as Bundle;

            //need a more slick solution for getting related references
            //we are connecting to NRLS so will only get Pointers back - a complete Fhir server would allow for includes
            var patients = await _patientService.GetPatients();                 //In live this could be lots

            var organisations = await _organisationServices.GetOrganisations(); //In live this could be lots

            var pointers = ListEntries <DocumentReference>(pointerBundle.Entry, ResourceType.DocumentReference);

            //var patients = ListEntries<Patient>(entries, ResourceType.Patient); // If we could do includes take from bundle
            //var organisations = ListEntries<Organization>(entries, ResourceType.Organization); // If we could do includes take from bundle

            foreach (var pointer in pointers)
            {
                var pointerViewModel = pointer.ToViewModel(DefaultUrlBase, PointerUrlBase);
                var patientNhsNumber = pointerViewModel.Subject?.Reference?.Replace(FhirConstants.SystemPDS, "");
                var authorOrgCode    = pointerViewModel.Author?.Reference?.Replace(FhirConstants.SystemODS, "");
                var custodianOrgCode = pointerViewModel.Custodian?.Reference?.Replace(FhirConstants.SystemODS, "");

                //This assumes the resource is relative
                //In reality it does not make sense to attach a patient because a GET to NRLS should be in the patient context anyway!
                var subject = patients.FirstOrDefault(s => s.Identifier.FirstOrDefault(t => !string.IsNullOrEmpty(patientNhsNumber) && !string.IsNullOrEmpty(t.System) && t.System.Equals(FhirConstants.SystemNhsNumber) && !string.IsNullOrEmpty(t.Value) && t.Value.Equals(patientNhsNumber)) != null);
                pointerViewModel.SubjectViewModel = subject?.ToViewModel(null);

                //This assumes the resource is relative
                var custodian = organisations.FirstOrDefault(s => s.Identifier.FirstOrDefault(t => !string.IsNullOrEmpty(custodianOrgCode) && !string.IsNullOrEmpty(t.System) && t.System.Equals(FhirConstants.SystemOrgCode) && !string.IsNullOrEmpty(t.Value) && t.Value.Equals(custodianOrgCode)) != null);
                pointerViewModel.CustodianViewModel = custodian?.ToViewModel(FhirConstants.SystemOrgCode);

                var author = organisations.FirstOrDefault(s => s.Identifier.FirstOrDefault(t => !string.IsNullOrEmpty(authorOrgCode) && !string.IsNullOrEmpty(t.System) && t.System.Equals(FhirConstants.SystemOrgCode) && !string.IsNullOrEmpty(t.Value) && t.Value.Equals(authorOrgCode)) != null);
                pointerViewModel.AuthorViewModel = author?.ToViewModel(FhirConstants.SystemOrgCode);

                pointerViewModels.Add(pointerViewModel);
            }

            if (pointers.Any())
            {
                CachePointers(request.Id, pointerViewModels);
            }

            return(pointerViewModels);
        }
        public async SystemTasks.Task <IEnumerable <PatientNumberViewModel> > GetPatientNumbers()
        {
            var patients = await _patientService.GetPatients();

            var patientNumbers = new List <PatientNumberViewModel>();

            patients.ForEach(p => {
                var nhsNumber = p.Identifier.FirstOrDefault(i => i.System.Equals(FhirConstants.IdsNhsNumber));

                var patientNumber = new PatientNumberViewModel
                {
                    Id        = p.Id,
                    NhsNumber = nhsNumber?.Value
                };

                patientNumbers.Add(patientNumber);
            });

            return(await SystemTasks.Task.Run(() => patientNumbers));
        }