/bonfhir-connectathon

bonFHIR Hackathon - Nov. 23rd, 2023

Primary LanguageTypeScript

bonFHIR logo

What's a FHIR connectathon?
https://www.hl7.org/events/fhir-connectathon/index.cfm

Useful links

Environments

Get started

  1. Prerequisite: install Node.js (v18+ / LTS recommended).

  2. Clone the repository git clone https://github.com/AlleyCorpNord/bonfhir-hackaton.git

  3. Install dependencies npm install

  4. Run the project npm run dev

Useful snippets

Read a single FHIR resource and display a simple value

const params = useParams<{ patientId: string }>();
const patientQuery = useFhirRead("Patient", params.patientId);

return <FhirValue type="date" value={patientQuery.data?.birthDate} />;

Read a list and display a paginated table

// The search controller coordinates the pagination
// between the query, the table and the pagination
const searchController = useFhirSearchControllerNext<PatientSortOrder>("q", {
  defaultSort: "name",
});

// For pagination to work the total must be requested and
// the `searchController.pageUrl` must be passed to the search as well
const patientsQuery = useFhirSearch(
  "Patient",
  (search) =>
    search
      ._total("accurate")
      ._count(searchController.pageSize)
      ._sort(searchController.sort),
  searchController.pageUrl,
);

return (
  <Paper>
    <Stack>
      <Title order={3}>Patients</Title>
      <Box>
        <FhirQueryLoader query={patientsQuery}>
          <FhirTable
            {...patientsQuery}
            {...searchController}
            onRowNavigate={(patient) => `/patients/${patient.id}`}
            columns={[
              {
                key: "name",
                title: "Name",
                sortable: true,
                render: (patient) => (
                  <FhirValue type="HumanName" value={patient.name} />
                ),
              },
            ]}
          />
          <FhirPagination {...patientsQuery} {...searchController} />
        </FhirQueryLoader>
      </Box>
    </Stack>
  </Paper>
);

Update a single FHIR resource in a controlled way

const params = useParams<{ patientId: string }>();
const router = useRouter();

// The `useFhirResourceForm` does the whole read/update cycle
// If you need more fine-grained control, `useFhirForm` will do.
// See https://mantine.dev/form/use-form/ for more information as well.
const form = useFhirResourceForm({
  id: params.patientId,
  type: "Patient",
  mutationOptions: {
    onSuccess(patient) {
      router.push(`/patients/${patient.id}`);
    },
  },
});

return (
  <Paper>
    <Stack>
      <Title order={3}>Edit patient</Title>
      <form onSubmit={form.onSubmit}>
        <Stack>
          <LoadingOverlay visible={form.query.isInitialLoading} />
          <FhirInput
            type="date"
            label="Date of Birth"
            {...form.getInputProps("birthDate")}
          />
          <FhirInputArray
            label="Name"
            min={1}
            {...form.getArrayInputProps("name", { newValue: {} })}
          >
            {({ index }) => {
              return (
                <FhirInput
                  type="HumanName"
                  mode="simple"
                  {...form.getInputProps(`name.${index}`)}
                />
              );
            }}
          </FhirInputArray>
          <Group mt="md">
            <Button type="submit" loading={form.mutation.isLoading}>
              Save
            </Button>
            <Button variant="outline" onClick={() => router.back()}>
              Cancel
            </Button>
          </Group>
        </Stack>
      </form>
    </Stack>
  </Paper>
);