Guest User

Untitled

a guest
Jul 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. // @flow
  2.  
  3. import data, {
  4. type Patient as BasePatient,
  5. type Reading as BaseReading,
  6. } from "./data.json";
  7.  
  8. export type Reading = $Diff<BaseReading, { timestamp: string }> & {
  9. timestamp: number,
  10. };
  11. export type Patient = ($Diff<BasePatient, { readings: BaseReading[] }> & {
  12. title: string,
  13. readings: Reading[],
  14. });
  15.  
  16. const patients : Patient = data.patients.map(p => ({
  17. ...p,
  18. title: `${p.mrn} / ${p.sex}`,
  19. readings: p.readings.map(r => ({
  20. ...r,
  21. timestamp: Date.parse(r.timestamp),
  22. })),
  23. }));
  24.  
  25. const readings = patients.reduce(
  26. (acc, { readings, ...p }) => [...acc, ...readings.map(r => ({ ...r, ...p }))],
  27. [],
  28. );
  29.  
  30. export { patients, readings };
Add Comment
Please, Sign In to add comment