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

Update Charting Demo #4494

Draft
wants to merge 62 commits into
base: main
Choose a base branch
from
Draft

Update Charting Demo #4494

wants to merge 62 commits into from

Conversation

ksmith94
Copy link
Collaborator

@ksmith94 ksmith94 commented May 2, 2024

This will update the current charting demo to be based around the Encounter resource. Specifically, it will demo how to create encounter notes.

Copy link

vercel bot commented May 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medplum-provider ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2024 11:58am
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
medplum-app ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 11:58am
medplum-storybook ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 11:58am
medplum-www ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 11:58am

Copy link

sonarcloud bot commented May 13, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

examples/medplum-chart-demo/README.md Outdated Show resolved Hide resolved
examples/medplum-chart-demo/README.md Outdated Show resolved Hide resolved
examples/medplum-chart-demo/package.json Outdated Show resolved Hide resolved
examples/medplum-chart-demo/src/pages/PatientPage.tsx Outdated Show resolved Hide resolved
Copy link

socket-security bot commented May 15, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/chart.js@4.4.2 None +1 5.01 MB chartjs-ci
npm/esbuild@0.21.2 environment, filesystem, network, shell +23 226 MB evanw

View full report↗︎

Copy link

socket-security bot commented May 15, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: npm/esbuild@0.21.2

View full report↗︎

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

@rahul1
Copy link
Member

rahul1 commented May 31, 2024

@SocketSecurity ignore npm/esbuild@0.21.2

Copy link
Member

Choose a reason for hiding this comment

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

since this is not a tsx file, the name should be lower case.

aslo, maybe something like measurement-constants, to more clearly indicate that these are static values

const secondBackgroundColor = 'rgba(255, 119, 0, 0.7)';
const secondBorderColor = 'rgba(255, 119, 0, 1)';

export const measurementsMeta: Record<string, ObservationType> = {
Copy link
Member

Choose a reason for hiding this comment

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

measurementStyles?

useEffect(() => {
if (observations) {
const labels: string[] = [];
const datasets: ChartDataset<'line', number[]>[] = chartDatasets.map((item) => ({ ...item, data: [] }));
Copy link
Member

Choose a reason for hiding this comment

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

please add some comments to this file to explain how things are working here.

}
checkForValidResponse();

function getNoteType(): string {
Copy link
Member

Choose a reason for hiding this comment

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

Comments

displayValues: ObstetricAnswers;
}

function ObstetricNoteDisplay({ displayValues }: ObstetricNoteDisplay): JSX.Element {
Copy link
Member

@rahul1 rahul1 May 31, 2024

Choose a reason for hiding this comment

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

Break each of these into their own component file

* @param user - The user creating the Condition resource
* @returns An array of bundle entries containing the Condition resource that can be created in a batch request.
*/
export function createConditionEntries(
Copy link
Member

Choose a reason for hiding this comment

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

Right now this function does two jobs:

  1. takes a partial Condition and adds default fields to create a full Condition resoruce
  2. Creates the bundle entry, with the appropriate search strings

Instead, for each of the resources Observation, Condition, ClinicalImpression, we should have functions:

  • create* that takes a partial entry and creates a full resource (or potentially 2 in the case of conditions)

Separately, we should just have 1 function that then takes all the output resources, and packages them into a transaction bundle (with the appropriate search string).

That way, we won't be repeating the bundle creation logic for each resource type


// Return the clinical impression in a bundle entry
return {
fullUrl: generateId(),
Copy link
Member

Choose a reason for hiding this comment

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

not sure that generateId() does the right thing here. Might be better to use `urn:uuid:${randomUUID()}`

};
}

function getWeightInKilograms(weight: Quantity): number {
Copy link
Member

Choose a reason for hiding this comment

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

can you break out all the BMI related functions into a new file called observation-utils

Conceptually, these are different from the functions above because they deal with computing single Observation values, rather than full bundles

key === 'selfReportedHistory' ? getSelfReportedCode(observationData.selfReportedHistory as string) : codes[key],
};

switch (key) {
Copy link
Member

Choose a reason for hiding this comment

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

you can simplify these switch statements as follows:

const observationTypes = {
'height': 'valueQuantity', 
'moodSwings': 'valueBoolean', 
/...
}

if(key !== bloodPressure) {
  resource[observationTypes[key]] = observationData[key]
}

Copy link
Member

Choose a reason for hiding this comment

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

You can then just handle the case of the bloodPressure separately

Copy link
Member

Choose a reason for hiding this comment

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

This also means you can combine all the createPartial***Observations functions into a single utility function.

createObservations( 
  observationData, 
  codes, 
  observationTypes) {
   // handle blood pressure 
   // else
   // use `observationTypes` to fill `value**`
  // Fill in the default fields
  // return a full Observation
}

Copy link
Member

Choose a reason for hiding this comment

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

This should really reduce the amount of specialized code per-note type

};

// Add the appropriate code based on the answer provided for self-reported history
switch (reportedHistory) {
Copy link
Member

@rahul1 rahul1 May 31, 2024

Choose a reason for hiding this comment

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

As above, this switch statement could be converted to a map

const labels: string[] = [];
const datasets: ChartDataset<'line', number[]>[] = chartDatasets.map((item) => ({ ...item, data: [] }));

for (const observation of observations) {
Copy link
Member

Choose a reason for hiding this comment

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

Might make sense to break this into a helper function that just converts a list of observations into a list of numbers

<QuantityDisplay value={displayValues.totalWeightGain} />
</Group>
)}
{/* <Group>
Copy link
Member

Choose a reason for hiding this comment

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

remove dead code

Copy link
Member

Choose a reason for hiding this comment

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

try to avoid the double extenson (.utils.ts) where possible.

Copy link
Member

Choose a reason for hiding this comment

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

Each of the note-specific functions should live in the files related to that component. Things in a utils file should truly be general purpose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
charting Features and fixes related to charting
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

3 participants