Beispiel #1
0
        public string CreateHl7FHIRBMPObservation(BPMCompleteSequence seqtocreate) //Signature may be changed
        {
            var saveobs = makeABPMObservation(seqtocreate);

            saveobs = client.Create(saveobs);
            return(saveobs.Id);
        }
Beispiel #2
0
        private Observation makeABPMObservation(BPMCompleteSequence seqtomake)
        {
            // Link https://stackoverflow.com/questions/311165/how-do-you-convert-a-byte-array-to-a-hexadecimal-string-and-vice-versa

            string rawdata = new string("");

            foreach (var sample in seqtomake.SequenceOfBPMSamples)
            {
                rawdata += ByteArrayToString(sample.BPMSamples);
            }

            var eob = new Observation();

            eob.Id     = seqtomake.NameOfObject; //"EKG-odjvbhofdjghodfgofg"; //JRT Be careful when
            eob.Status = ObservationStatus.Final;
            eob.Category.Add(new CodeableConcept()
            {
                Coding = new List <Coding>()
            });
            eob.Category[0].Coding.Add(new Coding()
            {
                Code = "BPM Measurement", System = "http://terminology.hl7.org/CodeSystem/observation-category", Display = "Procedure"
            });
            eob.Code = new CodeableConcept();
            eob.Code.Coding.Add(new Coding()
            {
                System = "urn:oid:1.2.3.4.5.6", Code = "AUH131328", Display = "MDC_BPM_Phys_Sequence"
            });
            eob.Subject           = new ResourceReference();
            eob.Subject.Reference = "AU-ECE-ST-E20";
            eob.Subject.Display   = "E20ST3PRJ3-NVK";

            //eob.Effective = new FhirDateTime("2015-02-19T09:30:35+01:00");
            //eob.Effective = new FhirDateTime(DateTime.Now);
            //For DateTime and DataTimeOffset se link https://docs.microsoft.com/en-us/dotnet/standard/datetime/converting-between-datetime-and-offset
            DateTimeOffset dtoff = DateTime.SpecifyKind(seqtomake.StartTime, DateTimeKind.Utc);

            eob.Effective = new FhirDateTime(dtoff); //JRT
            eob.Performer.Add(new ResourceReference()
            {
                Reference = "Student/E20", Display = "Students from E20STS3NVK"
            });
            eob.Device         = new ResourceReference();
            eob.Device.Display = "1 Transducer Device mmHG Metric";
            var m = new Observation.ComponentComponent();

            m.Code = new CodeableConcept();
            m.Code.Coding.Add(new Coding()
            {
                System = "urn:oid:1.2.3.4.5.6", Code = "AUH131328", Display = "MDC_BPM_Phys_Sequence_1"
            });
            m.Value = new SampledData()
            {
                Origin = new SimpleQuantity {
                    Value = 2048
                },                           //??
                Period     = 3600,           //??
                Factor     = (decimal)1.612, //??
                LowerLimit = -3300,          //??
                UpperLimit = 3300,           //??
                Dimensions = 1,
                Data       = rawdata,
            };
            eob.Component.Add(m);//Add the new data block to Observation

            //But then how to access the justed  in line 89  added SampleData Object again??
            //Well remark that Observation.ComponentComponent.Value attribute is an Element class Just place cursor over m.Value
            //Then important to notice is that SampleData class inherits the Element class! Why do you think this is the case?
            //Now a type cast is needed to acces Value as a SampleData Class just as showen in next line
            var    x = (SampledData)eob.Component[0].Value;
            string d = x.Data;

            //Lesson learned: As JSON does not cares about specific object types, class definitions does not exist in JSON. In C# we do
            //need to make polymorph classes shaping more than one class. Element class shapes all needed HL7 FHIR classes in Component,
            //SampleData shapes only one specific class but can be carried in an Element class


            return(eob);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Test of HL7FHIR!");

            //Step 1 Get acces to a local SQLite database
            using (var localdbcache = new LocalCacheDBContext())
            {
                localdbcache.Database.Migrate(); //Ensures the database is created and if needed updated with pending migrations
            }

            //Step 2 simulation af  a time limited session with collection of BPMs
            //In this template we are using a 1:Many association between the BMPCompleteSequence (root) and the BMPLocalSampleSequence (child).
            //Use your own classes here
            //Here next, each step simualed covers 1 second with 50 sample values
            using (var localdbcache = new LocalCacheDBContext())
            {
                var completeseq = new BPMCompleteSequence()
                {
                    NameOfObject = "231145-2341", StartTime = DateTime.Now, BPMCounts = 3600, DurationInSeconds = 3600
                };
                localdbcache.Add(completeseq);                  //Add the root object to db context
                localdbcache.SaveChanges();                     //Save root to database
                //Start receiving sample sequence from RPI, here the data is generated
                for (var step = 0; step < 100 /*3600*/; step++) //Simulation 1 hour in steps of second, though here truncated to 100 steps for spedding up test
                {
                    var samples = new BPMLocalSampleSequence()
                    {
                        NoBPMValues = 50, SequenceNo = step
                    };
                    float[] data = new float[50];
                    for (var sampleno = 0; sampleno < 50; sampleno++)//Generating values
                    {
                        data[sampleno] = sampleno / 100F;
                    }
                    //https://stackoverflow.com/questions/4635769/how-do-i-convert-an-array-of-floats-to-a-byte-and-back
                    var rawdata = new byte[data.Length * 4];                //Four bytes per float
                    Buffer.BlockCopy(data, 0, rawdata, 0, data.Length * 4); //Make floats a BLOB
                    //Third param in BlockCopy is number of bytes to copy, that's the reason to data.length *4 !
                    samples.BPMSamples = rawdata;                           //Add data to child object
                    completeseq.SequenceOfBPMSamples.Add(samples);          //Add child object to root object
                    //localdbcache.Add(samples); //Add child object to db context
                    localdbcache.SaveChanges();                             //Save current child to database with FK to root
                }

                //Step 3 when session is ended save all collected BPMs in one HL7FHIR Obersevation in the public HL7FHIR database
                //But first retrieve complete sequence from local cache (!!!! not using the other instance completeseq)

                var retId        = completeseq.BPMCompleteSequenceId;
                var retrievedseq = localdbcache.BPMCompleteSequences.
                                   Where(i => i.BPMCompleteSequenceId.Equals(retId)).
                                   Include(c => c.SequenceOfBPMSamples).Single();
                //.ToListAsync();

                //Then save sequence at
                var hl7fhirclient = new HL7FHIRR4BPMClient();
                var returnedid    = hl7fhirclient.CreateHl7FHIRBMPObservation(retrievedseq);


                //Step 4 Get a specfic Obesrvation from the public HL7FHIR database
                //And convert the BPM data to useable datatypes
                //"777886f0-3b63-43e4-9c61-4d8b8210a2c4"
                hl7fhirclient.ReadHL7FHIRVBPMObservation(returnedid);

                //Step 5 optional updates and deletes
            }
        }