public IenResult SavePregnancy(PregnancyDetails pregnancy)
        {
            // *** Saves pregnancy data ***

            IenResult result = new IenResult();

            // *** Create the dsio pregnancy string data ***
            DsioPregnancy dsioPregnancy = CreateDsioPregnancy(pregnancy);

            // *** Create RPC command ***
            DsioSavePregDetailsCommand command = new DsioSavePregDetailsCommand(this.broker);

            // *** Add command arguments ***
            command.AddCommandArguments(dsioPregnancy, false);

            // *** Execute the command ***
            RpcResponse response = command.Execute();

            // *** Add response data to result ***
            result.SetResult(response.Status == RpcResponseStatus.Success, response.InformationalMessage);

            if (result.Success)
            {
                result.Ien = command.Ien;
            }

            return(result);
        }
        public AddBabyResult AddBabyToPregnancy(string patientDfn, string pregnancyIen)
        {
            AddBabyResult returnResult = new AddBabyResult();

            PregnancyListResult pregResult = this.GetPregnancies(patientDfn, pregnancyIen);

            if (!pregResult.Success)
            {
                returnResult.SetResult(pregResult.Success, pregResult.Message);
            }
            else if (pregResult.Pregnancies != null)
            {
                if (pregResult.Pregnancies.Count == 1)
                {
                    PregnancyDetails pregDetail = pregResult.Pregnancies[0];

                    bool okToAdd = true;

                    // *** Do we have a babies object ? ***
                    if (pregDetail.Babies != null)
                    {
                        if (pregDetail.Babies.Count >= 9)
                        {
                            returnResult.SetResult(false, "This pregnancy already has 9 babies.  You cannot add more than 9 babies to a pregnancy.");
                            okToAdd = false;
                        }
                    }

                    if (okToAdd)
                    {
                        // *** Create the save command ***
                        DsioSavePregDetailsCommand saveCommand = new DsioSavePregDetailsCommand(this.broker);

                        // *** Create the dsio pregnancy ***
                        DsioPregnancy dsioPreg = CreateDsioPregnancy(pregDetail);

                        // *** Add the command arguments, addBaby = true ***
                        saveCommand.AddCommandArguments(dsioPreg, true);

                        // *** Execute the command ***
                        RpcResponse response = saveCommand.Execute();

                        returnResult.SetResult(pregResult.Success, pregResult.Message);

                        // *** Check the status ***
                        if (response.Status == RpcResponseStatus.Success)
                        {
                            //int newBabyNum = -1;
                            //int.TryParse(saveCommand.BabyNumber, out newBabyNum);
                            //pregDetail.Babies.Add(new Baby() { BabyNum = newBabyNum, Ien = saveCommand.BabyIen });
                            returnResult.NewBabyIen    = saveCommand.BabyIen;
                            returnResult.NewBabyNumber = saveCommand.BabyNumber;
                        }
                    }
                }
            }

            return(returnResult);
        }
        public DsioPregnancy AddCurrentPregnancy(IRpcBroker broker, string patientDfn)
        {
            DsioSavePregDetailsCommand command = new DsioSavePregDetailsCommand(broker);

            DsioPregnancy newPreg = new DsioPregnancy()
            {
                EDD        = DateTime.Now.AddMonths(6).ToString(VistaDates.VistADateOnlyFormat),
                RecordType = "CURRENT",
                PatientDfn = patientDfn
            };

            command.AddCommandArguments(newPreg, false);

            RpcResponse response = command.Execute();

            Assert.AreEqual(RpcResponseStatus.Success, response.Status);

            newPreg.Ien = command.Ien;

            return(newPreg);
        }
        public void TestSavePregnancy()
        {
            using (RpcBroker broker = this.GetConnectedBroker())
            {
                this.SignonToBroker(broker, 2);

                DsioSavePregDetailsCommand command = new DsioSavePregDetailsCommand(broker);

                DsioPregnancy preg = new DsioPregnancy();
                //preg.PatientDfn = "704";
                //preg.PatientDfn = "100007";
                //preg.PatientDfn = "763";
                preg.PatientDfn = TestConfiguration.DefaultPatientDfn;
                preg.Ien        = "";
                preg.RecordType = "HISTORICAL";
                //preg.FatherOfFetusIen = "U";
                preg.EDD = "";
                //preg.StartDate = "09/13/2014";
                //preg.StartDate = "";
                preg.EndDate         = "";
                preg.ObstetricianIen = "";
                preg.LDFacilityIen   = "";
                preg.HighRisk        = "1";
                preg.HighRiskDetails = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum";

                preg.GestationalAgeAtDelivery = "145";
                preg.LengthOfLabor            = "12";
                preg.TypeOfDelivery           = "Caesarean";
                preg.Anesthesia      = "Epidural";
                preg.PretermDelivery = "YES";
                preg.Outcome         = "P";

                command.AddCommandArguments(preg, false);

                RpcResponse response = command.Execute();

                Assert.AreEqual(RpcResponseStatus.Success, response.Status);
            }
        }
        public void TestCreateAndRetrieveHistoricalPregnancy()
        {
            using (RpcBroker broker = this.GetConnectedBroker())
            {
                this.SignonToBroker(broker, 2);

                DsioSavePregDetailsCommand createCommand = new DsioSavePregDetailsCommand(broker);

                DsioPregnancy preg = new DsioPregnancy();
                preg.PatientDfn       = TestConfiguration.DefaultPatientDfn;
                preg.Ien              = "";
                preg.RecordType       = "HISTORICAL";
                preg.FatherOfFetusIen = "U";
                preg.EDD              = "";
                preg.StartDate        = "";
                preg.EndDate          = "05/05/2011";
                preg.ObstetricianIen  = "";
                preg.LDFacilityIen    = "";

                preg.GestationalAgeAtDelivery = "145";
                preg.LengthOfLabor            = "12";
                preg.TypeOfDelivery           = "Caesarean";
                preg.Anesthesia      = "Epidural";
                preg.PretermDelivery = "YES";
                preg.Outcome         = "PretermDelivery";

                preg.Comment  = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
                preg.HighRisk = "1";

                preg.HighRiskDetails = "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

                createCommand.AddCommandArguments(preg, false);

                RpcResponse response = createCommand.Execute();

                Assert.IsNotNull(response);
                Assert.AreEqual(RpcResponseStatus.Success, response.Status);
                Assert.IsFalse(string.IsNullOrWhiteSpace(createCommand.Ien));

                string ien = createCommand.Ien;

                DsioGetPregDetailsCommand getCommand = new DsioGetPregDetailsCommand(broker);

                getCommand.AddCommandArguments(TestConfiguration.DefaultPatientDfn, ien);

                response = getCommand.Execute();

                Assert.AreEqual(RpcResponseStatus.Success, response.Status);
                Assert.IsNotNull(getCommand.PregnancyList);
                Assert.IsTrue(getCommand.PregnancyList.Count > 0);
                Assert.IsTrue(getCommand.PregnancyList.Count == 1);

                DsioPregnancy returnedPreg = getCommand.PregnancyList[0];

                Assert.AreEqual(preg.PatientDfn, returnedPreg.PatientDfn);
                Assert.AreNotEqual(preg.Ien, returnedPreg.Ien);
                Assert.AreEqual(preg.RecordType, returnedPreg.RecordType);
                Assert.IsTrue(preg.FatherOfFetusIen.Equals(returnedPreg.FatherOfFetusIen, StringComparison.InvariantCultureIgnoreCase));
                Assert.AreEqual(preg.EDD, returnedPreg.EDD);
                Assert.AreEqual(preg.StartDate, returnedPreg.StartDate);
                Assert.AreEqual(preg.EndDate, returnedPreg.EndDate);

                Assert.AreEqual(preg.GestationalAgeAtDelivery, returnedPreg.GestationalAgeAtDelivery);
                Assert.AreEqual(preg.LengthOfLabor, returnedPreg.LengthOfLabor);
                Assert.AreEqual(preg.Anesthesia, returnedPreg.Anesthesia);
                Assert.AreEqual(preg.Comment, returnedPreg.Comment);
                Assert.AreEqual(preg.HighRiskDetails, returnedPreg.HighRiskDetails);

                Assert.AreEqual(preg.HighRisk, returnedPreg.HighRisk);
                Assert.AreEqual(preg.TypeOfDelivery, returnedPreg.TypeOfDelivery);
                Assert.AreEqual(preg.PretermDelivery, returnedPreg.PretermDelivery);
                Assert.AreEqual(preg.Outcome, returnedPreg.Outcome);
            }
        }