1104: Calculation logic to determine number of months in period is incorrect

Test Case #:1104


Test Case Name: Calculation logic to determine number of months in period is incorrect

System: openLMIS

Subsystem: blue

Test case designed by: Lucyna Laska

Design Date:09.11.2016

Short description

  • The "Period" domain object should not have any "getTotalDifference" calculations. We don't understand why any method is called "getTotalDifference()" because there is not a difference calculation to be done. Instead it should have a method to return a rounded whole number of months (eg 2 months or 3 months or N months).
  • This code currently calculates the difference according to all periods in the system, not just a single period. This code currently calculates according to months and days, but it should only do months. Every period lives within its one schedule. The calculation we should be doing is how many months are in a period--the duration of the period. This should use rounding logic to determine how many months a period is. Many calculations that depend on this are done based on number of doses per month. So we expect the domain logic should have a way to determine how many months (in round integers) any period is long.
  • The logic should probably be in the ProcessingPeriod/ProcessingSchedule domain layer, rather than in the controller.
  • The minimum duration returned by the method is 1 month (even for the shortest possible period)
  • For the remaining cases, the period duration is rounded to the closest number of whole months, which means a month and a half and more is rounded up to 2 months and less than a month and a half is rounded down to 1 month.

                                                                                                                                                   

Pre – conditions:

                                                                                                                                                                                                                                                       

Step

Action

Expected system response

Comment

1

   Create schedule.

URL:  http://10.222.17.134/referencedata/api/processingSchedules/?access_token=47c06c5e-9581-46a1-b943-4789cf106a20

Method: POST

Body:

{

    "code": "someschedule",

    "name": "nameschedule"

}

                                                                              

                                                                   Schedule has been created successfully.                                                        

                                                 

2

 Create a period when difference between start date and end date is equals to:

  • 1 day.

URL:  http://10.222.17.134/referencedata/api/processingPeriods/?access_token=47c06c5e-9581-46a1-b943-4789cf106a20

Method: POST

Body:

  {

    "name": "Period 012",

    "startDate": "2017-01-01",

    "endDate": "2017-01-02",

    "processingSchedule": { "id": "44b037b3-a3ed-4b26-a4ae-b22b404cb244" }

  }


 

id: 672ced3f-0900-4a14-9fb4-7809ec360a45

 

3

Check the duration for the period above.

URL:  http://10.222.17.134/referencedata/api/processingPeriods/672ced3f-0900-4a14-9fb4-7809ec360a45/duration?access_token=47c06c5e-9581-46a1-b943-4789cf106a20

Method: GET

When the difference between end date and start date is less than 1 month and 15 days, the server will return 1 as a number of month.

 

4

 Create a period when difference between start date and end date is equals to:

 id: 76a05c3e-5dcd-411a-907c-7d70a478c777

 

5

Check the duration for the period above.

URL:   http://10.222.17.134/referencedata/api/processingPeriods/76a05c3e-5dcd-411a-907c-7d70a478c777/duration?access_token=47c06c5e-9581-46a1-b943-4789cf106a20

Method: GET

When the difference between end date and start date is less than 1 month and 15 days, the server will return 1 as a number of month.


 

 

6

 Create a period when difference between start date and end date is equals to:

  • 15 days.

 URL:  http://10.222.17.134/referencedata/api/processingPeriods/?access_token=47c06c5e-9581-46a1-b943-4789cf106a20

Body:

  {

    "name": "Period 015",

    "startDate": "2017-01-18",

    "endDate": "2017-02-02",

    "processingSchedule": { "id": "44b037b3-a3ed-4b26-a4ae-b22b404cb244" }

  }

id: f3492014-f103-42b4-b1bb-9a3303089931

When the difference between end date and start date is less than 1 month and 15 days, the server will return 1 as a number of month

 

7

Check the duration for the period above.

URL:  http://10.222.17.134/referencedata/api/processingPeriods/f3492014-f103-42b4-b1bb-9a3303089931/duration?access_token=647aa169-50ff-43f2-a209-39fde07b91a3

Method: GET

 

When the difference between end date and start date is less than 1 month and 15 days, the server will return 1 as a number of month.

 

8

                            

 Create a period when difference between start date and end date is less than:

  • 1 month and 14 days.

    

   URL:  http://10.222.17.134/referencedata/api/processingPeriods/?access_token=647aa169-50ff-43f2-a209-39fde07b91a3

Body:

  {

    "name": "Period 016",

    "startDate": "2017-03-20",

    "endDate": "2017-05-03",

    "processingSchedule": { "id": "44b037b3-a3ed-4b26-a4ae-b22b404cb244" }

  }

id: 6d82559e-8efb-43ad-947a-23481c120b38



 

9

Check the duration for the period above.

URL:  http://10.222.17.134/referencedata/api/processingPeriods/6d82559e-8efb-43ad-947a-23481c120b38/duration?access_token=647aa169-50ff-43f2-a209-39fde07b91a3

Method: GET

When the difference between end date and start date is less than 1 month and 15 days, the server will return 1 as a number of month.




10

 Create a period when difference between start date and end date is more than:

id: fa56a867-7c3e-4676-be5b-0207cc9a4354


11Check the duration for the period above.


When the difference between end date and start date is more than 1 month and 14 days, the server will return 2 as a number of month.


12

 Create a period when difference between start date and end date is:

  • bigger than 1 year.

URL:  http://10.222.17.134/referencedata/api/processingPeriods/?access_token=ffceb4c8-4296-47df-8c53-8ca402457a9c

Method: POST

Body:

  {

    "name": "Period 013",

    "startDate": "2018-05-19",

    "endDate": "2055-05-18",

    "processingSchedule": { "id": "881e948d-1630-43ff-a8a6-630691b4e79e" }

  }

id: b6b9de17-233b-4b8b-92a6-58fb13f63bd3


13

Check the duration for the period above.

URL:  http://10.222.17.134/referencedata/api/processingPeriods/b6b9de17-233b-4b8b-92a6-58fb13f63bd3/duration?access_token=ffceb4c8-4296-47df-8c53-8ca402457a9c

Method: GET


Post – conditions:

OpenLMIS: the global initiative for powerful LMIS software