Or perhaps, to follow our convention of using BDD-based "should" to help
scope testing:
shouldRetrieveEncounterResultFromDatabase
shouldRetrieveObsResultFromDatabase
shouldUseCacheInCalculationContext

-Burke

On Tue, Feb 21, 2012 at 7:40 PM, Darius Jazayeri <[email protected]> wrote:

> Wyclif,
>
> I like these. And this hadn't occurred to me, but I think we do need to
> include EncounterResult, ObsResult, etc in the core calculation module,
> even though we won't be including any providers that use them.
>
> One request: can you please change the naming of these tests so that they
> describe the *high-level* behavior you're trying to show?
>
> E.g. something more like:
> * testEncounterResultIsADateBasedResult
> * testObsResultIsADateBasedResult
> * testCacheInCalculationContext
>
> And you need to rewrite Test #3 so that it actually asserts that you don't
> use the cache on the first call, but you do on the second. Since these
> calculations and evaluators are purely for test purposes, you can just set
> a boolean flag if context.getFromCache returns something.
>
> -Darius
>
>
> On Tue, Feb 21, 2012 at 4:00 PM, Wyclif Luyima <[email protected]> wrote:
>
>> Hi all,
>>
>> Today i addressed some of the review comments from the past reviews. Just
>> as an update about the work on the DateBasedResults, i have added an
>> abstract class, BaseDateBasedResult(wanted to call it
>> AbstractDateBasedResult) and it defines the common properties with their
>> getters and setters, provides the implementations for isEmpty(),
>> asType(clazz), so concrete classes like EncounterResult just have extend
>> this and only have to implement getValue() and getDateOfResult(). I will be
>> implementing ObsResult and EncounterResult first, so i have put together
>> the following behavior tests for testing them:
>>
>> *Test #1*
>> public void shouldGetTheMostRecentEncounterForThePatient() throws
>> Exception {
>> Calculation mostRecentEncounterCalculation = new
>> DemoCalculationProvider().getCalculation("mostRecentEncounter",
>>     null);
>> int patientId = 2;
>> //probably this could be a sql stmt for fetching the most recent encounter
>>  Encounter expectedEncounter =
>> Context.getEncounterService().getEncounter(encounterId);
>> EncounterResult result = (EncounterResult)
>> getService().evaluate(patientId, mostRecentEncounterCalculation);
>>  Assert.assertEquals(expectedEncounter, result.asType(Encounter.class));
>> //Since this is a datebased result, check the date
>>  Assert.assertEquals(expectedEncounter.getEncounterDatetime(),
>> result.getDateOfResult());
>> }
>>  *Test #2*
>> public void shouldGetTheMostRecentObsForThePatient() throws Exception {
>>  Calculation mostRecentObsCalculation = new
>> DemoCalculationProvider().getCalculation("mostRecentObs", null);
>> int patientId = 2;
>>  Obs expectedObs = Context.getObsService().getObs(obsId);
>> ObsResult result = getService().evaluate(patientId,
>> mostRecentObsCalculation);
>>  Assert.assertEquals(expectedObs, result.asType(Obs.class));
>> Assert.assertEquals(expectedObs.getObsDatetime(),
>> result.getDateOfResult());
>>  }
>> *Test# 3*
>> public void
>> shouldGetTheMostRecentObsForTheMostEncounterForThePatientUsingTheCalculationContext()
>> throws Exception {
>>  //Just For testing purposes, our mostRecentEncounter evaluator always
>> caches the most recent encounter
>> //in the context with a special key, so that get most recent obs for the
>> most recent encounter doesn't
>>  //hit the database again
>> Calculation mostRecentEncounterCalculation = new
>> DemoCalculationProvider().getCalculation("mostRecentEncounter",
>>     null);
>> int patientId = 2;
>> EncounterResult encounterResult = (EncounterResult)
>> getService().evaluate(patientId, mostRecentEncounterCalculation);
>>  Calculation mostRecentObsCalculation = new
>> DemoCalculationProvider().getCalculation("mostRecentObs", null);
>>  Obs expectedObs = Context.getObsService().getObs(obsId);
>> Assert.assertEquals(expectedObs,
>>     getService().evaluate(patientId, mostRecentObsCalculation,
>> encounterResult.getCalculationContext()).asType(Obs.class));
>> Assert.assertEquals(expectedObs.getObsDatetime(),
>> result.getDateOfResult());
>>  }
>>
>>
>> *I wrote 3 new behavior tests to test evaluation of cohorts which are
>> below: (these are passing due to prior code that was when i implemented the
>> evaluation methods in CalculationService.evaluate(xx.........))*
>>
>> *Test A*
>> @Test
>> public void shouldCalculateTheAgesOfPatientsInACohort() throws Exception {
>>  Calculation ageCalculation = new
>> DemoCalculationProvider().getCalculation("age", null);
>> int patientId1 = 2;
>>  int patientId2 = 7;
>> Cohort cohort = new Cohort();
>> cohort.addMember(patientId1);
>>  cohort.addMember(patientId2);
>>  PatientService ps = Context.getPatientService();
>>  int expected1 = ps.getPatient(patientId1).getAge();
>> int expected2 = ps.getPatient(patientId2).getAge();
>>  CohortResult cr = getService().evaluate(cohort, ageCalculation);
>> Assert.assertEquals(expected1,
>> cr.get(patientId1).asType(Integer.class).intValue());
>>  Assert.assertEquals(expected2,
>> cr.get(patientId2).asType(Integer.class).intValue());
>> }
>>  *Test B*
>> @Test
>>  public void
>> shouldCalculateTheAgesOfPatientsInACohortBasedOnContextualInfo() throws
>> Exception {
>> Calculation ageCalculation = new
>> DemoCalculationProvider().getCalculation("age", null);
>>  int patientId1 = 2;
>> int patientId2 = 7;
>> Cohort cohort = new Cohort();
>>  cohort.addMember(patientId1);
>> cohort.addMember(patientId2);
>>  Date date = new SimpleDateFormat(TEST_DATE_FORMAT).parse("2000-01-01");
>> CalculationContext ctxt = getService().createCalculationContext();
>>  ctxt.setNow(date);
>>  PatientService ps = Context.getPatientService();
>>  int expected1 = ps.getPatient(patientId1).getAge(date);
>> int expected2 = ps.getPatient(patientId2).getAge(date);
>>  CohortResult cr = getService().evaluate(cohort, ageCalculation, ctxt);
>>  Assert.assertEquals(expected1,
>> cr.get(patientId1).asType(Integer.class).intValue());
>> Assert.assertEquals(expected2,
>> cr.get(patientId2).asType(Integer.class).intValue());
>>  }
>> *Test 3*
>>  @Test
>> public void
>> shouldCalculateTheAgesOfPatientsInACohortBasedOnContextualInfoAndParameterValues()
>> throws Exception {
>>  Calculation ageCalculation = new
>> DemoCalculationProvider().getCalculation("age", null);
>> int patientId1 = 2;
>>  int patientId2 = 7;
>> Cohort cohort = new Cohort();
>> cohort.addMember(patientId1);
>>  cohort.addMember(patientId2);
>>  Date date = new SimpleDateFormat(TEST_DATE_FORMAT).parse("2000-01-01");
>>  CalculationContext ctxt = getService().createCalculationContext();
>> ctxt.setNow(date);
>>  ParameterDefinition pd =
>> ageCalculation.getParameterDefinitionSet().getParameterByKey("units");
>>  Map<String, Object> values = new HashMap<String, Object>();
>> values.put(pd.getKey(), "months");
>>  CohortResult cr = getService().evaluate(cohort, ageCalculation, values,
>> ctxt);
>>  Assert.assertEquals(296,
>> cr.get(patientId1).asType(Integer.class).intValue());
>> Assert.assertEquals(280,
>> cr.get(patientId2).asType(Integer.class).intValue());
>>  }
>>
>>
>>
>> Any ideas are welcome,
>>
>> Wyclif
>>
>
>

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to 
[email protected] with "SIGNOFF openmrs-devel-l" in the  body (not 
the subject) of your e-mail.

[mailto:[email protected]?body=SIGNOFF%20openmrs-devel-l]

Reply via email to