Skip to content

Commit

Permalink
U3X-979: Add stock Item Reference UI in the OWA (#8)
Browse files Browse the repository at this point in the history
* U3X-979: Add stock Item Reference UI in the OWA

* esuring that its editable

* Removing duplication saving

* Esnure that Stock source and code are unique per stock source

* Removing deleted

* adding uuid to reference table
  • Loading branch information
slubwama authored Jan 10, 2024
1 parent 8f034a0 commit 3bac14f
Show file tree
Hide file tree
Showing 19 changed files with 1,109 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -537,4 +537,16 @@ <T extends StockItemInventory> void getStockInventory(StockItemInventorySearchFi
@Transactional
@Authorized(Privileges.APP_STOCKMANAGEMENT_STOCKITEMS)
StockItemReference saveStockItemReference(StockItemReference stockItemReference);

@Transactional
@Authorized(Privileges.APP_STOCKMANAGEMENT_STOCKITEMS)
void voidStockItemReference(String uuid, String reason, Integer userId);

@Transactional
@Authorized(Privileges.APP_STOCKMANAGEMENT_STOCKITEMS)
StockItemReference getStockItemReferenceByUuid(String uuid);

@Transactional
@Authorized(Privileges.APP_STOCKMANAGEMENT_STOCKITEMS)
List<StockItemReference> getStockItemReferenceByStockItem(String uuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,17 @@ public void voidStockItemPackagingUOM(String uuid, String reason, int voidedBy)
query.executeUpdate();
}

public void voidStockItemReference(String uuid, String reason, int voidedBy) {
DbSession session = getSession();
Query query = session
.createQuery("UPDATE stockmanagement.StockItemReference SET voided=1, dateVoided=:dateVoided, voidedBy=:voidedBy, voidReason=:reason WHERE uuid = :uuid)");
query.setParameter("uuid", uuid);
query.setDate("dateVoided", new Date());
query.setInteger("voidedBy", voidedBy);
query.setString("reason", reason);
query.executeUpdate();
}

public void voidStockSources(List<String> stockSourceIds, String reason, int voidedBy) {
DbSession session = getSession();
Query query = session
Expand Down Expand Up @@ -5283,4 +5294,16 @@ public StockItemReference saveStockItemReference(StockItemReference stockItemRef
getSession().saveOrUpdate(stockItemReference);
return stockItemReference;
}

public StockItemReference getStockItemReferenceByUuid(String uuid) {
return (StockItemReference) getSession().createCriteria(StockItemReference.class).add(Restrictions.eq("uuid", uuid))
.uniqueResult();
}

public List<StockItemReference> getStockItemReferenceByStockItem(StockItem stockItem) {
Criteria criteria = getSession().createCriteria(StockItemReference.class);
criteria.add(Restrictions.eq("stockItem", stockItem));
criteria.add(Restrictions.eq("voided", false));
return criteria.list();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.openmrs.module.stockmanagement.api.dto;

public class StockItemReferenceDTO {

private Integer id;

private String uuid;

private boolean voided;

private String referenceCode;

private int stockSourceId;

private String stockSourceUuid;

private String stockSourceName;

private int stockItemId;

private String stockItemUuid;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public boolean isVoided() {
return voided;
}

public void setVoided(boolean voided) {
this.voided = voided;
}

public String getReferenceCode() {
return referenceCode;
}

public void setReferenceCode(String referenceCode) {
this.referenceCode = referenceCode;
}

public int getStockSourceId() {
return stockSourceId;
}

public void setStockSourceId(int stockSourceId) {
this.stockSourceId = stockSourceId;
}

public String getStockSourceUuid() {
return stockSourceUuid;
}

public void setStockSourceUuid(String stockSourceUuid) {
this.stockSourceUuid = stockSourceUuid;
}

public String getStockSourceName() {
return stockSourceName;
}

public void setStockSourceName(String stockSourceName) {
this.stockSourceName = stockSourceName;
}

public int getStockItemId() {
return stockItemId;
}

public void setStockItemId(int stockItemId) {
this.stockItemId = stockItemId;
}

public String getStockItemUuid() {
return stockItemUuid;
}

public void setStockItemUuid(String stockItemUuid) {
this.stockItemUuid = stockItemUuid;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package org.openmrs.module.stockmanagement.api.dto;

import java.util.List;

public class StockItemReferenceSearchFilter {

private String uuid;

private List<String> stockItemUuids;

private List<Integer> stockItemIds;

private boolean includeVoided;

private boolean includeDispensingUnit;

private Integer startIndex;

private Integer limit;

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public List<String> getStockItemUuids() {
return stockItemUuids;
}

public void setStockItemUuids(List<String> stockItemUuids) {
this.stockItemUuids = stockItemUuids;
}

public List<Integer> getStockItemIds() {
return stockItemIds;
}

public void setStockItemIds(List<Integer> stockItemIds) {
this.stockItemIds = stockItemIds;
}

public boolean isIncludeVoided() {
return includeVoided;
}

public boolean getIncludeVoided() {
return includeVoided;
}

public void setIncludeVoided(boolean includeVoided) {
this.includeVoided = includeVoided;
}

public Integer getStartIndex() {
return startIndex;
}

public void setStartIndex(Integer startIndex) {
this.startIndex = startIndex;
}

public Integer getLimit() {
return limit;
}

public void setLimit(Integer limit) {
this.limit = limit;
}

public boolean includingDispensingUnit() {
return includeDispensingUnit;
}

public void setIncludeDispensingUnit(boolean includeDispensingUnit) {
this.includeDispensingUnit = includeDispensingUnit;
}

public static class ItemGroupFilter {

private Integer stockItemId;

private List<Integer> packagingUomIds;

public ItemGroupFilter() {
}

public ItemGroupFilter(Integer stockItemId, List<Integer> packagingUomIds) {
this.stockItemId = stockItemId;
this.packagingUomIds = packagingUomIds;
}

public Integer getStockItemId() {
return stockItemId;
}

public void setStockItemId(Integer stockItemId) {
this.stockItemId = stockItemId;
}

public List<Integer> getPackagingUomIds() {
return packagingUomIds;
}

public void setPackagingUomIds(List<Integer> packagingUomIds) {
this.packagingUomIds = packagingUomIds;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

ItemGroupFilter that = (ItemGroupFilter) o;

if (stockItemId != null ? !stockItemId.equals(that.stockItemId) : that.stockItemId != null)
return false;
return !(packagingUomIds != null ? !packagingUomIds.equals(that.packagingUomIds) : that.packagingUomIds != null);

}

@Override
public int hashCode() {
int result = stockItemId != null ? stockItemId.hashCode() : 0;
result = 31 * result + (packagingUomIds != null ? packagingUomIds.hashCode() : 0);
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.openmrs.notification.Alert;
import org.openmrs.notification.Template;
import org.openmrs.util.OpenmrsConstants;
import org.springframework.util.Assert;

import javax.mail.Session;
import java.math.BigDecimal;
Expand Down Expand Up @@ -3447,4 +3448,25 @@ public StockItem getStockItemByReference(StockSource stockSource, String code) {
public StockItemReference saveStockItemReference(StockItemReference stockItemReference) {
return dao.saveStockItemReference(stockItemReference);
}

@Override
public void voidStockItemReference(String uuid, String reason, Integer userId) {
dao.voidStockItemReference(uuid, reason, userId);
}

@Override
public StockItemReference getStockItemReferenceByUuid(String uuid) {
return dao.getStockItemReferenceByUuid(uuid);
}

@Override
public List<StockItemReference> getStockItemReferenceByStockItem(String uuid) {

StockItem stockItem= getStockItemByUuid(uuid);
if(stockItem!=null) {
return dao.getStockItemReferenceByStockItem(stockItem);
}else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class StockItem extends org.openmrs.BaseChangeableOpenmrsData implements
private Set<StockItemPackagingUOM> stockItemPackagingUOMs;

@OneToMany(mappedBy = "stockItem", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<StockItemReference> stockItemReferences;
private Set<StockItemReference> references;

@Field
@Column(name = "is_drug", nullable = false)
Expand Down Expand Up @@ -185,25 +185,25 @@ public StockItemPackagingUOM removeStockItemPackagingUom(StockItemPackagingUOM s
return stockItemPackagingUom;
}

public Set<StockItemReference> getStockItemReferences() {
return stockItemReferences;
public Set<StockItemReference> getReferences() {
return references;
}

public void setStockItemReferences(Set<StockItemReference> stockItemReferences) {
this.stockItemReferences = stockItemReferences;
public void setStockItemReferences(Set<StockItemReference> references) {
this.references = references;
}

public StockItemReference addStockItemReference(StockItemReference stockItemReference) {
getStockItemReferences().add(stockItemReference);
stockItemReference.setStockItem(this);
public StockItemReference addStockItemReference(StockItemReference reference) {
getReferences().add(reference);
reference.setStockItem(this);

return stockItemReference;
return reference;
}

public StockItemReference removeStockItemReferences(StockItemReference stockItemReference) {
getStockItemReferences().remove(stockItemReference);
stockItemReference.setStockItem(null);
return stockItemReference;
public StockItemReference removeStockItemReferences(StockItemReference reference) {
getReferences().remove(reference);
reference.setStockItem(null);
return reference;
}

public boolean isHasExpiration() {
Expand Down
Loading

0 comments on commit 3bac14f

Please sign in to comment.