public void similarHistoryTest() { Patient p1 = new Patient(1); Patient p2 = new Patient(2); Patient p3 = new Patient(3); DateTime now = DateTime.Now; p1.AddVisit(new Visit(1, 1, 1, now)); p1.AddVisit(new Visit(2, 1, 2, now)); p1.AddVisit(new Visit(3, 1, 3, now)); p1.AddVisit(new Visit(4, 1, 3, now.AddDays(1))); p2.AddVisit(new Visit(5, 1, 1, now)); p2.AddVisit(new Visit(6, 1, 2, now)); p3.AddVisit(new Visit(7, 1, 3, now)); p3.AddVisit(new Visit(8, 1, 3, now.AddDays(2))); bool result = p1.HasSimilarVisits(p2, 0.5f); Assert.True(result == true); result = p1.HasSimilarVisits(p3, 0.5f); Assert.True(result == false); result = p1.HasSimilarVisits(p3, 0.25f); Assert.True(result == true); result = p1.HasSimilarVisits(p2, 0.75f); Assert.True(result == false); }
//generate data for iteration 1 public void createIteration1PatientsAndVisits(int numberOfPatients) { Random random = new Random(); List<Patient> patients = new List<Patient>(); List<Patient> globallySimilarPatients = new List<Patient>(); List<Patient> globallyNonSimilarPatients = new List<Patient>(); List<PatientMatchNode> patientMatchNodes = new List<PatientMatchNode>(); float globallySimilarPatientsThreshold = 0.1f; float globallyNonSimilarPatientsThreshold = 0.1f; int requiredNumberOfGloballySimilarPatients = (int)((globallySimilarPatientsThreshold * numberOfPatients) + 0.5f); int requiredNumberOfGloballyNonSimilarPatients = (int)((globallyNonSimilarPatientsThreshold * numberOfPatients) + 0.5f); int currentNumberOfGloballySimilarPatients = 0; int currentNumberOfGloballyNonSimilarPatients = 0; DateTime maxRangeStart = new DateTime(2011, 01, 01); DateTime maxRangeEnd = new DateTime(2011, 12, 31); DateTime rangeStart = Util.getRandomDate(maxRangeStart, maxRangeEnd.AddMonths(-1)); DateTime rangeEnd = rangeStart.AddDays(15); int randRationalMin = 1; int randRationalMax = 5; DbMethods.getInstance().clearTables(); for (int i = 0; i < numberOfPatients; i++) { int patientID = i; DbMethods.getInstance().InsertPatient(); Patient patient = new Patient(patientID); PatientMatchNode patientNode = new PatientMatchNode(patient); int numberOfVisits = random.Next(10, 20); bool restart = true; do { patient.ClearVisits(); //generate directed visits for (int j = 0; j < numberOfVisits; j++) { Visit v = new Visit(-1, random.Next(1, 100), random.Next(randRationalMin, randRationalMax), Util.getRandomDate(rangeStart, rangeEnd)); if (!patient.HasVisit(v)) { patient.AddVisit(v); } else { j--; } } if (requiredNumberOfGloballySimilarPatients > 0) { //SIMILAR PATIENTS foreach (PatientMatchNode n in patientMatchNodes) { if (n.Patient.HasSimilarVisits(patient, 0.5f)) { n.addMatch(patient); restart = false; } } List<PatientMatchNode> nodesToRemove = new List<PatientMatchNode>(); foreach (PatientMatchNode n in patientMatchNodes) { if (n.getMatchesNumber() >= 4) { requiredNumberOfGloballySimilarPatients--; globallySimilarPatients.Add(n.Patient); nodesToRemove.Add(n); } } foreach (PatientMatchNode n in nodesToRemove) { patientMatchNodes.Remove(n); } nodesToRemove.Clear(); if(patientMatchNodes.Count < requiredNumberOfGloballySimilarPatients) { patientMatchNodes.Add(patientNode); restart = false; } } else if (requiredNumberOfGloballyNonSimilarPatients > 0) { //NON-SIMILAR PATIENTS rangeStart = maxRangeStart; rangeEnd = maxRangeEnd; bool hasSimilar = false; foreach (Patient p in patients) { if (!patient.HasNoSimilarVisits(p)) { hasSimilar = true; } } if (!hasSimilar) { restart = false; requiredNumberOfGloballyNonSimilarPatients--; globallyNonSimilarPatients.Add(patient); } } else { bool hasSimilar = false; foreach (Patient p in globallyNonSimilarPatients) { if (!patient.HasNoSimilarVisits(p)) { hasSimilar = true; } } if (!hasSimilar) { restart = false; } } } while(restart); //adding the visits foreach (Visit v in patient.Visits) { DbMethods.getInstance().InsertVisit(patientID, v.ProfessionalID, v.RationalID, v.Date); } patients.Add(patient); } }