Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #43 from OpenLMIS/dev
Browse files Browse the repository at this point in the history
Release Canidate for v1.0
  • Loading branch information
joshzamor committed Jun 13, 2015
2 parents 5044874 + bd3f1bf commit f1cb485
Show file tree
Hide file tree
Showing 141 changed files with 4,639 additions and 420 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ test-modules/functional-tests/src/main/resources/**/*.png
build.gradle.swp
node_modules/
modules/openlmis-web/src/test/coverage/
modules/openlmis-web/src/test/karma/
local-ftp-data/
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ subprojects {
'commons-io:commons-io:2.4'


testCompile 'junit:junit:4.8.2',
testCompile 'org.hamcrest:hamcrest-all:1.3',
'org.mockito:mockito-all:1.9.5',
'org.hamcrest:hamcrest-all:1.3',
'junit:junit:4.8.2',
'cglib:cglib:2.2.2',
'org.powermock:powermock-mockito-release-full:1.5',
'com.natpryce:make-it-easy:3.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ public abstract class BaseModel {
public BaseModel(Long id) {
this.id = id;
}

/**
* Determines if this BaseModel has an id set or not.
* @return true if it has an id set, false otherwise
*/
public boolean hasId() {
return id != null ? true : false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.openlmis.core.exception.DataException;
import org.openlmis.upload.Importable;
import org.openlmis.upload.annotation.ImportField;

/**
* DosageUnit represents the Dosage Unit for any product.
Expand All @@ -22,7 +25,20 @@
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class DosageUnit extends BaseModel {
public class DosageUnit extends BaseModel implements Importable {
@ImportField(mandatory = true, name="Dosage Unit Code")
private String code;

@ImportField(mandatory = true, name="Display Order")
private int displayOrder;

/**
* Validation method for an instantiated DosageUnit. A valid dosage unit has a code and a display order.
* @throws DataException if this dosage unit is not defined well.
*/
public void isValid() {
if (code == null
|| code.length() == 0
|| displayOrder <= 0 ) throw new DataException("error.reference.data.missing");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.openlmis.upload.Importable;
import org.openlmis.upload.annotation.ImportField;

/**
* FacilityOperator represents the operator for facility, the authority responsible for running a facility (for eg. WHO, MOH etc.)
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class FacilityOperator extends BaseModel {
public class FacilityOperator extends BaseModel implements Importable {
@ImportField(name="Facility Operator Code", mandatory=true)
private String code;

@ImportField(name="Name", mandatory=true)
private String text;

@ImportField(name="Display Order", mandatory=true)
private Integer displayOrder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public ProductGroup getActiveProductGroup() {
return null;
}

/**
* Calculates the ideal stock amount (ISA) the facility should be stocked to
* with the associated product.
* @param population the population of the facility that will be served by the
* product's stock.
* @param numberOfMonthsInPeriod the number of months the ideal stock amount
* will need to serve the facility.
* @return the ideal stock amount of the associated product for the associated
* facility or null if the ISA is not calculable.
*/
public Integer calculateIsa(Long population, Integer numberOfMonthsInPeriod) {
Integer idealQuantity;
if (this.overriddenIsa != null)
Expand All @@ -63,10 +73,25 @@ else if (this.programProductIsa == null || population == null)
else
idealQuantity = this.programProductIsa.calculate(population);

idealQuantity = Math.round(idealQuantity * ((float) numberOfMonthsInPeriod / this.getProduct().getPackSize()));
idealQuantity = idealQuantity * numberOfMonthsInPeriod;
return idealQuantity < 0 ? 0 : idealQuantity;
}

/**
* Calculates the ideal stock amount (ISA) in terms of pack size. i.e. the
* number of whole deliverable units that a facility would be stocked to for the associated
* product.
* @return the number of whole deliverable units of the associated product that meets or
* exceeds the ISA or null if the ISA is not calculable.
* @see #calculateIsa(Long, Integer)
*/
public Integer calculateIsaByPackSize(Long population, Integer numberOfMonthsInPeriod) {
Integer idealQuantity = calculateIsa(population, numberOfMonthsInPeriod);
if (idealQuantity == null) return null;

return new Double(Math.ceil( (float) idealQuantity / this.getProduct().getPackSize() )).intValue();
}

@JsonIgnore
public Double getWhoRatio(String productCode) {
ProgramProductISA programProductIsa = this.getProgramProductIsa();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.openlmis.upload.Importable;
import org.openlmis.upload.annotation.ImportField;

import static org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_EMPTY;

Expand All @@ -25,14 +27,29 @@
@NoArgsConstructor
@JsonSerialize(include = NON_EMPTY)
@EqualsAndHashCode(callSuper = false)
public class FacilityType extends BaseModel {
public class FacilityType extends BaseModel implements Importable {

@ImportField(name="Facility Type Code", mandatory=true)
private String code;

@ImportField(name="Name", mandatory=true)
private String name;

@ImportField(name="Description")
private String description;

private Integer levelId;

@ImportField(name="Nominal Max Month", mandatory=true)
private Integer nominalMaxMonth;

@ImportField(name="Nominal EOP", mandatory=true)
private Double nominalEop;

@ImportField(name="Display Order", mandatory=true)
private Integer displayOrder;

@ImportField(name="Active", mandatory=true, type="boolean")
private boolean active;

public FacilityType(String code) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import lombok.NoArgsConstructor;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.openlmis.upload.Importable;
import org.openlmis.upload.annotation.ImportField;

import static org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_EMPTY;

Expand All @@ -28,10 +30,17 @@
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@JsonSerialize(include = NON_EMPTY)
public class GeographicLevel extends BaseModel {
public class GeographicLevel extends BaseModel implements Importable {

@ImportField(name="Geographic Level Code", mandatory = true)
String code;

@ImportField(name="Name", mandatory = true)
String name;

@ImportField(name="Level Number", mandatory = true)
Integer levelNumber;

private static Integer ROOT_LEVEL_NUMBER = 1;

public GeographicLevel(Long id, String code, String name, Integer levelNumber) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.openlmis.core.exception.DataException;
import org.openlmis.upload.Importable;
import org.openlmis.upload.annotation.ImportField;

/**
* ProductForm represents real world entity for product form.
Expand All @@ -22,7 +25,20 @@
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class ProductForm extends BaseModel {
public class ProductForm extends BaseModel implements Importable {
@ImportField(name="Product Form Code", mandatory=true)
private String code;
private int displayOrder;

@ImportField(name="Display Order", mandatory=true)
private Integer displayOrder;

/**
* Validates this product form.
* @throws DataException if this object is not well-formed.
*/
public void isValid() {
if (code == null
|| code.length() == 0
|| displayOrder == null) throw new DataException("error.reference.data.missing");
}
}
22 changes: 19 additions & 3 deletions modules/core/src/main/java/org/openlmis/core/domain/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.openlmis.upload.Importable;
import org.openlmis.upload.annotation.ImportField;

import static org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_EMPTY;

Expand All @@ -26,15 +29,28 @@
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@JsonSerialize(include = NON_EMPTY)
public class Program extends BaseModel {
public class Program extends BaseModel implements Importable {

@ImportField(name="Program Code", mandatory=true)
private String code;

@ImportField(name="Name", mandatory=true)
private String name;

@ImportField(name="Description")
private String description;
private Boolean active;
private Boolean budgetingApplies;

@ImportField(name="Active", mandatory=true, type="boolean")
private Boolean active = true;

@ImportField(name="Budgeting Applies", type="boolean")
private Boolean budgetingApplies = false;

private boolean templateConfigured;

private boolean regimenTemplateConfigured;

@ImportField(name="Push", mandatory=true, type="boolean")
private boolean push;

public Program(Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.openlmis.upload.Importable;
import org.openlmis.upload.annotation.ImportField;

/**
* RegimenCategory represents category for a regimen (for eg. Adult or Child)
Expand All @@ -22,10 +24,15 @@
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class RegimenCategory extends BaseModel {
public class RegimenCategory extends BaseModel implements Importable {

@ImportField(name="Regimen Category Code", mandatory=true)
private String code;

@ImportField(name="Name", mandatory=true)
private String name;

@ImportField(name="Display Order", mandatory=true)
private Integer displayOrder;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* This program is part of the OpenLMIS logistics management information system platform software.
* Copyright © 2013 VillageReach
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*  
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses.  For additional information contact [email protected]
*/

package org.openlmis.core.repository;

import lombok.NoArgsConstructor;
import org.openlmis.core.domain.DosageUnit;
import org.openlmis.core.exception.DataException;
import org.openlmis.core.repository.mapper.DosageUnitMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Repository;

@Repository
@NoArgsConstructor
public class DosageUnitRepository {

private DosageUnitMapper duMapper;

@Autowired
public DosageUnitRepository(DosageUnitMapper dosageUnitMapper) {
this.duMapper = dosageUnitMapper;
}

public DosageUnit getByCode(String code) {
return duMapper.getByCode(code);
}

public DosageUnit getExisting(DosageUnit du) {
return duMapper.getByCode(du.getCode());
}

public void insert(DosageUnit du) {
du.isValid();
if(getByCode(du.getCode()) != null) throw new DataException("error.duplicate.dosage.unit.code");

try {
duMapper.insert(du);
} catch(DataIntegrityViolationException dive) {
throw new DataException("error.incorrect.length", dive);
}
}

public void update(DosageUnit du) {
duMapper.update(du);
}
}
Loading

0 comments on commit f1cb485

Please sign in to comment.