/** Notifies the backend service of a potential Covid-19 infection. */ public static async Task <HttpResponseMessage> Notify( DateTime symptomsOnset, bool isTested, string comment) { // Generates the daily tracer keys that have been or will be used // during the infectious period, based on the symptoms onset. // // Use median incubation and virus positive periods according to // <https://www.atsjournals.org/doi/pdf/10.1164/rccm.202003-0524LE> var keys = new List <Tuple <Date, DailyTracerKey> >(); { const int INCUBATION_PERIOD = 5; const int SYMPTOMS_TO_VIRUS_NEGATIVE = 11; var begin = symptomsOnset.AddDays(-INCUBATION_PERIOD); var end = symptomsOnset.AddDays(SYMPTOMS_TO_VIRUS_NEGATIVE); var masterKey = TracerKey.CurrentAppInstance(); for (var dt = begin; dt < end; dt = dt.AddDays(1)) { var date = new Date(dt); var key = masterKey.DerivateDailyKey(date); keys.Add(Tuple.Create(date, key)); } } // Constructs and submit the POST request. // // Keys are encoded as a repeated HTTP field. var queryParams = new List <KeyValuePair <String, String> > { new KeyValuePair <string, string>( "is_tested", isTested ? "true" : "false" ), new KeyValuePair <string, string>("comment", comment), }; for (int i = 0; i < keys.Count; ++i) { queryParams.Add(new KeyValuePair <string, string>( $"keys-{i}-date", keys[i].Item1.ToString() )); queryParams.Add(new KeyValuePair <string, string>( $"keys-{i}-value", keys[i].Item2.ToString() )); } var content = new FormUrlEncodedContent(queryParams.ToArray()); return(await Client.PostAsync($"{ROOT}/notify", content)); }
public TracerService(IBLEServer server_) { Key = TracerKey.CurrentAppInstance(); Contacts = new ContactDatabase(); server = server_; Logger.Info( $"TracerService instanced with key " + $"'{Key.ToHumanReadableString()}'"); }