by Endo Supply @Chonburi hospital
Overview
- No. of containers: 8 (A,B,C,...,H)
- No. of trays / container = 16 (1,2,3,...,16)
- Total: Can store up to 128 endoscopes
LED Lights
- Tray #A1 => command L00 to ports.A
- Tray #H6 => command: L15 to ports.H
Insert gif or link to demo
What did you learn while building this project? What challenges did you face and how did you overcome them?
Install my-project with npm
npm install my-project
cd my-project
## Color Reference
Color | Hex |
---|---|
Example Color | |
Example Color | |
Example Color | |
Example Color |
How realtime data fetching works when upadting temperate and humidity of each container.
- Backend
- When instantiate serialports , add listener to listen to any returned data from serialports (in serialport service)
- Cron job (in serialport) to write :sts to each serialport every minute
- Inside listen, 3.1 update the container stat every write 3.2 only create snapshot every hour
In order to create snapshot only every hour (not every time) A counter is used
If there is one serialport If counter = 60, then create snapshot (counter = 10 if want to update every 10 mins)
However, there are 8 serialports, the counter will increase by 8 every minute
Therefore we only create snapshot when counter = 60 * 8 (container_num)
counterCeil = CONTAINER_NUM * 60; => 60 can be from setting too, check in serialpots.service.ts
- Basically, the first time it run, it is 60 by default (on constants.ts DEFAULT_SNAPSHOT_INTERVAL_MINS)
- However, we update it async to whatever is in the database this.settingService.findSnapshotIntervalMins
- อัปเดทหลังแค่เสี้ยววินาที เลยทันตราบที่ไม่ได้แบบอัปเดททุปวินาที
- first min => counter = จำนวน container ถ้าไม่เกินก้อโอเค สรุปคือถ้า setting ไท่เท่ากับ 1 ไม่น่ามีปัญหาปะน้อ
- The setting is stored in setting table in the db
- When instantiate the serialports, use this value in the db (for counter ceiling)
- Later on, when this got updated by a user, have to update the counter ceilling value by getting it from the setting service
- just refetch every xxx seconds
- it does not directly query the serialport though, it queries the db. Therefore, if the db does not update yet, the frontend won't update either. I think currently
- container db updates every 1 minute
- endoscope db updates everytime there is action (so it's 100 up-to-date)
- snapshot db taken every 1 hour (can be changed in the setting)
- Firstly drop all the existing tables by running comment out the 01_drop.seed and run yarn seed:run
- start the service to recreate the database
- comment out the seed and run yarn seed:run again to create the data
- When current status =
- ready or expire_soon, you can use it (session created => status turns to being_used) and wash it
- expired => you can take out (session created => status turns to expired_and_out) and wash
- It is designed this way so in the session page, if expired_and_out => no need to fill-in the patient form
- in session, there is type endoWasExpired
- This is so we know that when endo is drying
- show NoPatientForm if endoWasExpired
- show PatientDetail if !endoWasExpired
- Endos table and EndosSetting table => by type, brand, and modal (in backend)
- Container: Sort by container col in the frontend
- Snapshots, Activities => autosort by pagination createdAt
- Start from L00
- Because in the container, the LED cord line is "U" shape. Row 1-8 => LED00-07, but Row 9 -16 => LED 15-08
The Idea is
- After 29 days, "ready" becomes "expire_soon"
- AFter 30 days (1 day after expired_soon), "expire_soon" becaomse "expired"
So in the code
- When drying is finished and is set from "drying" to "ready" =>
- 1 ADD A SCHEDULE (callback) to make it expire_soon in MAX_STORAGE_DAYS - 1.
- 2 Add a new row in endo_cron table
- When it reaches MAX_STORAGE_DAYS - 1 days and we set to "expire_soon", ADD A SCHEDULE to make it "expired" in 1 day But don't forget to remoe the schedule if someone use it before it expired
- 1 ADD A SCHEDULE to make it "expired" in 1 day
- 2 Add a new row in endo_cron table
If someone uses it before 30 days, in pickendo => Delete a schedule base on its name (from endoId and status),
Schedule: Endo xxx is to be expired
Whenever adding a new schedule => add a new row in database too Whenever a scheduled callback is called or a schedule is deleted => remove an existing row in th db
When creating a cron job, in code,
- when create a schedule, I need an endo id, to be status, and millisec
- when delete a schedule, I just need the name (could be get from endo id, and status)
So in the database, I just need to store the endoId, toBeStatus, and timeStamp
In the end
- addTimeout does not work because 30 days in millisec exceeds 32 bit
- use addCronJob instead to specify a specific date (see details in endoCron)
If the server is down, all the "unrun" crons are saved. when server comes back =>
- if in the future, re init all the crons
- if in past, run them!
- when init serialports
a: SP,
b: null,
c: SP,
}```
- when init parsers
```{
a: Parser,
b: null,
c: Parser,
}```
When deploy server
- yarn build
- yarn prod (node-service)
When deploy react
- build docker image
- remove running container (same name)
- run docker container (change image)
When installa at a hospital
- fix the COM port
- change the ip address in both server and clientdocker
- change chrome default page and new tab page to match ip address
when run yarn gen
- server => yarn dev (will listen to http localhost 4001)
- client =>