Beispiel #1
0
        public static void testRepo(PatientContext dbc)
        {
            System.Console.WriteLine("must start with new database using args of --init true");

            PatientRepo pr = new PatientRepo(dbc, null);

            //Get many
            System.Console.WriteLine("Get many");
            IEnumerable <Patient> allrecords = pr.getPatients("", "");

            System.Console.WriteLine("records: " + allrecords.Count());
            foreach (var record in allrecords)
            {
                System.Console.WriteLine("record: " + record.enterpriseId + "=" + record.memberRecords.Count());
            }
            Debug.Assert(allrecords.Count() == 1);

            //Get none
            System.Console.WriteLine("Get none");
            IEnumerable <Patient> norecords = pr.getPatients("a", "b");

            System.Console.WriteLine("records: " + norecords.Count());
            Debug.Assert(norecords.Count() == 0);

            //Get one
            System.Console.WriteLine("Get one");
            IEnumerable <Patient> records = pr.getPatients("JHU", "123x");

            System.Console.WriteLine("records: " + records.Count());
            Debug.Assert(records.Count() == 1);
            foreach (var record in records)
            {
                System.Console.WriteLine("record: " + record.enterpriseId + "=" + record.memberRecords.Count());
            }

            //Add
            System.Console.WriteLine("add");
            bool result = pr.addPatient(new Patient()
            {
                memberRecords = new List <PatientMemberRecord>()
                {
                    PatientRepo.createPatientMemberRecord("JHU", "123xz"),
                    PatientRepo.createPatientMemberRecord("JHU", "123xy")
                }
            }, null);

            System.Console.WriteLine("result: " + result);
            Debug.Assert(result);

            //Add duplicate (expected failure)
            System.Console.WriteLine("add failure");
            result = pr.addPatient(new Patient()
            {
                memberRecords = new List <PatientMemberRecord>()
                {
                    PatientRepo.createPatientMemberRecord("JHU", "123xz"),
                    PatientRepo.createPatientMemberRecord("JHU", "123xx")
                }
            }, null);
            System.Console.WriteLine("result: " + result);
            Debug.Assert(!result);

            //Get one (multiple memberRecords)
            System.Console.WriteLine("Get one");
            records = pr.getPatients("JHU", "123xy");
            System.Console.WriteLine("records: " + records.Count());
            foreach (var record in records)
            {
                System.Console.WriteLine("record: " + record.enterpriseId + "=" + record.memberRecords.Count());
            }
            Debug.Assert(records.Count() > 0);
            Debug.Assert(records.First().memberRecords.Count() == 2);

            //Update
            System.Console.WriteLine("Update");
            bool b = false;

            PatientMemberRecord changedRecord = PatientRepo.createPatientMemberRecord("JHU", "123xz");

            changedRecord.firstName = "Rob";
            Patient changedPatient = new Patient
            {
                memberRecords = new List <PatientMemberRecord> {
                    changedRecord,
                    PatientRepo.createPatientMemberRecord("JHU", "123xx")
                }
            };
            string eid = records.First().enterpriseId;

            Debug.Assert(pr.updatePatient(changedPatient, eid, ref b));

            records = pr.getPatients("JHU", "123xx");
            Debug.Assert(records.Count() > 0);
            Debug.Assert(records.First().memberRecords.Count() == 2);
            Debug.Assert(records.First().enterpriseId == eid);

            //Delete
            System.Console.WriteLine("Delete");
            Debug.Assert(pr.deletePatient("xyz"));

            allrecords = pr.getPatients("", "");
            Debug.Assert(allrecords.Count() == 1);
            Debug.Assert(allrecords.First().enterpriseId == eid);
        }
Beispiel #2
0
 public PatientRepo(PatientContext context, ILogger logger)
 {
     _libraryContext = context;
     _logger         = logger;
 }