public void should_Not_Update_Encounter_Obs_if_null() { var encounter = _encounters.First(); var obsCount = encounter.Obses.ToList().Count; var obs = encounter.Obses.Last(); var newObs = Obs.Create(obs.QuestionId, obs.EncounterId, _clientId, "Single", null); newObs.Id = obs.Id; encounter.AddOrUpdate(newObs, false); var updatedObs = encounter.Obses.FirstOrDefault(x => x.Id == newObs.Id); Assert.IsNull(updatedObs); }
public void Sync(EncounterInfo encounterInfo) { //Check pracitce var practice = _practiceRepository.Get(encounterInfo.PracticeId); if (null == practice) { throw new ArgumentException("Facility is not registered"); } //Check client var client = _clientRepository.Get(encounterInfo.ClientId); if (null == client) { throw new ArgumentException("Client is not registered"); } var encounter = _encounterRepository.Get(encounterInfo.Id); if (null == encounter) { encounter = Encounter.Create(encounterInfo); _encounterRepository.Insert(encounter); _encounterRepository.Save(); var obs = Obs.Create(encounterInfo); _obsRepository.Insert(obs); _obsRepository.Save(); } else { encounter.Update(encounterInfo); _encounterRepository.Update(encounter); _encounterRepository.Save(); var obs = Obs.Create(encounterInfo); _obsRepository.ReplaceAll(encounter.Id, obs); _obsRepository.Save(); } }
public void should_Not_Add_Encounter_Obs_If_Null() { var encounter = _encounters.First(); var obsCount = encounter.Obses.ToList().Count; var concept = Builder <Concept> .CreateNew().Build(); var question = Builder <Question> .CreateNew() .With(x => x.Concept = concept) .With(x => x.ConceptId = concept.Id) .Build(); var obs = Builder <Obs> .CreateNew() .With(x => x.QuestionId = question.Id) .Build(); obs = Obs.Create(obs.QuestionId, obs.EncounterId, _clientId, "Text", ""); encounter.AddOrUpdate(obs, false); var newObs = encounter.Obses.FirstOrDefault(x => x.Id == obs.Id); Assert.IsNull(newObs); Assert.IsTrue(encounter.Obses.ToList().Count == obsCount); }
public void Sync(List <EncounterInfo> encounterInfos) { foreach (var encounterInfo in encounterInfos) { try { //Check client var client = _clientRepository.Get(encounterInfo.ClientId); if (null != client) { var encounter = _encounterRepository.Get(encounterInfo.Id); if (null == encounter) { encounter = Encounter.Create(encounterInfo); _encounterRepository.Insert(encounter); _encounterRepository.Save(); var obs = Obs.Create(encounterInfo); _obsRepository.Insert(obs); _obsRepository.Save(); var obsTestResult = ObsTestResult.Create(encounterInfo); _obsTestResultRepository.Insert(obsTestResult); _obsTestResultRepository.Save(); var obsFinalTestResults = ObsFinalTestResult.Create(encounterInfo); _obsFinalTestResultRepository.Insert(obsFinalTestResults); _obsFinalTestResultRepository.Save(); var bsLinkages = ObsLinkage.Create(encounterInfo); _obsLinkageRepository.Insert(bsLinkages); _obsLinkageRepository.Save(); var obsTraceResults = ObsTraceResult.Create(encounterInfo); _obsTraceResultRepository.Insert(obsTraceResults); _obsTraceResultRepository.Save(); var obsMemberScreening = ObsMemberScreening.Create(encounterInfo); _obsMemberScreeningRepository.Insert(obsMemberScreening); _obsMemberScreeningRepository.Save(); var obsFamilyTraceResults = ObsFamilyTraceResult.Create(encounterInfo); _obsFamilyTraceResultRepository.Insert(obsFamilyTraceResults); _obsFamilyTraceResultRepository.Save(); if (obsFamilyTraceResults.Count > 0) { var met = obsFamilyTraceResults.FirstOrDefault(x => null != x.Outcome && x.Outcome == new Guid("b25f9a81-852f-11e7-bb31-be2e44b06b34")); if (null != met) { _obsFamilyTraceResultRepository.UpdateBooking(encounter, met); } } var obsPartnerScreenings = ObsPartnerScreening.Create(encounterInfo); _obsPartnerScreeningRepository.Insert(obsPartnerScreenings); _obsPartnerScreeningRepository.Save(); var obsPartnerTraceResults = ObsPartnerTraceResult.Create(encounterInfo); _obsPartnerTraceResultRepository.Insert(obsPartnerTraceResults); _obsPartnerTraceResultRepository.Save(); if (obsPartnerTraceResults.Count > 0) { var met = obsPartnerTraceResults.FirstOrDefault(x => null != x.Outcome && x.Outcome == new Guid("b25f9a81-852f-11e7-bb31-be2e44b06b34")); if (null != met) { _obsPartnerTraceResultRepository.UpdateBooking(encounter, met); } } } else { encounter.Update(encounterInfo); _encounterRepository.Update(encounter); _encounterRepository.Save(); var obs = Obs.Create(encounterInfo); _obsRepository.ReplaceAll(encounter.Id, obs); _obsRepository.Save(); var obsTestResult = ObsTestResult.Create(encounterInfo); _obsTestResultRepository.ReplaceAll(encounter.Id, obsTestResult); _obsTestResultRepository.Save(); var obsFinalTestResults = ObsFinalTestResult.Create(encounterInfo); _obsFinalTestResultRepository.ReplaceAll(encounter.Id, obsFinalTestResults); _obsFinalTestResultRepository.Save(); var bsLinkages = ObsLinkage.Create(encounterInfo); _obsLinkageRepository.ReplaceAll(encounter.Id, bsLinkages); _obsLinkageRepository.Save(); var obsTraceResults = ObsTraceResult.Create(encounterInfo); _obsTraceResultRepository.ReplaceAll(encounter.Id, obsTraceResults); _obsTraceResultRepository.Save(); var obsMemberScreening = ObsMemberScreening.Create(encounterInfo); _obsMemberScreeningRepository.ReplaceAll(encounter.Id, obsMemberScreening); _obsMemberScreeningRepository.Save(); var obsFamilyTraceResults = ObsFamilyTraceResult.Create(encounterInfo); _obsFamilyTraceResultRepository.ReplaceAll(encounter.Id, obsFamilyTraceResults); _obsFamilyTraceResultRepository.Save(); if (obsFamilyTraceResults.Count > 0) { var met = obsFamilyTraceResults.FirstOrDefault(x => null != x.Outcome && x.Outcome == new Guid("b25f9a81-852f-11e7-bb31-be2e44b06b34")); if (null != met) { _obsFamilyTraceResultRepository.UpdateBooking(encounter, met); } } var obsPartnerScreenings = ObsPartnerScreening.Create(encounterInfo); _obsPartnerScreeningRepository.ReplaceAll(encounter.Id, obsPartnerScreenings); _obsPartnerScreeningRepository.Save(); var obsPartnerTraceResults = ObsPartnerTraceResult.Create(encounterInfo); _obsPartnerTraceResultRepository.ReplaceAll(encounter.Id, obsPartnerTraceResults); _obsPartnerTraceResultRepository.Save(); if (obsPartnerTraceResults.Count > 0) { var met = obsPartnerTraceResults.FirstOrDefault(x => null != x.Outcome && x.Outcome == new Guid("b25f9a81-852f-11e7-bb31-be2e44b06b34")); if (null != met) { _obsPartnerTraceResultRepository.UpdateBooking(encounter, met); } } } } else { Log.Error("Missing client in encounter"); Preserve(encounterInfo); } } catch (Exception e) { Log.Error(e, "Error saving encounter"); Preserve(encounterInfo); } } }