public ActionResult OnGet([FromRoute] long id) { Study = Studies.GetStudy(id); if (Study == null) { return(NotFound()); } var studyIdentity = Study.Id; var consentedSubjects = Subjects.GetConsentedSubjects(studyIdentity); Logger.LogDebug( "Found {count} consentedPeople - {consentedPeopleIds}", consentedSubjects.Length, consentedSubjects); if (!Search) { SearchGroups = GetDefinedSearchGroups(); return(Page()); } var mergedSearchGroups = GetSearchGroupsAndValues(); SearchGroups = mergedSearchGroups; return(DoSearch()); }
/// <inheritdoc /> public WhenRecordingConsent_ForANonExistantStudy() { var nonExistentStudyId = -Study.Id; A.CallTo(() => Studies.GetStudy(nonExistentStudyId)).Returns(null); RecordConsent(A.Dummy <IIdentifierValueDto>(), A.Dummy <DateTime>(), studyId: nonExistentStudyId); }
private (StudyIdentity studyIdentity, IActionResult actionResult) GetStudy(long studyId) { var study = Studies.GetStudy(studyId); if (study != null) { return(study.Id, null); } Logger.LogWarning("Study#{studyId} not found", studyId); return(study.Id, NotFound()); }
public IActionResult PutConsent([FromBody] ConsentSpecification specification) { if (!ModelState.IsValid) { Logger.LogInformation("Invalid ModelState {@error}", new SerializableError(ModelState)); return(new BadRequestObjectResult(ModelState)); } var study = Studies.GetStudy(specification.StudyId); if (study == null) { Logger.LogWarning("Study#{studyId} not found", specification.StudyId); return(NotFound()); } var studySubject = Subjects.GetStudySubject(study.Id, specification.SubjectIdentifier); if (studySubject == null) { var subjectSpecification = new { specification.StudyId, specification.PersonId }; Logger.LogDebug("No existing studySubject - creating a new subject for {spec}", subjectSpecification); var personId = new PersonIdentity(specification.PersonId); studySubject = Subjects.FindStudySubject(study.Id, personId); if (studySubject != null) { Logger.LogError("There is already a study subject for {spec} - {identifier}", subjectSpecification, studySubject.SubjectIdentifier); return(BadRequest()); } studySubject = new StudySubject(study.Id, specification.SubjectIdentifier, personId); studySubject = Subjects.AddStudySubject(studySubject); } else { var existingConsent = Consents.FindActiveConsent(studySubject); if (existingConsent != null) { //TODO: Decide what to do with evidence, etc, for existing consents, or if you can be consented twice return(new SeeOtherOjectActionResult( "GetStudySubject", routeValues: new { studyId = study, subjectIdentifier = studySubject.SubjectIdentifier }, result: existingConsent.Id)); } } var evidence = EvidenceDtoMarshallers.ConvertToIdentifiers(specification.Evidence); var newConsentId = Consents.AddConsent( new Common.Consent.Consent( studySubject, specification.DateGiven, specification.GivenBy, evidence)); return(CreatedAtAction( "GetStudySubject", new { studyId = study, subjectIdentifier = studySubject.SubjectIdentifier }, newConsentId.Id)); }