protected async Task OnExecuteAsync() { var api = await apiClientProvider.CreateApiClient(); var subjects = await api.GetSubjectsForStudyAsync(StudyId); using (var writer = new CsvWriter( new StreamWriter(File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write), Encoding.UTF8))) { writer.WriteRecords(subjects.Select(_ => new { SubjectId = _.SubjectIdentifier, _.LastWithdrawalDate })); } }
public async Task Import(string source) { var client = await ApiClientProvider.CreateApiClient(); var identifierDefinitions = client.GetIdentityStoreMetadata(); Log.Debug("Available Identifiers Are {@identifiers}", identifierDefinitions); var evidenceDefinitions = client.GetConsentStoreMetadata(); Log.Debug("Available Evidences Are {@evidences}", evidenceDefinitions); var xmlParser = new XmlParser(identifierDefinitions, evidenceDefinitions); using (LogContext.PushProperty("PeopleSource", source)) using (var xmlReader = XmlReader.Create(source)) { foreach (var person in xmlParser.GetPeople(xmlReader)) { Log.Verbose("Processing {@person}", person); var api = await ApiClientProvider.CreateApiClient(); var personId = api.PutPerson(person.PersonSpecification); //TODO: handle null personId - why would this happen? Log.Debug("Person Id is {@personId}", personId); using (LogContext.PushProperty("PersonId", personId.PersonId)) { if (!person.ConsentSpecifications.Any()) { Log.Debug("No consents provided"); continue; } foreach (var consent in person.ConsentSpecifications) { using (LogContext.PushProperty("StudyId", consent.StudyId)) { RecordConsent(api, consent, personId.PersonId); } } } } } }