Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orders: Added Diagnoses Column #284

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions components/records/PrescriptionsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export function PrescriptionsTable({ prescriptions }) {
<td className="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
{quantity}
</td>
<td className="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
{prescription.notes}
</td>
<td className="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
{status}
</td>
Expand Down Expand Up @@ -60,6 +63,12 @@ export function PrescriptionsTable({ prescriptions }) {
>
Quantity
</th>
<th
scope="col"
className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900"
>
Dosage Instructions
</th>
<th
scope="col"
className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900"
Expand Down
44 changes: 39 additions & 5 deletions pages/pharmacy/orders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import SearchField from '@/components/TextComponents/SearchField';

const Orders = () => {
const [orders, setOrders] = useState([]);
const [diagnoses, setDiagnoses] = useState([]);
const [searchBy, setSearchBy] = useState('');
const [villageCode, setVillageCode] = useCachedVillageCode();

useEffect(() => {
loadPendingOrders();
loadDiagnoses();
}, []);

function filterByVillage() {
Expand All @@ -45,6 +47,16 @@ const Orders = () => {
const ordersFilteredByVillage = filterByVillage();
const ordersFilteredById = filterById();

const loadDiagnoses = useWithLoading(async () => {
try {
const { data: diagnoses } = await axiosInstance.get('/diagnosis');
setDiagnoses(diagnoses);
} catch (error) {
toast.error(`Failed to fetch diagnoses: ${error.message}`);
console.error('Error loading diagnoses:', error);
}
});

const loadPendingOrders = useWithLoading(async () => {
try {
const { data: orders } = await axiosInstance.get(
Expand Down Expand Up @@ -96,10 +108,8 @@ const Orders = () => {
{order.medication_review.medicine.medicine_name || ''}:{' '}
{Math.abs(order.medication_review.quantity_changed)}
<br />
{order.medication_review.medicine.notes && (
<div className="truncate">
Notes: {order.medication_review.medicine.notes}
</div>
{order.notes && (
<div className="truncate">Dosage Instructions: {order.notes}</div>
)}
</li>
);
Expand Down Expand Up @@ -127,6 +137,24 @@ const Orders = () => {
<td className="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
<ul>{prescriptions}</ul>
</td>
<td className="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
<ul>
{diagnoses
.filter(
// Filter by consult
diagnosis => {
return diagnosis.consult.id === order.consult;
}
)
.map((diagnosis, index) => (
<li key={diagnosis.id}>
<b>Diagnosis {index + 1}</b>
<p>Category: {diagnosis.category}</p>
<p>Notes: {diagnosis.details}</p>
</li>
))}
</ul>
</td>
<td className="whitespace-nowrap px-3 py-4 text-sm text-gray-500 space-x-2">
<Button
colour="green"
Expand Down Expand Up @@ -181,7 +209,13 @@ const Orders = () => {
scope="col"
className="px-3 py-3.5 text-left text-base font-semibold text-gray-900"
>
Record
Dosage
</th>
<th
scope="col"
className="px-3 py-3.5 text-left text-base font-semibold text-gray-900"
>
Diagnoses
</th>
<th
scope="col"
Expand Down
6 changes: 6 additions & 0 deletions pages/records/patient-consultation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ const PatientConsultation = () => {
return;
}

// Ensure Dosage Instructions is non-empty
if (!orderFormDetails.notes || orderFormDetails.notes === '') {
toast.error('Please enter Dosage Instructions.');
return;
}

// get pending quantity of medicine requested
const pendingQuantity = await axiosInstance
.get(`/medications/${orderFormDetails.medicine}?order_status=PENDING`)
Expand Down
Loading