Optional animal
This commit is contained in:
@@ -76,7 +76,7 @@ class DrugWithVariantsResponse(BaseModel):
|
|||||||
class DispensingCreate(BaseModel):
|
class DispensingCreate(BaseModel):
|
||||||
drug_variant_id: int
|
drug_variant_id: int
|
||||||
quantity: float
|
quantity: float
|
||||||
animal_name: str
|
animal_name: Optional[str] = None
|
||||||
user_name: str
|
user_name: str
|
||||||
notes: Optional[str] = None
|
notes: Optional[str] = None
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ class DispensingResponse(BaseModel):
|
|||||||
id: int
|
id: int
|
||||||
drug_variant_id: int
|
drug_variant_id: int
|
||||||
quantity: float
|
quantity: float
|
||||||
animal_name: str
|
animal_name: Optional[str] = None
|
||||||
user_name: str
|
user_name: str
|
||||||
notes: Optional[str] = None
|
notes: Optional[str] = None
|
||||||
dispensed_at: datetime
|
dispensed_at: datetime
|
||||||
|
|||||||
@@ -223,18 +223,41 @@ async function handleAddDrug(e) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_URL}/drugs`, {
|
// Create the drug first
|
||||||
|
const drugResponse = await fetch(`${API_URL}/drugs`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(drugData)
|
body: JSON.stringify(drugData)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) throw new Error('Failed to add drug');
|
if (!drugResponse.ok) throw new Error('Failed to add drug');
|
||||||
|
const createdDrug = await drugResponse.json();
|
||||||
|
|
||||||
|
// Check if initial variant data was provided
|
||||||
|
const variantStrength = document.getElementById('initialVariantStrength').value.trim();
|
||||||
|
if (variantStrength) {
|
||||||
|
const variantData = {
|
||||||
|
strength: variantStrength,
|
||||||
|
quantity: parseFloat(document.getElementById('initialVariantQuantity').value) || 0,
|
||||||
|
unit: document.getElementById('initialVariantUnit').value || 'units',
|
||||||
|
low_stock_threshold: parseFloat(document.getElementById('initialVariantThreshold').value) || 10
|
||||||
|
};
|
||||||
|
|
||||||
|
const variantResponse = await fetch(`${API_URL}/drugs/${createdDrug.id}/variants`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(variantData)
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!variantResponse.ok) throw new Error('Failed to add variant');
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById('drugForm').reset();
|
document.getElementById('drugForm').reset();
|
||||||
|
document.getElementById('initialVariantUnit').value = 'units';
|
||||||
|
document.getElementById('initialVariantThreshold').value = '10';
|
||||||
closeModal(document.getElementById('addModal'));
|
closeModal(document.getElementById('addModal'));
|
||||||
await loadDrugs();
|
await loadDrugs();
|
||||||
alert('Drug added successfully! Now add variants for this drug.');
|
alert('Drug added successfully!');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error adding drug:', error);
|
console.error('Error adding drug:', error);
|
||||||
alert('Failed to add drug. Check the console for details.');
|
alert('Failed to add drug. Check the console for details.');
|
||||||
@@ -251,8 +274,8 @@ async function handleDispenseDrug(e) {
|
|||||||
const userName = document.getElementById('dispenseUser').value;
|
const userName = document.getElementById('dispenseUser').value;
|
||||||
const notes = document.getElementById('dispenseNotes').value;
|
const notes = document.getElementById('dispenseNotes').value;
|
||||||
|
|
||||||
if (!variantId || !quantity || !animalName || !userName) {
|
if (!variantId || isNaN(quantity) || quantity <= 0 || !userName) {
|
||||||
alert('Please fill in all required fields');
|
alert('Please fill in all required fields (Drug Variant, Quantity > 0, Dispensed by)');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,7 +381,13 @@ async function handleAddVariant(e) {
|
|||||||
|
|
||||||
// Open edit variant modal
|
// Open edit variant modal
|
||||||
function openEditVariantModal(variantId) {
|
function openEditVariantModal(variantId) {
|
||||||
const variant = currentDrug.variants.find(v => v.id === variantId);
|
// Find the variant from all drugs
|
||||||
|
let variant = null;
|
||||||
|
for (const drug of allDrugs) {
|
||||||
|
variant = drug.variants.find(v => v.id === variantId);
|
||||||
|
if (variant) break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!variant) return;
|
if (!variant) return;
|
||||||
|
|
||||||
document.getElementById('editVariantId').value = variant.id;
|
document.getElementById('editVariantId').value = variant.id;
|
||||||
|
|||||||
@@ -83,6 +83,29 @@
|
|||||||
<input type="text" id="drugDescription">
|
<input type="text" id="drugDescription">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr style="margin: 20px 0; border: none; border-top: 1px solid #ddd;">
|
||||||
|
<h3 style="margin-top: 0;">Initial Variant (Optional)</h3>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="initialVariantStrength">Strength</label>
|
||||||
|
<input type="text" id="initialVariantStrength" placeholder="e.g., 10mg, 5.4mg">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="initialVariantQuantity">Quantity</label>
|
||||||
|
<input type="number" id="initialVariantQuantity" placeholder="0" min="0" step="0.1">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="initialVariantUnit">Unit</label>
|
||||||
|
<input type="text" id="initialVariantUnit" placeholder="e.g., tablets, capsules, vials" value="units">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="initialVariantThreshold">Low Stock Threshold</label>
|
||||||
|
<input type="number" id="initialVariantThreshold" placeholder="0" min="0" step="0.1" value="10">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="submit" class="btn btn-primary">Add Drug</button>
|
<button type="submit" class="btn btn-primary">Add Drug</button>
|
||||||
<button type="button" class="btn btn-secondary" id="cancelAddBtn">Cancel</button>
|
<button type="button" class="btn btn-secondary" id="cancelAddBtn">Cancel</button>
|
||||||
@@ -96,27 +119,27 @@
|
|||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<span class="close">×</span>
|
<span class="close">×</span>
|
||||||
<h2>Dispense Drug</h2>
|
<h2>Dispense Drug</h2>
|
||||||
<form id="dispenseForm">
|
<form id="dispenseForm" novalidate>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="dispenseDrugSelect">Drug Variant *</label>
|
<label for="dispenseDrugSelect">Drug Variant *</label>
|
||||||
<select id="dispenseDrugSelect" required>
|
<select id="dispenseDrugSelect">
|
||||||
<option value="">-- Select a drug variant --</option>
|
<option value="">-- Select a drug variant --</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="dispenseQuantity">Quantity *</label>
|
<label for="dispenseQuantity">Quantity *</label>
|
||||||
<input type="number" id="dispenseQuantity" step="0.1" required>
|
<input type="number" id="dispenseQuantity" step="0.1">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="dispenseAnimal">Animal Name/ID *</label>
|
<label for="dispenseAnimal">Animal Name/ID</label>
|
||||||
<input type="text" id="dispenseAnimal" required>
|
<input type="text" id="dispenseAnimal">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="dispenseUser">User Name *</label>
|
<label for="dispenseUser">Dispensed by *</label>
|
||||||
<input type="text" id="dispenseUser" required>
|
<input type="text" id="dispenseUser">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|||||||
Reference in New Issue
Block a user