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

MF-795: Add swr to vitals widget #405

Merged
merged 2 commits into from
Oct 4, 2021
Merged

MF-795: Add swr to vitals widget #405

merged 2 commits into from
Oct 4, 2021

Conversation

denniskigen
Copy link
Member

@denniskigen denniskigen commented Sep 27, 2021

Requirements

  • This PR has a title that briefly describes the work done, including the ticket number if there is a ticket.
  • My work conforms to the OpenMRS 3.0 Styleguide.
  • I checked for feature overlap with existing widgets.

Summary

Apologies for the huge diff.

This PR:

  1. Adds SWR data fetching hooks to the Vitals widget.
  2. Refactors the existing components to reuse these hooks.
  3. Refactors existing tests to work within the SWR paradigm.
  4. Moves useVitalsConceptMetadata (a hook for fetching vitals and biometrics concept units and metadata) to esm-patient-common-lib so it can be reused by both the vitals and biometrics widgets. Also moves the withUnit helper function which renders a label for a vital sign along with its associated unit.
  5. Adds a mutate call in the VitalsandBiometricsForm so that the related widgets automatically revalidate when a new set of vitals or biometrics is successfully recorded via the form.

Issue

https://issues.openmrs.org/browse/MF-795

@denniskigen denniskigen changed the title Add swr to vitals widget MF-795: Add swr to vitals widget Sep 27, 2021
@denniskigen denniskigen marked this pull request as draft September 27, 2021 15:50
@denniskigen denniskigen marked this pull request as ready for review September 27, 2021 15:52
view: string;
vitals: PatientVitals;
toggleView(): void;
showDetails: boolean;
showRecordVitals: boolean;
}

const VitalsHeaderStateTitle: React.FC<VitalsHeaderStateTitleProps> = ({
const VitalsHeaderTitle: React.FC<VitalsHeaderTitleProps> = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a funny name. Is it a header, or a title? Or a header tile? Or the title of the header, because for some reason the body has its own title, which is different??

Comment on lines 33 to 56
const systolicBloodPressureData = observations?.filter((obs) =>
obs.code.coding.some((sys) => sys.code === config.concepts.systolicBloodPressureUuid),
);
const diastolicBloodPressureData = observations?.filter((obs) =>
obs.code.coding.some((sys) => sys.code === config.concepts.diastolicBloodPressureUuid),
);
const pulseData = observations?.filter((obs) =>
obs.code.coding.some((sys) => sys.code === config.concepts.pulseUuid),
);
const temperatureData = observations?.filter((obs) =>
obs.code.coding.some((sys) => sys.code === config.concepts.temperatureUuid),
);
const oxygenSaturationData = observations?.filter((obs) =>
obs.code.coding.some((sys) => sys.code === config.concepts.oxygenSaturationUuid),
);
const heightData = observations?.filter((obs) =>
obs.code.coding.some((sys) => sys.code === config.concepts.heightUuid),
);
const weightData = observations?.filter((obs) =>
obs.code.coding.some((sys) => sys.code === config.concepts.weightUuid),
);
const respiratoryRateData = observations?.filter((obs) =>
obs.code.coding.some((sys) => sys.code === config.concepts.respiratoryRateUuid),
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was better as it was before. That filterByConceptUuid function could even be defined as an arrow function right on top of these lines, so it's all right there.


const tableHeaders = [
{ key: 'date', header: 'Date and time', isSortable: true },
{
key: 'bloodPressure',
header: withUnit('BP', bloodPressureUnit),
header: withUnit('BP', conceptUnits ? conceptUnits[0] : ''),
Copy link
Contributor

@brandones brandones Oct 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
header: withUnit('BP', conceptUnits ? conceptUnits[0] : ''),
header: withUnit('BP', conceptUnits?.[0] ?? ''),

Right? Also I wonder if withUnit should (or does?) just treat undefined like ''. Then it could be

Suggested change
header: withUnit('BP', conceptUnits ? conceptUnits[0] : ''),
header: withUnit('BP', conceptUnits?.[0]),

<div className={styles.row}>
<VitalsHeaderItem
unitName={t('temperatureAbbreviated', 'Temp')}
unitSymbol={conceptUnits ? conceptUnits[2] : ''}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point (not in this PR) I think the vitals will need some refactoring to make it more robust, especially once we want to make it configurable. e.g. having these really arbitrary indexes tied to specific vitals is not awesome.

Copy link
Contributor

@brandones brandones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small things, nothing major. I think the major thing is that all this vitals stuff will need some refactoring in the near future. And the situation with the units is bad.

Nice work, generally

@brandones
Copy link
Contributor

Feel free to resolve conflicts, address feedback at your discretion, and merge.

Improvements to the VitalsOverview involving the use of the `withUnit` function. Additionally, this commit adds improvements to the Vitals resource that include:

- Better type annotations.
- Inlining the `filterByConceptUuid` function implementation in the `useVitals` hook.
- Invoking `formatVitals` directly on the results of calling `filterByConceptUuid`. This has the corollary of reducing the number of lines of repetitive code significantly.
@denniskigen
Copy link
Member Author

Thanks, @brandones, for your review and suggestions. Unfortunately, the scope of this PR ended up far exceeding its original intention. I agree about refactoring being required very shortly - especially around the units stuff. The latest commit addresses the issues around the use of withUnit and the useVitals hook. The remaining issues should be resolved outside of this PR, as you suggest. I'll proceed to merge this.

@denniskigen denniskigen merged commit 89e7b1e into master Oct 4, 2021
@denniskigen denniskigen deleted the MF-795 branch October 4, 2021 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants