diff --git a/package.json b/package.json index aa07b94..de9cca7 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "@headlessui/react": "^2.0.4", "@hookform/resolvers": "^3.3.1", + "@radix-ui/react-avatar": "^1.1.1", "@radix-ui/react-collapsible": "^1.1.0", "@radix-ui/react-dialog": "^1.0.4", "@radix-ui/react-icons": "^1.3.0", @@ -38,7 +39,7 @@ "jsonwebtoken": "^9.0.2", "jwt-decode": "^3.1.2", "lucide-react": "^0.271.0", - "next": "14.2.13", + "next": "14.2.14", "next-auth": "beta", "nextjs-toploader": "^1.6.12", "postcss": "8.4.29", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eb41d9b..44db452 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ dependencies: '@hookform/resolvers': specifier: ^3.3.1 version: 3.3.1(react-hook-form@7.45.4) + '@radix-ui/react-avatar': + specifier: ^1.1.1 + version: 1.1.1(@types/react-dom@18.2.7)(@types/react@18.2.21)(react-dom@18.3.1)(react@18.3.1) '@radix-ui/react-collapsible': specifier: ^1.1.0 version: 1.1.0(@types/react-dom@18.2.7)(@types/react@18.2.21)(react-dom@18.3.1)(react@18.3.1) @@ -93,14 +96,14 @@ dependencies: specifier: ^0.271.0 version: 0.271.0(react@18.3.1) next: - specifier: 14.2.13 - version: 14.2.13(@babel/core@7.22.11)(react-dom@18.3.1)(react@18.3.1) + specifier: 14.2.14 + version: 14.2.14(@babel/core@7.22.11)(react-dom@18.3.1)(react@18.3.1) next-auth: specifier: beta - version: 5.0.0-beta.21(next@14.2.13)(react@18.3.1) + version: 5.0.0-beta.22(next@14.2.14)(react@18.3.1) nextjs-toploader: specifier: ^1.6.12 - version: 1.6.12(next@14.2.13)(react-dom@18.3.1)(react@18.3.1) + version: 1.6.12(next@14.2.14)(react-dom@18.3.1)(react@18.3.1) postcss: specifier: 8.4.29 version: 8.4.29 @@ -171,8 +174,8 @@ packages: '@jridgewell/trace-mapping': 0.3.19 dev: false - /@auth/core@0.35.0: - resolution: {integrity: sha512-XvMALiYn5ZQd1hVeG1t+jCU89jRrc7ortl/05wkBrPHnRWZScxAK5jKuzBz+AOBQXewDjYcMpzeF5tTqg6rDhQ==} + /@auth/core@0.35.3: + resolution: {integrity: sha512-g6qfiqU4OtyvIEZ8J7UoIwAxEnNnLJV0/f/DW41U+4G5nhBlaCrnKhawJIJpU0D3uavXLeDT3B0BkjtiimvMDA==} peerDependencies: '@simplewebauthn/browser': ^9.0.1 '@simplewebauthn/server': ^9.0.2 @@ -569,8 +572,8 @@ packages: '@jridgewell/resolve-uri': 3.1.1 '@jridgewell/sourcemap-codec': 1.4.15 - /@next/env@14.2.13: - resolution: {integrity: sha512-s3lh6K8cbW1h5Nga7NNeXrbe0+2jIIYK9YaA9T7IufDWnZpozdFUp6Hf0d5rNWUKu4fEuSX2rCKlGjCrtylfDw==} + /@next/env@14.2.14: + resolution: {integrity: sha512-/0hWQfiaD5//LvGNgc8PjvyqV50vGK0cADYzaoOOGN8fxzBn3iAiaq3S0tCRnFBldq0LVveLcxCTi41ZoYgAgg==} dev: false /@next/eslint-plugin-next@13.4.19: @@ -579,8 +582,8 @@ packages: glob: 7.1.7 dev: false - /@next/swc-darwin-arm64@14.2.13: - resolution: {integrity: sha512-IkAmQEa2Htq+wHACBxOsslt+jMoV3msvxCn0WFSfJSkv/scy+i/EukBKNad36grRxywaXUYJc9mxEGkeIs8Bzg==} + /@next/swc-darwin-arm64@14.2.14: + resolution: {integrity: sha512-bsxbSAUodM1cjYeA4o6y7sp9wslvwjSkWw57t8DtC8Zig8aG8V6r+Yc05/9mDzLKcybb6EN85k1rJDnMKBd9Gw==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] @@ -588,8 +591,8 @@ packages: dev: false optional: true - /@next/swc-darwin-x64@14.2.13: - resolution: {integrity: sha512-Dv1RBGs2TTjkwEnFMVL5XIfJEavnLqqwYSD6LXgTPdEy/u6FlSrLBSSfe1pcfqhFEXRAgVL3Wpjibe5wXJzWog==} + /@next/swc-darwin-x64@14.2.14: + resolution: {integrity: sha512-cC9/I+0+SK5L1k9J8CInahduTVWGMXhQoXFeNvF0uNs3Bt1Ub0Azb8JzTU9vNCr0hnaMqiWu/Z0S1hfKc3+dww==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] @@ -597,8 +600,8 @@ packages: dev: false optional: true - /@next/swc-linux-arm64-gnu@14.2.13: - resolution: {integrity: sha512-yB1tYEFFqo4ZNWkwrJultbsw7NPAAxlPXURXioRl9SdW6aIefOLS+0TEsKrWBtbJ9moTDgU3HRILL6QBQnMevg==} + /@next/swc-linux-arm64-gnu@14.2.14: + resolution: {integrity: sha512-RMLOdA2NU4O7w1PQ3Z9ft3PxD6Htl4uB2TJpocm+4jcllHySPkFaUIFacQ3Jekcg6w+LBaFvjSPthZHiPmiAUg==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -606,8 +609,8 @@ packages: dev: false optional: true - /@next/swc-linux-arm64-musl@14.2.13: - resolution: {integrity: sha512-v5jZ/FV/eHGoWhMKYrsAweQ7CWb8xsWGM/8m1mwwZQ/sutJjoFaXchwK4pX8NqwImILEvQmZWyb8pPTcP7htWg==} + /@next/swc-linux-arm64-musl@14.2.14: + resolution: {integrity: sha512-WgLOA4hT9EIP7jhlkPnvz49iSOMdZgDJVvbpb8WWzJv5wBD07M2wdJXLkDYIpZmCFfo/wPqFsFR4JS4V9KkQ2A==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -615,8 +618,8 @@ packages: dev: false optional: true - /@next/swc-linux-x64-gnu@14.2.13: - resolution: {integrity: sha512-aVc7m4YL7ViiRv7SOXK3RplXzOEe/qQzRA5R2vpXboHABs3w8vtFslGTz+5tKiQzWUmTmBNVW0UQdhkKRORmGA==} + /@next/swc-linux-x64-gnu@14.2.14: + resolution: {integrity: sha512-lbn7svjUps1kmCettV/R9oAvEW+eUI0lo0LJNFOXoQM5NGNxloAyFRNByYeZKL3+1bF5YE0h0irIJfzXBq9Y6w==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -624,8 +627,8 @@ packages: dev: false optional: true - /@next/swc-linux-x64-musl@14.2.13: - resolution: {integrity: sha512-4wWY7/OsSaJOOKvMsu1Teylku7vKyTuocvDLTZQq0TYv9OjiYYWt63PiE1nTuZnqQ4RPvME7Xai+9enoiN0Wrg==} + /@next/swc-linux-x64-musl@14.2.14: + resolution: {integrity: sha512-7TcQCvLQ/hKfQRgjxMN4TZ2BRB0P7HwrGAYL+p+m3u3XcKTraUFerVbV3jkNZNwDeQDa8zdxkKkw2els/S5onQ==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -633,8 +636,8 @@ packages: dev: false optional: true - /@next/swc-win32-arm64-msvc@14.2.13: - resolution: {integrity: sha512-uP1XkqCqV2NVH9+g2sC7qIw+w2tRbcMiXFEbMihkQ8B1+V6m28sshBwAB0SDmOe0u44ne1vFU66+gx/28RsBVQ==} + /@next/swc-win32-arm64-msvc@14.2.14: + resolution: {integrity: sha512-8i0Ou5XjTLEje0oj0JiI0Xo9L/93ghFtAUYZ24jARSeTMXLUx8yFIdhS55mTExq5Tj4/dC2fJuaT4e3ySvXU1A==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] @@ -642,8 +645,8 @@ packages: dev: false optional: true - /@next/swc-win32-ia32-msvc@14.2.13: - resolution: {integrity: sha512-V26ezyjPqQpDBV4lcWIh8B/QICQ4v+M5Bo9ykLN+sqeKKBxJVDpEc6biDVyluTXTC40f5IqCU0ttth7Es2ZuMw==} + /@next/swc-win32-ia32-msvc@14.2.14: + resolution: {integrity: sha512-2u2XcSaDEOj+96eXpyjHjtVPLhkAFw2nlaz83EPeuK4obF+HmtDJHqgR1dZB7Gb6V/d55FL26/lYVd0TwMgcOQ==} engines: {node: '>= 10'} cpu: [ia32] os: [win32] @@ -651,8 +654,8 @@ packages: dev: false optional: true - /@next/swc-win32-x64-msvc@14.2.13: - resolution: {integrity: sha512-WwzOEAFBGhlDHE5Z73mNU8CO8mqMNLqaG+AO9ETmzdCQlJhVtWZnOl2+rqgVQS+YHunjOWptdFmNfbpwcUuEsw==} + /@next/swc-win32-x64-msvc@14.2.14: + resolution: {integrity: sha512-MZom+OvZ1NZxuRovKt1ApevjiUJTcU2PmdJKL66xUPaJeRywnbGGRWUlaAOwunD6dX+pm83vj979NTC8QXjGWg==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -743,6 +746,29 @@ packages: react-dom: 18.3.1(react@18.3.1) dev: false + /@radix-ui/react-avatar@1.1.1(@types/react-dom@18.2.7)(@types/react@18.2.21)(react-dom@18.3.1)(react@18.3.1): + resolution: {integrity: sha512-eoOtThOmxeoizxpX6RiEsQZ2wj5r4+zoeqAwO0cBaFQGjJwIH3dIX0OCxNrCyrrdxG+vBweMETh3VziQG7c1kw==} + peerDependencies: + '@types/react': '*' + '@types/react-dom': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@types/react-dom': + optional: true + dependencies: + '@radix-ui/react-context': 1.1.1(@types/react@18.2.21)(react@18.3.1) + '@radix-ui/react-primitive': 2.0.0(@types/react-dom@18.2.7)(@types/react@18.2.21)(react-dom@18.3.1)(react@18.3.1) + '@radix-ui/react-use-callback-ref': 1.1.0(@types/react@18.2.21)(react@18.3.1) + '@radix-ui/react-use-layout-effect': 1.1.0(@types/react@18.2.21)(react@18.3.1) + '@types/react': 18.2.21 + '@types/react-dom': 18.2.7 + react: 18.3.1 + react-dom: 18.3.1(react@18.3.1) + dev: false + /@radix-ui/react-collapsible@1.1.0(@types/react-dom@18.2.7)(@types/react@18.2.21)(react-dom@18.3.1)(react@18.3.1): resolution: {integrity: sha512-zQY7Epa8sTL0mq4ajSJpjgn2YmCgyrG7RsQgLp3C0LQVkG7+Tf6Pv1CeNWZLyqMjhdPkBa5Lx7wYBeSu7uCSTA==} peerDependencies: @@ -865,6 +891,19 @@ packages: react: 18.3.1 dev: false + /@radix-ui/react-context@1.1.1(@types/react@18.2.21)(react@18.3.1): + resolution: {integrity: sha512-UASk9zi+crv9WteK/NU4PLvOoL3OuE6BWVKNF6hPRBtYBDXQ2u5iu3O59zUlJiTVvkyuycnqrztsHVJwcK9K+Q==} + peerDependencies: + '@types/react': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + dependencies: + '@types/react': 18.2.21 + react: 18.3.1 + dev: false + /@radix-ui/react-dialog@1.0.0(@types/react@18.2.21)(react-dom@18.3.1)(react@18.3.1): resolution: {integrity: sha512-Yn9YU+QlHYLWwV1XfKiqnGVpWYWk6MeBVM6x/bcoyPvxgjQGoeT35482viLPctTMWoMw0PoHgqfSox7Ig+957Q==} peerDependencies: @@ -3985,8 +4024,8 @@ packages: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} dev: false - /next-auth@5.0.0-beta.21(next@14.2.13)(react@18.3.1): - resolution: {integrity: sha512-VrT6LV9u/o5tMuWxRDN5d/K1OgPskrMHy+aITTwasVfIrkIaU/8UVg3TXH8ynJgzhfzlDx/3hLWGhi+eXQw4qg==} + /next-auth@5.0.0-beta.22(next@14.2.14)(react@18.3.1): + resolution: {integrity: sha512-QGBo9HGOjmnJBHGXvtFztl0tM5tL0porDlk74HVoCCzXd986ApOlIW3EmiCuho7YzEopgkFiwwmcXpoCrHAtYw==} peerDependencies: '@simplewebauthn/browser': ^9.0.1 '@simplewebauthn/server': ^9.0.2 @@ -4001,13 +4040,13 @@ packages: nodemailer: optional: true dependencies: - '@auth/core': 0.35.0 - next: 14.2.13(@babel/core@7.22.11)(react-dom@18.3.1)(react@18.3.1) + '@auth/core': 0.35.3 + next: 14.2.14(@babel/core@7.22.11)(react-dom@18.3.1)(react@18.3.1) react: 18.3.1 dev: false - /next@14.2.13(@babel/core@7.22.11)(react-dom@18.3.1)(react@18.3.1): - resolution: {integrity: sha512-BseY9YNw8QJSwLYD7hlZzl6QVDoSFHL/URN5K64kVEVpCsSOWeyjbIGK+dZUaRViHTaMQX8aqmnn0PHBbGZezg==} + /next@14.2.14(@babel/core@7.22.11)(react-dom@18.3.1)(react@18.3.1): + resolution: {integrity: sha512-Q1coZG17MW0Ly5x76shJ4dkC23woLAhhnDnw+DfTc7EpZSGuWrlsZ3bZaO8t6u1Yu8FVfhkqJE+U8GC7E0GLPQ==} engines: {node: '>=18.17.0'} hasBin: true peerDependencies: @@ -4024,7 +4063,7 @@ packages: sass: optional: true dependencies: - '@next/env': 14.2.13 + '@next/env': 14.2.14 '@swc/helpers': 0.5.5 busboy: 1.6.0 caniuse-lite: 1.0.30001620 @@ -4034,28 +4073,28 @@ packages: react-dom: 18.3.1(react@18.3.1) styled-jsx: 5.1.1(@babel/core@7.22.11)(react@18.3.1) optionalDependencies: - '@next/swc-darwin-arm64': 14.2.13 - '@next/swc-darwin-x64': 14.2.13 - '@next/swc-linux-arm64-gnu': 14.2.13 - '@next/swc-linux-arm64-musl': 14.2.13 - '@next/swc-linux-x64-gnu': 14.2.13 - '@next/swc-linux-x64-musl': 14.2.13 - '@next/swc-win32-arm64-msvc': 14.2.13 - '@next/swc-win32-ia32-msvc': 14.2.13 - '@next/swc-win32-x64-msvc': 14.2.13 + '@next/swc-darwin-arm64': 14.2.14 + '@next/swc-darwin-x64': 14.2.14 + '@next/swc-linux-arm64-gnu': 14.2.14 + '@next/swc-linux-arm64-musl': 14.2.14 + '@next/swc-linux-x64-gnu': 14.2.14 + '@next/swc-linux-x64-musl': 14.2.14 + '@next/swc-win32-arm64-msvc': 14.2.14 + '@next/swc-win32-ia32-msvc': 14.2.14 + '@next/swc-win32-x64-msvc': 14.2.14 transitivePeerDependencies: - '@babel/core' - babel-plugin-macros dev: false - /nextjs-toploader@1.6.12(next@14.2.13)(react-dom@18.3.1)(react@18.3.1): + /nextjs-toploader@1.6.12(next@14.2.14)(react-dom@18.3.1)(react@18.3.1): resolution: {integrity: sha512-nbun5lvVjlKnxLQlahzZ55nELVEduqoEXT03KCHnsEYJnFpI/3BaIzpMyq/v8C7UGU2NfxQmjq6ldZ310rsDqA==} peerDependencies: next: '>= 6.0.0' react: '>= 16.0.0' react-dom: '>= 16.0.0' dependencies: - next: 14.2.13(@babel/core@7.22.11)(react-dom@18.3.1)(react@18.3.1) + next: 14.2.14(@babel/core@7.22.11)(react-dom@18.3.1)(react@18.3.1) nprogress: 0.2.0 prop-types: 15.8.1 react: 18.3.1 diff --git a/src/app/(dashboard)/patients/[id]/components/patientInfo.tsx b/src/app/(dashboard)/patients/[id]/components/patientInfo.tsx index 682d05d..153cf9d 100644 --- a/src/app/(dashboard)/patients/[id]/components/patientInfo.tsx +++ b/src/app/(dashboard)/patients/[id]/components/patientInfo.tsx @@ -1,7 +1,20 @@ +import React from "react"; import HiddenText from "@/components/hidden.text"; +import { Button } from "@/components/ui/button"; import { Patient } from "@/lib/fhir/types"; import { CarePlanData } from "@/lib/models/types"; -import React from "react"; +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { Card, CardContent } from "@/components/ui/card"; +import { Avatar, AvatarFallback } from "@/components/ui/avatar"; type Props = { patient: Patient; @@ -18,19 +31,67 @@ const PatientInfo = ({ patient, carePlan }: Props) => { {getAge(patient.birthDate)} years old -
- {carePlan && ( -
- {carePlan.title && ( -

{carePlan.title}

- )} -
- )} - +
+
+ {carePlan && ( +
+ {carePlan.title && ( +

{carePlan.title}

+ )} +
+ )} + +
+
+ {patient.links.length > 0 && ( + + + + + + + Patient Links +
+ { +
    + {patient.links.map((link) => ( + + +
    + + + {link.initials} + + +
    +

    + {link.name} +

    +

    + {link.id} +

    +
    +
    +
    +
    + ))} +
+ } +
+
+
+
+ )} +
); diff --git a/src/components/ui/avatar.tsx b/src/components/ui/avatar.tsx new file mode 100644 index 0000000..51e507b --- /dev/null +++ b/src/components/ui/avatar.tsx @@ -0,0 +1,50 @@ +"use client" + +import * as React from "react" +import * as AvatarPrimitive from "@radix-ui/react-avatar" + +import { cn } from "@/lib/utils" + +const Avatar = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +Avatar.displayName = AvatarPrimitive.Root.displayName + +const AvatarImage = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AvatarImage.displayName = AvatarPrimitive.Image.displayName + +const AvatarFallback = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName + +export { Avatar, AvatarImage, AvatarFallback } diff --git a/src/components/ui/dialog.tsx b/src/components/ui/dialog.tsx index 2f33766..69b2e62 100644 --- a/src/components/ui/dialog.tsx +++ b/src/components/ui/dialog.tsx @@ -1,22 +1,18 @@ -"use client" +"use client"; -import * as React from "react" -import * as DialogPrimitive from "@radix-ui/react-dialog" -import { X } from "lucide-react" +import * as React from "react"; +import * as DialogPrimitive from "@radix-ui/react-dialog"; +import { X } from "lucide-react"; -import { cn } from "@/lib/utils" +import { cn } from "@/lib/utils"; -const Dialog = DialogPrimitive.Root +const Dialog = DialogPrimitive.Root; -const DialogTrigger = DialogPrimitive.Trigger +const DialogTrigger = DialogPrimitive.Trigger; -const DialogPortal = ({ - className, - ...props -}: DialogPrimitive.DialogPortalProps) => ( - -) -DialogPortal.displayName = DialogPrimitive.Portal.displayName +const DialogPortal = DialogPrimitive.Portal; + +const DialogClose = DialogPrimitive.Close; const DialogOverlay = React.forwardRef< React.ElementRef, @@ -25,13 +21,13 @@ const DialogOverlay = React.forwardRef< -)) -DialogOverlay.displayName = DialogPrimitive.Overlay.displayName +)); +DialogOverlay.displayName = DialogPrimitive.Overlay.displayName; const DialogContent = React.forwardRef< React.ElementRef, @@ -42,7 +38,7 @@ const DialogContent = React.forwardRef< -)) -DialogContent.displayName = DialogPrimitive.Content.displayName +)); +DialogContent.displayName = DialogPrimitive.Content.displayName; const DialogHeader = ({ className, @@ -68,8 +64,8 @@ const DialogHeader = ({ )} {...props} /> -) -DialogHeader.displayName = "DialogHeader" +); +DialogHeader.displayName = "DialogHeader"; const DialogFooter = ({ className, @@ -82,8 +78,8 @@ const DialogFooter = ({ )} {...props} /> -) -DialogFooter.displayName = "DialogFooter" +); +DialogFooter.displayName = "DialogFooter"; const DialogTitle = React.forwardRef< React.ElementRef, @@ -97,8 +93,8 @@ const DialogTitle = React.forwardRef< )} {...props} /> -)) -DialogTitle.displayName = DialogPrimitive.Title.displayName +)); +DialogTitle.displayName = DialogPrimitive.Title.displayName; const DialogDescription = React.forwardRef< React.ElementRef, @@ -109,15 +105,19 @@ const DialogDescription = React.forwardRef< className={cn("text-sm text-muted-foreground", className)} {...props} /> -)) -DialogDescription.displayName = DialogPrimitive.Description.displayName +)); +DialogDescription.displayName = DialogPrimitive.Description.displayName; export { Dialog, + DialogPortal, + DialogOverlay, + DialogClose, DialogTrigger, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, -} +}; + diff --git a/src/lib/fhir/patient.ts b/src/lib/fhir/patient.ts index 72ff4c3..dc5d8e4 100644 --- a/src/lib/fhir/patient.ts +++ b/src/lib/fhir/patient.ts @@ -1,18 +1,35 @@ +import { fhirR4 } from "@smile-cdr/fhirts"; import { Patient } from "./types"; -export const createPatient = (data: any): Patient => { +export const createPatient = (data: fhirR4.Patient): Patient => { + const firstName = data.name?.[0]?.given?.[0] ?? ""; + const lastName = data?.name?.[0]?.family ?? ""; return { - id: data.id, + id: data.id ?? "NA", locationId: - data.meta.tag.find( + (data.meta?.tag ?? []).find( (e: any) => e.system === "http://smartregister.org/fhir/location-tag" )?.code ?? "NA", identifier: data.identifier?.[0]?.value ?? "NA", - name: data.name[0].given[0] + " " + data.name[0].family, - firstName: data.name[0].given[0], - lastName: data.name[0].family, - gender: data.gender, - birthDate: data.birthDate, + name: `${firstName} ${lastName}`, + firstName: firstName, + lastName: lastName, + gender: data.gender ?? "unknown", + birthDate: data.birthDate ?? "", + links: + (data.link ?? []).map((value) => { + const items = value.other.display?.split(",") ?? []; + const name = items[items.length > 3 ? 2 : 1] ?? "NA"; + const initials = name + .split(" ") + .map((e) => e[0]) + .join(""); + return { + id: items?.[0].trim() ?? "NA", + name: name, + initials: initials, + }; + }) ?? [], phoneNumbers: data.telecom?.map((value: any) => { var array = value.value?.split("|"); @@ -21,14 +38,14 @@ export const createPatient = (data: any): Patient => { owner: array[2], }; }) ?? [], - active: data.active, + active: data.active ?? true, address: data.address?.map((value: any) => ({ facility: value.district ?? "NA", physical: data.address?.[0]?.text ?? "NA", })) ?? [], registrationDate: - data.meta.tag.find( + (data?.meta?.tag ?? []).find( (e: any) => e.system === "https://d-tree.org/fhir/created-on-tag" )?.code ?? "NA", registratedBy: data.generalPractitioner?.[0]?.display ?? "NA", diff --git a/src/lib/fhir/types.ts b/src/lib/fhir/types.ts index 6fc0730..dee0154 100644 --- a/src/lib/fhir/types.ts +++ b/src/lib/fhir/types.ts @@ -15,4 +15,9 @@ export type Patient = { number: string, owner: string, }[], + links: { + name: string, + id: string, + initials: string; + }[] } \ No newline at end of file