private async void GlucoseServiceHandler_MeasurementNotification(GlucoseMeasurementValue measurement) { await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var value = new GlucoseMeasurementValueWrapper(measurement); this.glucoseMeasurementList.Add(value); }); }
public GlucoseMeasurementValueWrapper(GlucoseMeasurementValue measurement) { this.Measurement = measurement; this.timeOffSet = this.Measurement.TimeOffset.ToString(); this.sequenceNumber = this.Measurement.SequenceNumber.ToString(); this.baseTime = this.Measurement.BaseTime.ToString(); this.location = this.Measurement.Location.ToString(); this.type = this.Measurement.Type.ToString(); this.glucoseConcentrationKgL = this.Measurement.GlucoseConcentrationKgL.ToString(); this.glucoseConcentrationMolL = this.Measurement.GlucoseConcentrationMolL.ToString(); }
public async Task CreateAndUploadMeasurementAsFhir() { // For the sake of simplicity the measurement is created directly rather than read via bluetooth var measurement = new GlucoseMeasurementValue { GlucoseConcentrationMolL = 5.4f, BaseTime = DateTime.UtcNow }; // The measurement can then be converted to a FHIR resource by following a simple factory pattern, that fills a blueprint with values var observation = ObservationFactory.FromMeasurement(measurement); // This FHIR resource now can be uploaded to the tangle var interactor = new CreateResourceInteractor(new IotaFhirRepository(Repository, new FhirJsonTryteSerializer(), new InMemoryResourceTracker())); // The result includes all necessary data to read the FHIR resource from e.g. an FHIR API var result = await interactor.ExecuteAsync(new CreateResourceRequest { Resource = observation }); }
public static Observation FromMeasurement(GlucoseMeasurementValue measurement) { var observation = new Observation { Identifier = new List <Identifier> { new Identifier { System = "http://www.bmc.nl/zorgportal/identifiers/observations", Value = "6323", Use = Identifier.IdentifierUse.Official } }, Status = ObservationStatus.Final, Code = new CodeableConcept { Coding = new List <Coding> { new Coding { System = "http://loinc.org", Code = "15074-8", Display = "Glucose [Moles/volume] in Blood" } } }, Issued = DateTimeOffset.UtcNow, Value = new SimpleQuantity { Value = (decimal)measurement.GlucoseConcentrationMolL, Unit = "mmol/l", System = "http://unitsofmeasure.org", Code = "mmol/l" } }; if (measurement.BaseTime != null) { observation.Effective = new Period { StartElement = new FhirDateTime(new DateTimeOffset(measurement.BaseTime.Value)) }; } return(observation); }
public async Task RunAsync(int rounds) { var repository = new RestIotaRepository( new FallbackIotaClient( new List <string> { "https://nodes.thetangle.org:443", "http://node04.iotatoken.nl:14265", "http://node05.iotatoken.nl:16265", "https://nodes.thetangle.org:443", "http://iota1.heidger.eu:14265", "https://nodes.iota.cafe:443", "https://potato.iotasalad.org:14265", "https://durian.iotasalad.org:14265", "https://turnip.iotasalad.org:14265", "https://nodes.iota.fm:443", "https://tuna.iotasalad.org:14265", "https://iotanode2.jlld.at:443", "https://node.iota.moe:443", "https://wallet1.iota.town:443", "https://wallet2.iota.town:443", "http://node03.iotatoken.nl:15265", "https://node.iota-tangle.io:14265", "https://pow4.iota.community:443", "https://dyn.tangle-nodes.com:443", "https://pow5.iota.community:443", }, 5000), new PoWSrvService()); var fhirRepository = new IotaFhirRepository(repository, new FhirJsonTryteSerializer(), new InMemoryResourceTracker()); var resourceInteractor = new CreateResourceInteractor(fhirRepository); var readInteractor = new ReadResourceInteractor(fhirRepository); var measurement = new GlucoseMeasurementValue { GlucoseConcentrationMolL = 5.4f, BaseTime = DateTime.UtcNow }; var resourceId = string.Empty; var n = 0; while (n < rounds) { n++; this.Tracker.Update(n); // The example sends an observation. Nevertheless it does not make a difference from a technical perspective // what resource is sent, as long as its size fits one IOTA transaction var response = await resourceInteractor.ExecuteAsync(new CreateResourceRequest { Resource = ObservationFactory.FromMeasurement(measurement) }); if (string.IsNullOrEmpty(resourceId)) { resourceId = response.LogicalId; } } foreach (var trackingEntry in fhirRepository.ResultTimes) { this.Logger.Log($"Create: {trackingEntry.CreateTime:0000} | Attach: {trackingEntry.AttachTime:0000}"); } await readInteractor.ExecuteAsync(new ReadResourceRequest { ResourceId = resourceId }); foreach (var readEntry in fhirRepository.ReadTimes) { this.Logger.Log($"Read: {readEntry.ReadTime:0000}"); } }