Example #1
0
        public void t_PointCountLess50_Select_ByGuid()
        {
            Observation_ado setupObject = null;
            // backdoor data setup
            Guid pointSurveyId = TestHelper.TestGuid3;

            DbTestHelper.LoadSinglePointSurvey(pointSurveyId, TestHelper.TestGuid2, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                setupObject = new Observation_ado()
                {
                    Comments          = "asdfasdf asdf adsfa dsfads fasdf adsfasd fadsf awefr34fr34r34 ",
                    SpeciesId         = new Guid(TestHelper.SPECIES_1_ID),
                    EventId           = pointSurveyId,
                    ObservationTypeId = _PointCountLess50TypeId
                };
                iba.AddToObservation_ado(setupObject);
            });
            DbTestHelper.LoadExtraneousObservations(TestHelper.TestGuid3);

            // Exercise the test
            PointCountWithin50 PointCountLess50 = ObservationMapper.Select <PointCountWithin50>(setupObject.ObservationId);

            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                validateObjectEquality(PointCountLess50, setupObject, iba);
            }
        }
Example #2
0
        public void t_PointCountLess50_Select_ByEventId()
        {
            Guid pointSurveyId = TestHelper.TestGuid2;

            DbTestHelper.LoadSinglePointSurvey(pointSurveyId, TestHelper.TestGuid2, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));
            Observation_ado setupObject = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                setupObject = new Observation_ado()
                {
                    Comments          = "asdfasdf asdf adsfa dsfads fasdf adsfasd fadsf awefr34fr34r34 ",
                    SpeciesId         = new Guid(TestHelper.SPECIES_1_ID),
                    EventId           = pointSurveyId,
                    ObservationTypeId = _PointCountLess50TypeId
                };
                iba.AddToObservation_ado(setupObject);
            });
            DbTestHelper.LoadExtraneousObservations(TestHelper.TestGuid3);

            // Exercise the test
            List <PointCountWithin50> selectList = ObservationMapper.SelectAllForEvent <PointCountWithin50>(setupObject.EventId);

            Assert.AreEqual(1, selectList.Count(), "Does not contain just one object");
            PointCountWithin50 result = selectList[0];

            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                validateObjectEquality(result, setupObject, iba);
            }
        }
Example #3
0
        public void t_PointCountLess50_Delete()
        {
            Observation_ado setupObject = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                setupObject = new Observation_ado()
                {
                    Comments          = "asdfasdf asdf adsfa dsfads fasdf adsfasd fadsf awefr34fr34r34 ",
                    SpeciesId         = new Guid(TestHelper.SPECIES_1_ID),
                    EventId           = TestHelper.TestGuid1,
                    ObservationTypeId = _PointCountLess50TypeId
                };
                iba.AddToObservation_ado(setupObject);
            });
            List <Observation_ado> Observationlist = DbTestHelper.LoadExtraneousObservations(TestHelper.TestGuid3);

            ObservationMapper.Delete(new PointCountWithin50()
            {
                Id = setupObject.ObservationId
            });

            // Validate results
            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var PointCountLess50Query = from PointCountLess50s in iba.Observation_ado
                                            select PointCountLess50s;
                Assert.IsNotNull(PointCountLess50Query, "Query result is null");
                Assert.AreEqual(Observationlist.Count(), PointCountLess50Query.Count(), "Wrong number of results in query");
                validateExtraObservations(Observationlist, PointCountLess50Query);
            }
        }
 private void fakeDataSaveObservations(FiftyMeterPointSurvey survey)
 {
     foreach (FiftyMeterPointObservation observation in survey.Observations)
     {
         ObservationMapper.Insert(observation);
     }
 }
        public void t_PointCountBeyond50_DeleteTopX()
        {
            Guid   eventId            = TestHelper.TestGuid1;
            Guid   speciesId          = new Guid(TestHelper.SPECIES_2_ID);
            string speciesCode        = TestHelper.SPECIES_2_CODE;
            Guid   observationTypeId1 = LookupConstants.ObservationTypePointLess50m;
            Guid   observationTypeId2 = LookupConstants.ObservationTypeSupplemental;

            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                Observation_ado obs1 = Observation_ado.CreateObservation_ado(0, eventId, speciesId, observationTypeId1);
                iba.AddToObservation_ado(obs1);
                Observation_ado ob2 = Observation_ado.CreateObservation_ado(0, eventId, speciesId, observationTypeId1);
                iba.AddToObservation_ado(ob2);
                Observation_ado obs3 = Observation_ado.CreateObservation_ado(0, eventId, speciesId, observationTypeId1);
                iba.AddToObservation_ado(obs3);
                Observation_ado obs4 = Observation_ado.CreateObservation_ado(0, eventId, speciesId, observationTypeId2);
                iba.AddToObservation_ado(obs4);
            });

            ObservationMapper.DeleteTopX(eventId, observationTypeId1, speciesCode, 2);

            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var observationQuery = from observations in iba.Observation_ado select observations;
                Assert.IsNotNull(observationQuery, "observationQuery is null");
                Assert.AreEqual(2, observationQuery.Count(), "observationQuery has wrong count");
                Assert.AreEqual(1, observationQuery.Count(x => x.ObservationTypeId.Equals(observationTypeId1)), "wrong count for type 1");
                Assert.AreEqual(1, observationQuery.Count(x => x.ObservationTypeId.Equals(observationTypeId2)), "wrong count for type 2");
            }
        }
Example #6
0
        public void Update(SupplementalObservation observation)
        {
            observation.SpeciesCode = observation.SpeciesCode.ToUpper();
            ObservationMapper.Update(observation);

            _state.SiteVisit.SupplementalObservations.RemoveAll(x => x.Id.Equals(observation.Id));
            _state.SiteVisit.SupplementalObservations.Add(observation);
        }
 public iNaturalistMapperFactory()
 {
     CommentMapper = new CommentMapper();
     PhotoMapper = new PhotoMapper();
     TaxonMapper = new TaxonMapper(PhotoMapper);
     IdentificationMapper = new IdentificationMapper(TaxonMapper);
     UserMapper = new UserMapper();
     ObservationMapper = new ObservationMapper(CommentMapper, IdentificationMapper,
         PhotoMapper, TaxonMapper, UserMapper);
 }
Example #8
0
 public List <SupplementalObservation> SelectAllForEvent(Guid eventId)
 {
     if (_state.SiteVisit.Id.Equals(eventId))
     {
         return(_state.SiteVisit.SupplementalObservations);
     }
     else
     {
         return(ObservationMapper.SelectAllForEvent <SupplementalObservation>(eventId));
     }
 }
Example #9
0
    protected void RetrieveIncomplete_Click(object sender, EventArgs e)
    {
        if (this.SiteVisitedInput.SelectedIndex > -1 && !string.IsNullOrEmpty(this.VisitDateInput.Text))
        {
            List <SiteVisit> visitList = SiteVisitMapper.SelectAllForSite(Guid.Parse(this.SiteVisitedInput.SelectedValue));
            SiteVisit        theVisit  = visitList.Find(x => !x.IsDataEntryComplete
                                                        &&
                                                        x.StartTimeStamp.Value.ToShortDateString()
                                                        .Equals(
                                                            DateTime.Parse(this.VisitDateInput.Text).ToShortDateString()));
            if (theVisit != null)
            {
                resetSession();

                this.UserState.SiteVisit = theVisit;
                this.UserState.SiteVisit.SupplementalObservations.AddRange(
                    SupplementalObservationMapper.SelectAllForEvent(theVisit.Id));
                this.UserState.SiteVisit.PointSurveys.AddRange(PointSurveyMapper.SelectAllForSiteVisit(theVisit.Id));
                this.UserState.SiteVisit.PointSurveys.ForEach(x =>
                {
                    x.Observations.AddRange(ObservationMapper.SelectAllForEvent <PointCountBeyond50>(x.Id));
                    x.Observations.AddRange(ObservationMapper.SelectAllForEvent <PointCountWithin50>(x.Id));
                });
                List <SiteCondition> conditions = ConditionsMapper.Select_BySiteVisitId(theVisit.Id);
                if (conditions != null && conditions.Count.Equals(2))
                {
                    this.UserState.SiteVisit.StartConditions =
                        conditions.Single(x => x.Id.Equals(this.UserState.SiteVisit.StartConditions.Id));
                    this.UserState.SiteVisit.EndConditions =
                        conditions.Single(x => x.Id.Equals(this.UserState.SiteVisit.EndConditions.Id));
                }

                loadCurrentSiteVisit();
            }
            else
            {
                Master.SetErrorMessage(
                    "<p>No <i>incomplete</i> site visit entry has been started for this site and date.</p>");
            }
        }
        else
        {
            Master.SetErrorMessage(
                "<p>Both site and date must be filled in to retrieve an incomplete site visit.</p>");
        }
    }
        public HttpResponseMessage Create(Hl7.Fhir.Model.Observation fhirObservation)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Observation observation = ObservationMapper.MapResource(fhirObservation);

            observation = (Observation)ControllerUtils.AddMetadata(observation, ControllerUtils.CREATE);

            db.Observations.Add(observation);
            db.SaveChanges();

            message.Content          = new StringContent("Observation created!", Encoding.UTF8, "text/html");
            message.StatusCode       = HttpStatusCode.Created;
            message.Headers.Location = new Uri(Url.Link("SpecificObservation", new { id = observation.ObservationId }));

            return(message);
        }
Example #11
0
        public void t_PointCountLess50_Save_Update()
        {
            //loadSiteVisit(TestHelper.TestGuid1);
            Observation_ado setupObject = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                setupObject = new Observation_ado()
                {
                    Comments          = "asdfasdf asdf adsfa dsfads fasdf adsfasd fadsf awefr34fr34r34 ",
                    SpeciesId         = new Guid(TestHelper.SPECIES_1_ID),
                    EventId           = TestHelper.TestGuid1,
                    ObservationTypeId = _PointCountLess50TypeId
                };
                iba.AddToObservation_ado(setupObject);
            });
            List <Observation_ado> extraList = DbTestHelper.LoadExtraneousObservations(TestHelper.TestGuid3);

            // Setup object to be saved. Change everything except the Id.
            PointCountWithin50 testObject = new PointCountWithin50()
            {
                Comments    = "hurdy gurdy",
                SpeciesCode = TestHelper.SPECIES_2_CODE,
                EventId     = setupObject.EventId,
                Id          = setupObject.ObservationId
            };

            // Execute the test
            ObservationMapper.Update(testObject);

            // Validate results
            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var PointCountLess50Query = from PointCountLess50s in iba.Observation_ado select PointCountLess50s;
                Assert.IsNotNull(PointCountLess50Query, "Query result is null");
                Assert.AreEqual(extraList.Count() + 1, PointCountLess50Query.Count(), "Wrong number of results in query");

                Observation_ado adoPointCountLess50 = PointCountLess50Query.First(x => x.ObservationId == setupObject.ObservationId);
                validateObjectEquality(testObject, adoPointCountLess50, iba);

                validateExtraObservations(extraList, PointCountLess50Query);
            }
        }
Example #12
0
        public void t_PointCountLess50_Select_All()
        {
            // Backdoor setup
            Guid pointSurveyId = TestHelper.TestGuid3;

            DbTestHelper.LoadSinglePointSurvey(pointSurveyId, TestHelper.TestGuid2, TestHelper.TestGuid1, DateTime.Now, DateTime.Now.AddHours(1));
            List <Observation_ado> list = DbTestHelper.LoadExtraneousObservations(pointSurveyId); List <Observation_ado> PointCountLess50AdoList = extraPointCountLess50s(list);

            // Exercise the test
            List <PointCountWithin50> PointCountLess50List = ObservationMapper.SelectAll <PointCountWithin50>();

            // Validate results
            Assert.AreEqual(PointCountLess50AdoList.Count(), PointCountLess50List.Count, "Wrong number of objects in the result list");
            foreach (Observation_ado ado in PointCountLess50AdoList)
            {
                // just check to make sure the object is there; leave specific value check for the Select_ByGuid test
                Assert.IsTrue(PointCountLess50List.Exists(x => x.Id.Equals(ado.ObservationId)), "Observation " + ado.ObservationId.ToString() + " is not in the results");
            }
        }
        public void ObservationMapTest()
        {
            // Arrange
            var mockCommentMapper = new Mock<IMapper<Comment>>().Object;
            var mockIdentificationMapper = new Mock<IMapper<Identification>>().Object;
            var mockPhotoMapper = new Mock<IMapper<Photo>>().Object;
            var mockTaxonMapper = new Mock<IMapper<Taxon>>().Object;
            var mockUserMapper = new Mock<IMapper<User>>().Object;
            var observationMapper = new ObservationMapper(mockCommentMapper, mockIdentificationMapper,
                mockPhotoMapper, mockTaxonMapper, mockUserMapper);

            dynamic obj = new JObject();
            obj.id = "101";
            obj.created_at = "2016-11-20T14:28:53.572+11:00";
            obj.observed_on = "2012-11-20T14:28:53.572+11:00";
            obj.description = "Pretty!";
            obj.latitude = "75";
            obj.longitude = "150";
            obj.community_taxon_id = "102";
            obj.observation_sounds_count = "10";
            obj.quality_grade = "research";

            var observation = new Observation();

            // Act
            observationMapper.Map(obj, observation);

            // Assert
            Assert.AreEqual(observation.Id, 101);
            Assert.AreEqual(observation.CreatedAt, Convert.ToDateTime("2016-11-20T14:28:53.572+11:00"));
            Assert.AreEqual(observation.ObservedOn, Convert.ToDateTime("2012-11-20T14:28:53.572+11:00"));
            Assert.AreEqual(observation.Description, "Pretty!");
            Assert.AreEqual(observation.Location.Latitude, 75);
            Assert.AreEqual(observation.Location.Longitude, 150);
            Assert.AreEqual(observation.CommunityTaxonId, 102);
            Assert.AreEqual(observation.SoundsCount, 10);
            Assert.AreEqual(observation.QualityGrade, "research");
            Assert.AreEqual(observation.Taxon, null);
            Assert.AreEqual(observation.User, null);
            Assert.AreEqual(observation.Photos.Count, 0);
            Assert.AreEqual(observation.Feedback.Count, 0);
        }
        public void Update(FiftyMeterDataEntry entry)
        {
            entry.SpeciesCode = entry.SpeciesCode.ToUpper();
            List <PointCountBeyond50> beyond50 = entry.GetListBeyond50();
            List <PointCountWithin50> within50 = entry.GetListWithin50();

            beyond50.FindAll(y => y.Id.Equals(0)).ForEach(x =>
            {
                ObservationMapper.Update(x);
                _state.PointSurvey.Observations.Add(x);
            });
            within50.FindAll(y => y.Id.Equals(0)).ForEach(x =>
            {
                ObservationMapper.Update(x);
                _state.PointSurvey.Observations.Add(x);
            });



            int deleteBeyond = _state.PointSurvey.Observations.OfType <PointCountBeyond50>().Where(x => x.SpeciesCode.Equals(entry.SpeciesCode)).Count() - beyond50.Count();
            int deleteWithin = _state.PointSurvey.Observations.OfType <PointCountWithin50>().Where(x => x.SpeciesCode.Equals(entry.SpeciesCode)).Count() - within50.Count();

            if (deleteBeyond > 0)
            {
                var toDelete = _state.PointSurvey.Observations.Where(x => x.SpeciesCode.Equals(entry.SpeciesCode)).Take(deleteBeyond);
                toDelete.ToList().ForEach(x =>
                {
                    ObservationMapper.Delete(x);
                    _state.PointSurvey.Observations.Remove(x);
                });
            }
            if (deleteWithin > 0)
            {
                var toDelete = _state.PointSurvey.Observations.Where(x => x.SpeciesCode.Equals(entry.SpeciesCode)).Take(deleteWithin);
                toDelete.ToList().ForEach(x =>
                {
                    ObservationMapper.Delete(x);
                    _state.PointSurvey.Observations.Remove(x);
                });
            }
        }
Example #15
0
        public void t_SupplementalObservation_Save_Insert()
        {
            //loadSiteVisit(TestHelper.TestGuid1);
            SupplementalObservation supplemental = new SupplementalObservation()
            {
                Comments    = "asdfasdf asdf adsfa dsfads fasdf adsfasd fadsf awefr34fr34r34 ",
                SpeciesCode = TestHelper.SPECIES_1_CODE,
                EventId     = TestHelper.TestGuid1
            };

            ObservationMapper.Insert(supplemental);

            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var SupplementalObservationQuery = from SupplementalObservations in iba.Observation_ado select SupplementalObservations;
                Assert.IsNotNull(SupplementalObservationQuery, "Query result is null");
                Assert.AreEqual(1, SupplementalObservationQuery.Count(), "Wrong number of results in query");
                Observation_ado adoSupplementalObservation = SupplementalObservationQuery.First();
                validateObjectEquality(supplemental, adoSupplementalObservation, iba);
            }
        }
        public HttpResponseMessage Read(int observationId, string _format = "application/xml+FHIR", bool _summary = false)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Observation observation = db.Observations.Find(observationId);

            if (observation == null)
            {
                message.StatusCode = HttpStatusCode.NotFound;
                message.Content    = new StringContent("observation with id " + observationId + " not found!", Encoding.UTF8, "text/html");
                return(message);
            }

            Hl7.Fhir.Model.Observation fhirObservation = ObservationMapper.MapModel(observation);
            string fixedFormat = ControllerUtils.FixMimeString(_format);

            string payload = ControllerUtils.Serialize(fhirObservation, fixedFormat, _summary);

            message.Content = new StringContent(payload, Encoding.UTF8, fixedFormat);
            return(message);
        }
Example #17
0
        public void t_PointCountLess50_Save_Insert()
        {
            //loadSiteVisit(TestHelper.TestGuid1);
            PointCountWithin50 supplemental = new PointCountWithin50()
            {
                Comments    = "asdfasdf asdf adsfa dsfads fasdf adsfasd fadsf awefr34fr34r34 ",
                SpeciesCode = TestHelper.SPECIES_1_CODE,
                EventId     = TestHelper.TestGuid1
            };

            ObservationMapper.Insert(supplemental);

            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var PointCountLess50Query = from PointCountLess50s in iba.Observation_ado select PointCountLess50s;
                Assert.IsNotNull(PointCountLess50Query, "Query result is null");
                Assert.AreEqual(1, PointCountLess50Query.Count(), "Wrong number of results in query");
                Observation_ado adoPointCountLess50 = PointCountLess50Query.First();
                validateObjectEquality(supplemental, adoPointCountLess50, iba);
            }
        }
Example #18
0
        /// <summary>
        /// Get patient data for ML task
        /// </summary>
        /// <param name="patient"> given patient </param>
        /// <returns> a patient contains observation values for ML task </returns>
        public static async Task <Models.Patient> GetDataForAnalysis(Models.Patient patient)
        {
            Models.Patient currentPatient = patient;
            currentPatient.Observations    = new List <Models.Observation>();
            currentPatient.HasObservations = true;
            try
            {
                var ObservationQuery = new SearchParams()
                                       .Where("patient=" + currentPatient.Id)
                                       .OrderBy("-date")
                                       .LimitTo(LIMIT_ENTRY);

                Bundle ObservationResult = await Client.SearchAsync <Hl7.Fhir.Model.Observation>(ObservationQuery);

                foreach (var Entry in ObservationResult.Entry)
                {
                    Hl7.Fhir.Model.Observation fhirObservation = (Hl7.Fhir.Model.Observation)Entry.Resource;
                    if (fhirObservation.Value != null && fhirObservation.Value is Hl7.Fhir.Model.Quantity)
                    {
                        ObservationMapper  mapper      = new ObservationMapper();
                        Models.Observation observation = mapper.Map(fhirObservation);
                        if (!currentPatient.ContainsObservation(observation.CodeText))
                        {
                            currentPatient.Observations.Add(observation);
                        }
                    }
                }
            }
            catch (FhirOperationException FhirException)
            {
                System.Diagnostics.Debug.WriteLine("Fhir error message: " + FhirException.Message);
            }
            catch (Exception GeneralException)
            {
                System.Diagnostics.Debug.WriteLine("General error message: " + GeneralException.Message);
            }

            return(currentPatient);
        }
        public void Insert(FiftyMeterDataEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            entry.SpeciesCode = entry.SpeciesCode.ToUpper();
            List <PointCountBeyond50> beyond50 = entry.GetListBeyond50();
            List <PointCountWithin50> within50 = entry.GetListWithin50();

            beyond50.FindAll(y => !y.MarkForDeletion).ForEach(x =>
            {
                ObservationMapper.Insert(x);
                _state.PointSurvey.Observations.Add(x);
            });
            within50.FindAll(y => !y.MarkForDeletion).ForEach(x =>
            {
                ObservationMapper.Insert(x);
                _state.PointSurvey.Observations.Add(x);
            });
        }
        public HttpResponseMessage Update(Hl7.Fhir.Model.Observation fhirObservation, int observationId)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            if (observationId != int.Parse(fhirObservation.Id))
            {
                message.StatusCode = HttpStatusCode.BadRequest;
                message.Content    = new StringContent("Mismatch of observation ID! Provided " + observationId + " in URL but found " + fhirObservation.Id + "in payload!", Encoding.UTF8, "text/html");
                return(message);
            }

            Observation observation = ObservationMapper.MapResource(fhirObservation);

            observation = (Observation)ControllerUtils.AddMetadata(observation, ControllerUtils.UPDATE);

            db.Entry(observation).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ObservationExists(observationId))
                {
                    message.StatusCode = HttpStatusCode.NotFound;
                    message.Content    = new StringContent("observation with id " + observationId + " not found!", Encoding.UTF8, "text/html");
                    return(message);
                }
                else
                {
                    throw;
                }
            }

            message.StatusCode = HttpStatusCode.OK;
            return(message);
        }
        public void Delete(FiftyMeterDataEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            ObservationMapper.DeleteTopX(entry.PointSurveyId, PointCountWithin50.ObservationTypeGuid,
                                         entry.SpeciesCode, entry.CountWithin50);
            ObservationMapper.DeleteTopX(entry.PointSurveyId, PointCountBeyond50.ObservationTypeGuid,
                                         entry.SpeciesCode, entry.CountBeyond50);

            entry.GetListBeyond50().ForEach(x =>
            {
                _state.PointSurvey.Observations.RemoveAll(y => y.ObservationTypeId.Equals(x.ObservationTypeId) &&
                                                          y.SpeciesCode.Equals(x.SpeciesCode));
            });
            entry.GetListWithin50().ForEach(x =>
            {
                _state.PointSurvey.Observations.RemoveAll(y => y.ObservationTypeId.Equals(x.ObservationTypeId) &&
                                                          y.SpeciesCode.Equals(x.SpeciesCode));
            });
        }
Example #22
0
        /// <summary>
        /// Get Observation values of a patients list (Total Cholesterol, Blood Pressure)
        /// </summary>
        /// <param name="patients"> given list of patients </param>
        /// <returns> list of patients that contain Cholesterol and Blood Pressure values </returns>
        public static async Task <PatientsList> GetObservationValues(PatientsList patients)
        {
            PatientsList MonitoredPatientList = new PatientsList();

            foreach (Models.Patient MonitoredPatient in patients)
            {
                try
                {
                    Models.Patient patient = MonitoredPatient;
                    patient.Observations    = new List <Models.Observation>();
                    patient.HasObservations = true;

                    // sort by date, limit to 1 so only take the newest Cholesterol observation
                    var ObservationQuery = new SearchParams()
                                           .Where("patient=" + MonitoredPatient.Id)
                                           .Where("code=" + CHOLESTEROL_CODE)
                                           .OrderBy("-date")
                                           .LimitTo(1);

                    Bundle ObservationResult = await Client.SearchAsync <Hl7.Fhir.Model.Observation>(ObservationQuery);

                    if (ObservationResult.Entry.Count > 0)
                    {
                        // Map the FHIR Observation object to App's Observation object
                        Hl7.Fhir.Model.Observation fhirObservation        = (Hl7.Fhir.Model.Observation)ObservationResult.Entry[0].Resource;
                        ObservationMapper          mapper                 = new ObservationMapper();
                        Models.Observation         cholesterolObservation = mapper.Map(fhirObservation);
                        patient.Observations.Add(cholesterolObservation);
                    }

                    // sort by date, limit to 5 so only take the lastest Blood Pressure observation
                    ObservationQuery = new SearchParams()
                                       .Where("patient=" + MonitoredPatient.Id)
                                       .Where("code=" + BLOOD_PRESSURE_CODE)
                                       .OrderBy("-date")
                                       .LimitTo(5);

                    ObservationResult = await Client.SearchAsync <Hl7.Fhir.Model.Observation>(ObservationQuery);

                    for (int i = 0; i < ObservationResult.Entry.Count; i++)
                    {
                        // Map the FHIR Observation object to App's Observation object
                        Hl7.Fhir.Model.Observation fhirObservation = (Hl7.Fhir.Model.Observation)ObservationResult.Entry[i].Resource;
                        ComponentObservationMapper mapper          = new ComponentObservationMapper();

                        Models.Observation diastolicObservation = mapper.Map(fhirObservation.Component[0]);
                        diastolicObservation.Id = fhirObservation.Id;

                        Models.Observation systolicObservation = mapper.Map(fhirObservation.Component[1]);
                        systolicObservation.Id = fhirObservation.Id;

                        if (fhirObservation.Issued != null)
                        {
                            diastolicObservation.Issued = ((DateTimeOffset)fhirObservation.Issued).DateTime;
                            systolicObservation.Issued  = ((DateTimeOffset)fhirObservation.Issued).DateTime;
                        }
                        else
                        {
                            diastolicObservation.Issued = null;
                            systolicObservation.Issued  = null;
                        }

                        patient.Observations.Add(diastolicObservation);
                        patient.Observations.Add(systolicObservation);
                    }

                    MonitoredPatientList.AddPatient(patient);
                }
                catch (FhirOperationException FhirException)
                {
                    System.Diagnostics.Debug.WriteLine("Fhir error message: " + FhirException.Message);
                }
                catch (Exception GeneralException)
                {
                    System.Diagnostics.Debug.WriteLine("General error message: " + GeneralException.Message);
                }
            }
            return(MonitoredPatientList);
        }
Example #23
0
 public void t_PointCountLess50_Select_ByPointSurveyId_Empty()
 {
     // Exercise the test
     List <PointCountWithin50> PointCountLess50 = ObservationMapper.SelectAllForEvent <PointCountWithin50>(Guid.Empty);
 }
Example #24
0
 public void Delete(SupplementalObservation observation)
 {
     ObservationMapper.Delete(observation);
     _state.SiteVisit.SupplementalObservations.RemoveAll(x => x.Id.Equals(observation.Id));
 }
Example #25
0
 public void Insert(SupplementalObservation observation)
 {
     observation.SpeciesCode = observation.SpeciesCode.ToUpper();
     ObservationMapper.Insert(observation);
     _state.SiteVisit.SupplementalObservations.Add(observation);
 }
Example #26
0
 public void t_SupplementalObservation_Select_ByPointSurveyId_Empty()
 {
     // Exercise the test
     List <SupplementalObservation> SupplementalObservation = ObservationMapper.SelectAllForEvent <SupplementalObservation>(Guid.Empty);
 }