Add drug
This commit is contained in:
@@ -1612,36 +1612,14 @@ async function handleAddDrug(e) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create the drug first
|
|
||||||
const drugResponse = await apiCall('/drugs', {
|
const drugResponse = await apiCall('/drugs', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(drugData)
|
body: JSON.stringify(drugData)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!drugResponse.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 apiCall(`/drugs/${createdDrug.id}/variants`, {
|
|
||||||
method: 'POST',
|
|
||||||
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();
|
||||||
showToast('Drug added successfully!', 'success');
|
showToast('Drug added successfully!', 'success');
|
||||||
|
|||||||
@@ -138,36 +138,6 @@
|
|||||||
</label>
|
</label>
|
||||||
</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>
|
|
||||||
<select id="initialVariantUnit">
|
|
||||||
<option value="tablets">Tablets</option>
|
|
||||||
<option value="bottles">Bottles</option>
|
|
||||||
<option value="boxes">Boxes</option>
|
|
||||||
<option value="vials">Vials</option>
|
|
||||||
<option value="units">Units</option>
|
|
||||||
<option value="packets">Packets</option>
|
|
||||||
</select>
|
|
||||||
</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>
|
||||||
|
|||||||
Reference in New Issue
Block a user