diff --git a/cypress/pageobject/Patient/PatientInvestigation.ts b/cypress/pageobject/Patient/PatientInvestigation.ts index c226c358676..8f73cf908bc 100644 --- a/cypress/pageobject/Patient/PatientInvestigation.ts +++ b/cypress/pageobject/Patient/PatientInvestigation.ts @@ -10,7 +10,7 @@ class PatientInvestigation { } selectInvestigation(investigation: string) { - cy.get("#search-patient-investigation").click(); + cy.get("#search-patient-investigation").type(investigation); cy.verifyAndClickElement("#investigation-group", investigation); cy.verifyAndClickElement("#investigation", "Investigation No. 1"); } diff --git a/src/CAREUI/interactive/FiltersSlideover.tsx b/src/CAREUI/interactive/FiltersSlideover.tsx index 83f92e2bd90..496f1b3e516 100644 --- a/src/CAREUI/interactive/FiltersSlideover.tsx +++ b/src/CAREUI/interactive/FiltersSlideover.tsx @@ -58,7 +58,7 @@ export const AdvancedFilterButton = ({ onClick }: { onClick: () => void }) => { diff --git a/src/Common/constants.tsx b/src/Common/constants.tsx index f0d0ab08f04..5c09b0fd201 100644 --- a/src/Common/constants.tsx +++ b/src/Common/constants.tsx @@ -1370,3 +1370,18 @@ export const PATIENT_NOTES_THREADS = { } as const; export const RATION_CARD_CATEGORY = ["BPL", "APL", "NO_CARD"] as const; + +export const DEFAULT_ALLOWED_EXTENSIONS = [ + "image/*", + "video/*", + "audio/*", + "text/plain", + "text/csv", + "application/rtf", + "application/msword", + "application/vnd.oasis.opendocument.text", + "application/pdf", + "application/vnd.ms-excel", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "application/vnd.oasis.opendocument.spreadsheet,application/pdf", +]; diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx index 796e532a41e..f6f83e7030f 100644 --- a/src/Components/Assets/AssetsList.tsx +++ b/src/Components/Assets/AssetsList.tsx @@ -105,40 +105,63 @@ const AssetsList = () => { prefetch: !!(qParams.facility && qParams.location), }); - const getAssetIdFromQR = async (assetUrl: string) => { + function isValidURL(url: string) { + try { + new URL(url); + return true; + } catch (_) { + return false; + } + } + + const accessAssetIdFromQR = async (assetURL: string) => { try { setIsLoading(true); setIsScannerActive(false); - const params = parseQueryParams(assetUrl); + if (!isValidURL(assetURL)) { + setIsLoading(false); + Notification.Error({ + msg: "Invalid QR code scanned !!!", + }); + return; + } + const params = parseQueryParams(assetURL); // QR Maybe searchParams "asset" or "assetQR" + // If no params found, then use assetText const assetId = params.asset || params.assetQR; + if (assetId) { - const { data } = await request(routes.listAssets, { - query: { qr_code_id: assetId }, + const { data } = await request(routes.listAssetQR, { + pathParams: { qr_code_id: assetId }, + }); + if (!data) { + setIsLoading(false); + Notification.Error({ + msg: "Invalid QR code scanned !!!", + }); + return; + } + const { data: assetData } = await request(routes.listAssets, { + query: { qr_code_id: assetId, limit: 1 }, + }); + if (assetData?.results.length === 1) { + navigate( + `/facility/${assetData.results[0].location_object.facility?.id}/assets/${assetData.results[0].id}`, + ); + } else { + setIsLoading(false); + Notification.Error({ + msg: "Asset not found !!!", + }); + } + } else { + setIsLoading(false); + Notification.Error({ + msg: "Invalid QR code scanned !!!", }); - return data?.results[0].id; - } - } catch (err) { - console.log(err); - } - }; - - const checkValidAssetId = async (assetId: string) => { - const { data: assetData } = await request(routes.getAsset, { - pathParams: { external_id: assetId }, - }); - try { - if (assetData) { - navigate( - `/facility/${assetData.location_object.facility?.id}/assets/${assetId}`, - ); } } catch (err) { console.log(err); - setIsLoading(false); - Notification.Error({ - msg: "Invalid QR code scanned !!!", - }); } }; @@ -159,8 +182,7 @@ const AssetsList = () => { { if (text) { - const assetId = await getAssetIdFromQR(text); - checkValidAssetId(assetId ?? text); + await accessAssetIdFromQR(text); } }} onError={(e) => { diff --git a/src/Components/Common/FilePreviewDialog.tsx b/src/Components/Common/FilePreviewDialog.tsx index 9bf9780c7a3..b4443d330ea 100644 --- a/src/Components/Common/FilePreviewDialog.tsx +++ b/src/Components/Common/FilePreviewDialog.tsx @@ -32,6 +32,19 @@ type FilePreviewProps = { fixedWidth?: boolean; }; +const previewExtensions = [ + ".html", + ".htm", + ".pdf", + ".mp4", + ".webm", + ".jpg", + ".jpeg", + ".png", + ".gif", + ".webp", +]; + const FilePreviewDialog = (props: FilePreviewProps) => { const { show, onClose, file_state, setFileState, downloadURL, fileUrl } = props; @@ -130,13 +143,21 @@ const FilePreviewDialog = (props: FilePreviewProps) => { }} pageNumber={page} /> - ) : ( + ) : previewExtensions.includes(file_state.extension) ? (