private void SaveScreening() { if (Validate()) { ObsPartnerScreening obs; if (null == ObsPartnerScreening) { obs = ObsPartnerScreening.Create( ScreeningDate, SelectedIPVScreening.ItemId, SelectedPhysicalAssult.ItemId, SelectedThreatened.ItemId, SelectedSexuallyUncomfortable.ItemId, SelectedHIVStatus.ItemId, SelectedEligibility.ItemId, BookingDate, Remarks, SelectedPnsAccepted.ItemId, SelectedIPVOutcome.ItemId, Occupation, SelectedPNSRealtionship.ItemId, SelectedLivingWithClient.ItemId, SelectedPNSApproach.ItemId, EncounterId, IndexClient.Id); } else { obs = ObsPartnerScreening; obs.ScreeningDate = ScreeningDate; obs.PnsAccepted = SelectedPnsAccepted.ItemId; obs.IPVScreening = SelectedIPVScreening.ItemId; obs.PhysicalAssult = SelectedPhysicalAssult.ItemId; obs.Threatened = SelectedThreatened.ItemId; obs.SexuallyUncomfortable = SelectedSexuallyUncomfortable.ItemId; obs.IPVOutcome = SelectedIPVOutcome.ItemId; obs.Occupation = Occupation; obs.PNSRealtionship = SelectedPNSRealtionship.ItemId; obs.LivingWithClient = SelectedLivingWithClient.ItemId; obs.HivStatus = SelectedHIVStatus.ItemId; obs.Eligibility = SelectedEligibility.ItemId; obs.BookingDate = BookingDate; obs.Remarks = Remarks; obs.PNSApproach = SelectedPNSApproach.ItemId; } _partnerScreeningService.SavePartnerScreening(obs, Client.Id, IndexClient.Id); _partnerScreeningService.MarkEncounterCompleted(EncounterId, AppUserId, true); ShowViewModel <DashboardViewModel>(new { id = Client.Id }); } }
public void SavePartnerScreening(ObsPartnerScreening testResult, Guid clientId, Guid indexClientId) { _obsPartnerScreeningRepository.SaveOrUpdate(testResult); _clientStateRepository.SaveOrUpdate(new ClientState(clientId, testResult.EncounterId, LiveState.PartnerScreened, indexClientId)); _clientStateRepository.DeleteState(clientId, testResult.EncounterId, LiveState.PartnerEligibileNo, indexClientId); _clientStateRepository.DeleteState(clientId, testResult.EncounterId, LiveState.PartnerEligibileYes, indexClientId); if (testResult.Eligibility == new Guid("b25eccd4-852f-11e7-bb31-be2e44b06b34")) { _clientStateRepository.SaveOrUpdate(new ClientState(clientId, testResult.EncounterId, LiveState.PartnerEligibileYes, indexClientId)); } else { _clientStateRepository.SaveOrUpdate(new ClientState(clientId, testResult.EncounterId, LiveState.PartnerEligibileNo, indexClientId)); } }
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); } } }