Пример #1
0
 /// <inheritdoc />
 public IEnumerable <Common.Consent.Consent> GetConsentsForSubject(StudyIdentity studyIdentity, string subjectIdentifier)
 {
     return
         (from c in (
              from c in ConsentsFor(studyIdentity, subjectIdentifier)
              .Include(_ => _.GivenEvidence).Include(_ => _.WithdrawnEvidence)
              orderby c.DateProvided descending
              let subject = c.StudySubject
                            let person = subject.Person
                                         select new
     {
         StudySubject = new StudySubject(studyIdentity, subjectIdentifier,
                                         new PersonIdentity(person.Id)),
         c.DateProvided,
         c.DateWithdrawn,
         GivenById = (long?)c.GivenBy.Id,
         GivenEvidence = c.GivenEvidence.ToArray(),
         WithdrawnEvidence = c.WithdrawnEvidence.ToArray()
     }
              ).ToArray()
          select new Common.Consent.Consent(
              c.StudySubject,
              c.DateProvided,
              c.GivenById,
              c.GivenEvidence?.AsQueryable().Select(MarshallEvidenceFromEntity()))
     {
         DateWithdrawn = c.DateWithdrawn,
         WithdrawnEvidence = c.WithdrawnEvidence?.AsQueryable().Select(MarshallEvidenceFromEntity())
     });
 }
Пример #2
0
 /// <inheritdoc />
 public ConsentControllerTestBase()
 {
     Study         = Create.Study;
     StudyId       = new StudyIdentity(Study.Id);
     StudySubject  = new StudySubject(StudyId, "AA100023", new PersonIdentity(500L));
     Studies       = CreateStudyRepository(Study);
     StudySubjects = CreateSubjectRepository(Study, StudySubject);
     Consents      = CreateConsentRepository(Study, StudySubject);
 }
        /// <inheritdoc />
        public string GenerateIdentifier(StudyIdentity studyIdentity)
        {
            var current = SubjectIdentifiers.SingleOrDefault(_ => _.StudyId == studyIdentity.Id);

            if (current == null)
            {
                if (!Studies.Any(_ => _.Id == studyIdentity.Id))
                {
                    throw new InvalidOperationException($"No study found for {studyIdentity}");
                }

                current = SubjectIdentifiers.Add(new SubjectIdentifierEntity {
                    StudyId = studyIdentity
                });
            }

            var id = current.CurrentValue += 1;

            return($"{id:x16}");
        }
Пример #4
0
 StudySubject IStudySubjectRepository.FindStudySubject(StudyIdentity study, PersonIdentity personId)
 {
     return(GetStudySubject(FindStudySubjectForPerson(study, personId)));
 }
Пример #5
0
 StudySubject IStudySubjectRepository.GetStudySubject(StudyIdentity study, string subjectIdentifier) =>
 GetStudySubject(SubjectsForStudy(study).Where(_ => _.SubjectIdentifier == subjectIdentifier));
Пример #6
0
 /// <inheritdoc />
 public Study GetStudy(StudyIdentity studyId) =>
 context.Studies
 .Where(_ => _.Id == studyId.Id)
 .Select(_ => new Study(new StudyIdentity(_.Id), _.Name))
 .SingleOrDefault();
Пример #7
0
 /// <inheritdoc />
 public ConsentedPersonSpecification(StudyIdentity studyId)
 {
     StudyId = studyId;
 }
Пример #8
0
 /// <inheritdoc />
 public Study(long id, string name = null) : this(name)
 {
     Id = new StudyIdentity(id);
 }
Пример #9
0
        /// <inheritdoc />
        public ConsentRepositoryTests(ITestOutputHelper outputHelper, DatabaseFixture fixture) : base(outputHelper, fixture)
        {
            readContext   = CreateNewContextInSameTransaction();
            updateContext = CreateNewContextInSameTransaction();
            createContext = CreateNewContextInSameTransaction();


            study = createContext.Studies.Add(new StudyEntity {
                Name = Random.String()
            }).Entity;

            var consentedPerson = createContext.People.Add(new PersonEntity()).Entity;

            consentedStudySubject = createContext.Add(new StudySubjectEntity {
                Study = study, Person = consentedPerson, SubjectIdentifier = "Consented"
            }).Entity;
            createContext.Add(
                new ConsentEntity
            {
                StudySubject  = consentedStudySubject,
                DateProvided  = 1.December(1965),
                DateWithdrawn = 1.January(1966),
                GivenBy       = consentedPerson
            });

            activeConsent = createContext.Add(
                new ConsentEntity
            {
                StudySubject = consentedStudySubject,
                DateProvided = 1.February(1966),
                GivenBy      = consentedPerson
            }).Entity;

            var unconsentedPerson = createContext.People.Add(new PersonEntity()).Entity;

            createContext.Add(
                new StudySubjectEntity {
                Study = study, Person = unconsentedPerson, SubjectIdentifier = "Unconsented"
            });

            var withdrawnConsent = createContext.Add(new PersonEntity()).Entity;
            var withdrawnSubject = createContext.Add(
                new StudySubjectEntity {
                Study = study, Person = withdrawnConsent, SubjectIdentifier = "Withdrawn"
            }).Entity;

            withdrawnSubjectWithdrawnDate = 5.January(2018);
            createContext.Add(new ConsentEntity
            {
                StudySubject  = withdrawnSubject,
                DateProvided  = 1.December(2017),
                DateWithdrawn = withdrawnSubjectWithdrawnDate,
                GivenBy       = withdrawnConsent
            });


            createContext.SaveChanges();

            studyId             = new StudyIdentity(study.Id);
            consentedPersonId   = consentedPerson;
            unconsentedPersonId = unconsentedPerson;
            withdrawnPersonId   = withdrawnConsent;

            consents = CreateConsentRepository(readContext);

            studySubjects = CreateStudySubjectRepository(readContext);
            studies       = CreateStudyRepository(readContext);
        }