//public PregnancyResult GetMostRecentPregnancy(string patientDfn) //{ // PregnancyResult result = new PregnancyResult(); // PregnancyListResult listResult = GetPregnancies(patientDfn, ""); // if (listResult.Success) // { // if (listResult.Pregnancies != null) // { // Pregnancy mostRecent; // foreach (Pregnancy preg in listResult.Pregnancies) // { // if (mostRecent == null) // mostRecent = preg; // else if (preg.RecordType == PregnancyRecordType.Current) // mostRecent = preg; // } // } // } // return result; //} private List <DsioObservation> GetObservationsToSave(string patientDfn, PregnancyHistory pregnancyHistory) { PregnancyHistory origHist = null; // *** Get original history *** PregnancyHistoryResult histResult = this.GetPregnancyHistory(patientDfn); // *** Create a list of items that need to be saved *** List <DsioObservation> observationsToSave = new List <DsioObservation>(); // *** Set original history *** if (histResult.Success) { origHist = histResult.PregnancyHistory; } // *** Loop through all the observations *** foreach (Observation newObservation in pregnancyHistory.Observations.Values) { if (!string.IsNullOrWhiteSpace(newObservation.Value)) // *** Add if there's something there { // *** If we have previous entries *** if (origHist != null) { // *** Compare current with previous and only save if different *** string origVal = origHist.GetValue(newObservation.Code); if (origVal == null) { origVal = ""; } if (origVal != newObservation.Value) { DsioObservation dsioObs = ObservationUtility.GetDsioObservation(newObservation); observationsToSave.Add(dsioObs); } } else { DsioObservation dsioObs = ObservationUtility.GetDsioObservation(newObservation); observationsToSave.Add(dsioObs); } } } return(observationsToSave); }
public PregnancyHistoryResult GetPregnancyHistory(string patientDfn) { // *** Gets pregnancy history *** PregnancyHistoryResult result = new PregnancyHistoryResult(); // *** Create the command *** DsioGetObservationsCommand command = new DsioGetObservationsCommand(this.broker); // *** Add command arguments *** command.AddCommandArguments(patientDfn, "", "", "", "", "", "", "Pregnancy History", 1, 1000); // *** Execute command *** RpcResponse response = command.Execute(); // *** Add results to return *** result.Success = response.Status == RpcResponseStatus.Success; result.Message = response.InformationalMessage; // *** Create pregnancy history *** if (result.Success) { // *** Check that there are observations *** if (command.ObservationsList != null) { if (command.ObservationsList.Count > 0) { // *** Create a dictionary to hold only most recent *** Dictionary <string, DsioObservation> mostRecentList = new Dictionary <string, DsioObservation>(); // *** Loop through the list, if it does not exist add it, or if it is newer, replace *** foreach (DsioObservation dsioObservation in command.ObservationsList) { if (!mostRecentList.ContainsKey(dsioObservation.Code.Code)) { mostRecentList.Add(dsioObservation.Code.Code, dsioObservation); } else { // *** Get dates to compare *** DateTime existingDate = VistaDates.ParseDateString(mostRecentList[dsioObservation.Code.Code].EntryDate, VistaDates.VistADateFormatTwo); DateTime newDate = VistaDates.ParseDateString(dsioObservation.EntryDate, VistaDates.VistADateFormatTwo); // *** If newer replace *** if (newDate > existingDate) { mostRecentList[dsioObservation.Code.Code] = dsioObservation; } } } // *** Loop through most recent and add to pregnancy history *** foreach (DsioObservation dsioObservation in mostRecentList.Values) { if (!string.IsNullOrWhiteSpace(dsioObservation.Code.Code)) { Observation tempObs = ObservationUtility.GetObservation(dsioObservation); result.PregnancyHistory.Observations[dsioObservation.Code.Code] = tempObs; //result.PregnancyHistory.SetValue(dsioObservation.Code, dsioObservation.Value); } } } } } return(result); }