Skip to content

Commit

Permalink
Merge pull request #284 from NUS-Project-SaBai/orders/add-diagnoses-col
Browse files Browse the repository at this point in the history
Orders: Added Diagnoses Column
  • Loading branch information
nathantew14 authored Dec 4, 2024
2 parents 2251bbf + cdd1345 commit 82749af
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
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

0 comments on commit 82749af

Please sign in to comment.