Thanks for the update on your progress with Logic 2.0 (aka Calculation), Wyclif. Can we use calculationProvider.*getCalculation()* instead of calculationProvider.*getCalculationInstance()*?
-Burke On Thu, Feb 16, 2012 at 7:03 PM, Wyclif Luyima <[email protected]> wrote: > Hi all, > > On Wednesday i completed the token registration CRUD methods and their > unit tests, i know we said this was for a later date, but i was already > done with 90% of the work, so i just decided to complete and commit it. > > Later yesterday(Wednesday) i wrote up the 3 tests outlined on the design > call along with a TestCalculationProvider and an AgeCalculator, i wrote > afew just for the start, i created a review for them where i added mike and > darius. Mike added some comments which i addressed this morning. Sorry I > got a little confused because darius said he preferred that i include the > tests in the email while preferred that i used crucible reviews probably we > need to decide on this. > > Today i have been coding up the the test calculation, evaluator, > provider, the evaluations service methods and wiring everything to get the > tests passing. > > The implementation for my TestCalculationProivider is that it has a > private map of calculationNames and Classes which takes the the form > '<String, Class<? extends Calculation>>', the map is populated from the > constructor of the provider. Typically when its getCalculationInstance() > method is called, it looks up the Class mapped to the key, creates an > instance of it and returns it. > > Below are the tests that i added and trying to get passing: > > > public void shouldCalculateThePatientAge() { > CalculationProvider p = new TestCalculationProvider(); > Calculation ageCalculation = p.getCalculationInstance("age", null); > int patientId = 2; > int expected = Context.getPatientService().getPatient(patientId).getAge(); > Assert.assertEquals(expected, service.evaluate(patientId, > ageCalculation).asType(Integer.class).intValue()); > } > public void shouldCalculateThePatientAgeBasedOnContextualInfo() throws > ParseException { > CalculationProvider p = new TestCalculationProvider(); > Calculation ageCalculation = p.getCalculationInstance("age", null); > > int patientId = 2; > Date date = new SimpleDateFormat(DATE_FORMAT).parse("2000-01-01"); > CalculationContext ctxt = service.createCalculationContext(); > ctxt.setIndexDate(date); > int expected = > Context.getPatientService().getPatient(patientId).getAge(date); > Assert.assertEquals(expected, service.evaluate(patientId, ageCalculation, > ctxt).asType(Integer.class).intValue()); > } > public void > shouldCalculateThePatientAgeBasedOnContextualInfoAndParameterValues() > throws ParseException { > CalculationProvider p = new TestCalculationProvider(); > Calculation ageCalculation = p.getCalculationInstance("age", null); > ParameterDefinitionSet pds = ageCalculation.getParameterDefinitionsSet(); > ParameterDefinition pd = pds.getParameterByKey("units"); > Assert.assertNotNull(pd); > Assert.assertEquals(pd.getName(), "Units Of Age"); > int patientId = 2; > Date date = new SimpleDateFormat(DATE_FORMAT).parse("2000-01-01"); > CalculationContext ctxt = service.createCalculationContext(); > ctxt.setIndexDate(date); > Map<String, Object> values = new HashMap<String, Object>(); > values.put("units", "months"); > Assert.assertEquals(296, service.evaluate(patientId, ageCalculation, > values, ctxt).asType(Integer.class).intValue()); > } > > > 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]

