@photonhealth/react 2.0.0-rc.1 → 2.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/README.md +52 -9
  2. package/dist/adapters/tailwind.d.ts.map +1 -1
  3. package/dist/adapters/tailwind.js +7 -4
  4. package/dist/adapters/tailwind.js.map +1 -1
  5. package/dist/analytics/PhotonAnalyticsProvider.d.ts +19 -0
  6. package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
  7. package/dist/analytics/PhotonAnalyticsProvider.js +76 -0
  8. package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
  9. package/dist/analytics/cardLifecycle.d.ts +10 -0
  10. package/dist/analytics/cardLifecycle.d.ts.map +1 -0
  11. package/dist/analytics/cardLifecycle.js +43 -0
  12. package/dist/analytics/cardLifecycle.js.map +1 -0
  13. package/dist/analytics/fieldInteraction.d.ts +18 -0
  14. package/dist/analytics/fieldInteraction.d.ts.map +1 -0
  15. package/dist/analytics/fieldInteraction.js +102 -0
  16. package/dist/analytics/fieldInteraction.js.map +1 -0
  17. package/dist/analytics/lifecycleOutcomes.d.ts +8 -0
  18. package/dist/analytics/lifecycleOutcomes.d.ts.map +1 -0
  19. package/dist/analytics/lifecycleOutcomes.js +16 -0
  20. package/dist/analytics/lifecycleOutcomes.js.map +1 -0
  21. package/dist/analytics/tracker.d.ts +19 -0
  22. package/dist/analytics/tracker.d.ts.map +1 -0
  23. package/dist/analytics/tracker.js +41 -0
  24. package/dist/analytics/tracker.js.map +1 -0
  25. package/dist/analytics/viewed.d.ts +11 -0
  26. package/dist/analytics/viewed.d.ts.map +1 -0
  27. package/dist/analytics/viewed.js +16 -0
  28. package/dist/analytics/viewed.js.map +1 -0
  29. package/dist/components/PhotonOrder.d.ts +18 -18
  30. package/dist/components/PhotonOrder.d.ts.map +1 -1
  31. package/dist/components/PhotonOrder.js +34 -19
  32. package/dist/components/PhotonOrder.js.map +1 -1
  33. package/dist/components/PhotonPatient.d.ts +7 -35
  34. package/dist/components/PhotonPatient.d.ts.map +1 -1
  35. package/dist/components/PhotonPatient.js +6 -78
  36. package/dist/components/PhotonPatient.js.map +1 -1
  37. package/dist/components/PhotonPrescription.d.ts +15 -26
  38. package/dist/components/PhotonPrescription.d.ts.map +1 -1
  39. package/dist/components/PhotonPrescription.js +6 -360
  40. package/dist/components/PhotonPrescription.js.map +1 -1
  41. package/dist/components/format.d.ts +2 -2
  42. package/dist/components/format.js +2 -2
  43. package/dist/components/index.d.ts +1 -1
  44. package/dist/components/index.d.ts.map +1 -1
  45. package/dist/components/index.js +1 -1
  46. package/dist/components/index.js.map +1 -1
  47. package/dist/components/open.d.ts +11 -13
  48. package/dist/components/open.d.ts.map +1 -1
  49. package/dist/components/open.js +7 -2
  50. package/dist/components/open.js.map +1 -1
  51. package/dist/components/order/DraftOrderPrompt.d.ts +18 -0
  52. package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
  53. package/dist/components/order/DraftOrderPrompt.js +26 -0
  54. package/dist/components/order/DraftOrderPrompt.js.map +1 -0
  55. package/dist/components/patient/PatientCard/PatientCard.d.ts +30 -0
  56. package/dist/components/patient/PatientCard/PatientCard.d.ts.map +1 -0
  57. package/dist/components/patient/PatientCard/PatientCard.js +101 -0
  58. package/dist/components/patient/PatientCard/PatientCard.js.map +1 -0
  59. package/dist/components/patient/PatientCard/usePatientToShow.d.ts +22 -0
  60. package/dist/components/patient/PatientCard/usePatientToShow.d.ts.map +1 -0
  61. package/dist/components/patient/PatientCard/usePatientToShow.js +40 -0
  62. package/dist/components/patient/PatientCard/usePatientToShow.js.map +1 -0
  63. package/dist/components/patient/PatientIntakeForm.d.ts +16 -0
  64. package/dist/components/patient/PatientIntakeForm.d.ts.map +1 -0
  65. package/dist/components/patient/PatientIntakeForm.js +114 -0
  66. package/dist/components/patient/PatientIntakeForm.js.map +1 -0
  67. package/dist/components/patient/PatientSearch.d.ts +12 -0
  68. package/dist/components/patient/PatientSearch.d.ts.map +1 -0
  69. package/dist/components/patient/PatientSearch.js +148 -0
  70. package/dist/components/patient/PatientSearch.js.map +1 -0
  71. package/dist/components/patient/{Benefits.d.ts → PatientSummary/BenefitsInputForm.d.ts} +2 -2
  72. package/dist/components/patient/PatientSummary/BenefitsInputForm.d.ts.map +1 -0
  73. package/dist/components/patient/{Benefits.js → PatientSummary/BenefitsInputForm.js} +6 -5
  74. package/dist/components/patient/PatientSummary/BenefitsInputForm.js.map +1 -0
  75. package/dist/components/patient/{Clinical.d.ts → PatientSummary/ClinicalInputForm.d.ts} +15 -16
  76. package/dist/components/patient/PatientSummary/ClinicalInputForm.d.ts.map +1 -0
  77. package/dist/components/patient/{Clinical.js → PatientSummary/ClinicalInputForm.js} +29 -28
  78. package/dist/components/patient/PatientSummary/ClinicalInputForm.js.map +1 -0
  79. package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts +5 -0
  80. package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts.map +1 -0
  81. package/dist/components/patient/PatientSummary/CollapsedSummary.js +30 -0
  82. package/dist/components/patient/PatientSummary/CollapsedSummary.js.map +1 -0
  83. package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts +10 -0
  84. package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts.map +1 -0
  85. package/dist/components/patient/PatientSummary/PatientDetailsForm.js +65 -0
  86. package/dist/components/patient/PatientSummary/PatientDetailsForm.js.map +1 -0
  87. package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts +53 -0
  88. package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts.map +1 -0
  89. package/dist/components/patient/PatientSummary/PatientDetailsSchema.js +78 -0
  90. package/dist/components/patient/PatientSummary/PatientDetailsSchema.js.map +1 -0
  91. package/dist/components/patient/PatientSummary/PatientSummary.d.ts +46 -0
  92. package/dist/components/patient/PatientSummary/PatientSummary.d.ts.map +1 -0
  93. package/dist/components/patient/PatientSummary/PatientSummary.js +57 -0
  94. package/dist/components/patient/PatientSummary/PatientSummary.js.map +1 -0
  95. package/dist/components/patient/PatientSummary/SummaryHeader.d.ts +19 -0
  96. package/dist/components/patient/PatientSummary/SummaryHeader.d.ts.map +1 -0
  97. package/dist/components/patient/PatientSummary/SummaryHeader.js +22 -0
  98. package/dist/components/patient/PatientSummary/SummaryHeader.js.map +1 -0
  99. package/dist/components/patient/fields.d.ts +7 -26
  100. package/dist/components/patient/fields.d.ts.map +1 -1
  101. package/dist/components/patient/fields.js +11 -52
  102. package/dist/components/patient/fields.js.map +1 -1
  103. package/dist/components/patient/parsePatientSearchQuery.d.ts +16 -0
  104. package/dist/components/patient/parsePatientSearchQuery.d.ts.map +1 -0
  105. package/dist/components/patient/{query.js → parsePatientSearchQuery.js} +3 -10
  106. package/dist/components/patient/parsePatientSearchQuery.js.map +1 -0
  107. package/dist/components/prescription/PrescriptionCard.d.ts +51 -0
  108. package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
  109. package/dist/components/prescription/PrescriptionCard.js +186 -0
  110. package/dist/components/prescription/PrescriptionCard.js.map +1 -0
  111. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
  112. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
  113. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
  114. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
  115. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
  116. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
  117. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
  118. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
  119. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
  120. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
  121. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
  122. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
  123. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
  124. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
  125. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
  126. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
  127. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
  128. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
  129. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
  130. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
  131. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
  132. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
  133. package/dist/components/{TreatmentPicker.js → prescription/TreatmentSearch/TreatmentPicker.js} +113 -105
  134. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
  135. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
  136. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
  137. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
  138. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
  139. package/dist/components/schemaErrors.d.ts +13 -0
  140. package/dist/components/schemaErrors.d.ts.map +1 -0
  141. package/dist/components/schemaErrors.js +25 -0
  142. package/dist/components/schemaErrors.js.map +1 -0
  143. package/dist/components/search.d.ts +1 -1
  144. package/dist/components/search.js +1 -1
  145. package/dist/index.d.ts +2 -0
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +1 -0
  148. package/dist/index.js.map +1 -1
  149. package/dist/meta/version.d.ts +5 -0
  150. package/dist/meta/version.d.ts.map +1 -0
  151. package/dist/meta/version.js +5 -0
  152. package/dist/meta/version.js.map +1 -0
  153. package/dist/primitives/PhotonProvider.d.ts +3 -1
  154. package/dist/primitives/PhotonProvider.d.ts.map +1 -1
  155. package/dist/primitives/PhotonProvider.js +23 -11
  156. package/dist/primitives/PhotonProvider.js.map +1 -1
  157. package/dist/primitives/defaults.d.ts.map +1 -1
  158. package/dist/primitives/defaults.js +6 -3
  159. package/dist/primitives/defaults.js.map +1 -1
  160. package/dist/primitives/photonContext.d.ts +3 -0
  161. package/dist/primitives/photonContext.d.ts.map +1 -0
  162. package/dist/primitives/photonContext.js +3 -0
  163. package/dist/primitives/photonContext.js.map +1 -0
  164. package/dist/primitives/types.d.ts +15 -3
  165. package/dist/primitives/types.d.ts.map +1 -1
  166. package/dist/primitives/types.js.map +1 -1
  167. package/dist/primitives/useProvidedPhoton.d.ts +8 -0
  168. package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
  169. package/dist/primitives/useProvidedPhoton.js +8 -0
  170. package/dist/primitives/useProvidedPhoton.js.map +1 -0
  171. package/dist/styles.css +45 -3
  172. package/dist/test-utils/contract.d.ts.map +1 -1
  173. package/dist/test-utils/contract.js +23 -2
  174. package/dist/test-utils/contract.js.map +1 -1
  175. package/package.json +8 -3
  176. package/src/adapters/tailwind.tsx +52 -24
  177. package/src/analytics/PhotonAnalyticsProvider.test.tsx +190 -0
  178. package/src/analytics/PhotonAnalyticsProvider.tsx +151 -0
  179. package/src/analytics/cardLifecycle.test.tsx +272 -0
  180. package/src/analytics/cardLifecycle.ts +44 -0
  181. package/src/analytics/fieldInteraction.test.tsx +186 -0
  182. package/src/analytics/fieldInteraction.tsx +148 -0
  183. package/src/analytics/lifecycleOutcomes.test.ts +78 -0
  184. package/src/analytics/lifecycleOutcomes.ts +29 -0
  185. package/src/analytics/tracker.test.ts +52 -0
  186. package/src/analytics/tracker.ts +49 -0
  187. package/src/analytics/usePhotonAnalytics.test.tsx +106 -0
  188. package/src/analytics/viewed.ts +27 -0
  189. package/src/components/PhotonOrder.test.tsx +394 -0
  190. package/src/components/PhotonOrder.tsx +79 -53
  191. package/src/components/PhotonPatient.tsx +15 -166
  192. package/src/components/PhotonPrescription.test.tsx +120 -0
  193. package/src/components/PhotonPrescription.tsx +23 -583
  194. package/src/components/ScreeningAlerts.test.tsx +81 -0
  195. package/src/components/format.ts +2 -2
  196. package/src/components/index.ts +1 -1
  197. package/src/components/open.ts +13 -16
  198. package/src/components/order/DraftOrderPrompt.test.tsx +77 -0
  199. package/src/components/order/DraftOrderPrompt.tsx +81 -0
  200. package/src/components/patient/PatientCard/PatientCard.test.tsx +255 -0
  201. package/src/components/patient/PatientCard/PatientCard.tsx +177 -0
  202. package/src/components/patient/PatientCard/usePatientToShow.ts +44 -0
  203. package/src/components/patient/PatientIntakeForm.test.tsx +262 -0
  204. package/src/components/patient/PatientIntakeForm.tsx +222 -0
  205. package/src/components/patient/PatientSearch.test.tsx +204 -0
  206. package/src/components/patient/PatientSearch.tsx +221 -0
  207. package/src/components/patient/PatientSummary/BenefitsInputForm.test.tsx +164 -0
  208. package/src/components/patient/{Benefits.tsx → PatientSummary/BenefitsInputForm.tsx} +24 -16
  209. package/src/components/patient/PatientSummary/ClinicalInputForm.test.tsx +247 -0
  210. package/src/components/patient/{Clinical.tsx → PatientSummary/ClinicalInputForm.tsx} +53 -48
  211. package/src/components/patient/PatientSummary/CollapsedSummary.test.tsx +90 -0
  212. package/src/components/patient/PatientSummary/CollapsedSummary.tsx +46 -0
  213. package/src/components/patient/PatientSummary/PatientDetailsForm.test.tsx +201 -0
  214. package/src/components/patient/PatientSummary/PatientDetailsForm.tsx +320 -0
  215. package/src/components/patient/PatientSummary/PatientDetailsSchema.test.ts +296 -0
  216. package/src/components/patient/PatientSummary/PatientDetailsSchema.ts +95 -0
  217. package/src/components/patient/PatientSummary/PatientSummary.test.tsx +194 -0
  218. package/src/components/patient/PatientSummary/PatientSummary.tsx +225 -0
  219. package/src/components/patient/PatientSummary/SummaryHeader.test.tsx +183 -0
  220. package/src/components/patient/PatientSummary/SummaryHeader.tsx +85 -0
  221. package/src/components/patient/fields.tsx +12 -124
  222. package/src/components/patient/parsePatientSearchQuery.test.ts +107 -0
  223. package/src/components/patient/{query.ts → parsePatientSearchQuery.ts} +4 -15
  224. package/src/components/prescription/PrescriptionCard.test.tsx +247 -0
  225. package/src/components/prescription/PrescriptionCard.tsx +361 -0
  226. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +82 -0
  227. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
  228. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +206 -0
  229. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
  230. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +453 -0
  231. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
  232. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
  233. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
  234. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +72 -0
  235. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
  236. package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
  237. package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +695 -0
  238. package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
  239. package/src/components/schemaErrors.test.ts +49 -0
  240. package/src/components/schemaErrors.ts +34 -0
  241. package/src/components/search.tsx +1 -1
  242. package/src/index.ts +2 -0
  243. package/src/meta/version.test.ts +11 -0
  244. package/src/meta/version.ts +4 -0
  245. package/src/primitives/PhotonProvider.tsx +30 -15
  246. package/src/primitives/defaults.tsx +44 -21
  247. package/src/primitives/photonContext.ts +4 -0
  248. package/src/primitives/types.ts +15 -3
  249. package/src/primitives/useProvidedPhoton.ts +21 -0
  250. package/src/styles.css +45 -3
  251. package/src/test-utils/contract.tsx +45 -2
  252. package/dist/components/TreatmentPicker.d.ts +0 -45
  253. package/dist/components/TreatmentPicker.d.ts.map +0 -1
  254. package/dist/components/TreatmentPicker.js.map +0 -1
  255. package/dist/components/patient/Benefits.d.ts.map +0 -1
  256. package/dist/components/patient/Benefits.js.map +0 -1
  257. package/dist/components/patient/Clinical.d.ts.map +0 -1
  258. package/dist/components/patient/Clinical.js.map +0 -1
  259. package/dist/components/patient/IntakeForm.d.ts +0 -10
  260. package/dist/components/patient/IntakeForm.d.ts.map +0 -1
  261. package/dist/components/patient/IntakeForm.js +0 -324
  262. package/dist/components/patient/IntakeForm.js.map +0 -1
  263. package/dist/components/patient/Summary.d.ts +0 -48
  264. package/dist/components/patient/Summary.d.ts.map +0 -1
  265. package/dist/components/patient/Summary.js +0 -80
  266. package/dist/components/patient/Summary.js.map +0 -1
  267. package/dist/components/patient/query.d.ts +0 -23
  268. package/dist/components/patient/query.d.ts.map +0 -1
  269. package/dist/components/patient/query.js.map +0 -1
  270. package/src/components/TreatmentPicker.tsx +0 -350
  271. package/src/components/patient/IntakeForm.tsx +0 -532
  272. package/src/components/patient/Summary.tsx +0 -310
@@ -0,0 +1,107 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { parsePatientSearchQuery } from "./parsePatientSearchQuery.ts";
3
+
4
+ describe("parsePatientSearchQuery", () => {
5
+ describe("parse names", () => {
6
+ it("one word: a first name", () => {
7
+ expect(parsePatientSearchQuery("Ada")).toEqual({ name: { first: "Ada" } });
8
+ });
9
+
10
+ it("two words: first name, then last name", () => {
11
+ expect(parsePatientSearchQuery("Ada Lovelace")).toEqual({ name: { first: "Ada", last: "Lovelace" } });
12
+ });
13
+
14
+ it("extra spaces: ignored", () => {
15
+ expect(parsePatientSearchQuery(" Ada Lovelace ")).toEqual({ name: { first: "Ada", last: "Lovelace" } });
16
+ });
17
+
18
+ it("nothing typed: nothing parsed", () => {
19
+ expect(parsePatientSearchQuery(" ")).toEqual({});
20
+ });
21
+
22
+ it("three words: the first word is the first name, the rest is the last name", () => {
23
+ expect(parsePatientSearchQuery("Mary Ann Smith")).toEqual({ name: { first: "Mary", last: "Ann Smith" } });
24
+ });
25
+ });
26
+
27
+ describe("parse dates of birth to YYYY-MM-DD format", () => {
28
+ it("YYYY-MM-DD format: supported", () => {
29
+ expect(parsePatientSearchQuery("1990-01-01")).toEqual({ dateOfBirth: "1990-01-01" });
30
+ });
31
+
32
+ it("M/D/YYYY format: supported", () => {
33
+ expect(parsePatientSearchQuery("1/2/1990")).toEqual({ dateOfBirth: "1990-01-02" });
34
+ });
35
+
36
+ it("MM-DD-YYYY format: supported", () => {
37
+ expect(parsePatientSearchQuery("01-02-1990")).toEqual({ dateOfBirth: "1990-01-02" });
38
+ });
39
+
40
+ // Pins today's behavior
41
+ // TODO: return nothing for impossible dates
42
+ it("an impossible date: still sent as a date", () => {
43
+ expect(parsePatientSearchQuery("13/45/1990")).toEqual({ dateOfBirth: "1990-13-45" });
44
+ });
45
+
46
+ // Pins today's behavior
47
+ // TODO: return nothing for unsupported date formats
48
+ it("a two-digit year or an unpadded YYYY-M-D: not supported read as a name", () => {
49
+ expect(parsePatientSearchQuery("1/1/90")).toEqual({ name: { first: "1/1/90" } });
50
+ expect(parsePatientSearchQuery("1990-1-1")).toEqual({ name: { first: "1990-1-1" } });
51
+ });
52
+ });
53
+
54
+ describe("parse phone numbers to E.164", () => {
55
+ it("10 digits, however punctuated without spaces: supported", () => {
56
+ expect(parsePatientSearchQuery("4155550172")).toEqual({ phone: "+14155550172" });
57
+ expect(parsePatientSearchQuery("415-555-0172")).toEqual({ phone: "+14155550172" });
58
+ expect(parsePatientSearchQuery("(415)555-0172")).toEqual({ phone: "+14155550172" });
59
+ });
60
+
61
+ it("11 digits starting with 1: supported", () => {
62
+ expect(parsePatientSearchQuery("+14155550172")).toEqual({ phone: "+14155550172" });
63
+ });
64
+
65
+ // Pins today's behavior
66
+ // TODO: support a phone typed with spaces, e.g. "(415) 555-0172"
67
+ it("a phone with a space in it: read as a name", () => {
68
+ expect(parsePatientSearchQuery("(415) 555-0172")).toEqual({ name: { first: "(415)", last: "555-0172" } });
69
+ });
70
+
71
+ // Pins today's behavior
72
+ // TODO: decide what an 11-digit number not starting with 1 is
73
+ it("11 digits not starting with 1: sent as typed, not E.164", () => {
74
+ expect(parsePatientSearchQuery("25555550172")).toEqual({ phone: "25555550172" });
75
+ });
76
+
77
+ // Pins today's behavior
78
+ // TODO: return nothing for invalid phone numbers
79
+ it("fewer than 10 digits: read as a name", () => {
80
+ expect(parsePatientSearchQuery("5550172")).toEqual({ name: { first: "5550172" } });
81
+ });
82
+ });
83
+
84
+ describe("parse email", () => {
85
+ it("an email: parsed as is", () => {
86
+ expect(parsePatientSearchQuery("ada@example.com")).toEqual({ email: "ada@example.com" });
87
+ });
88
+ });
89
+
90
+ // TODO: we don't need to support combined inputs if it complicates code implementation
91
+ describe("parse combined inputs", () => {
92
+ it("date of birth with a name, in any order: both parsed", () => {
93
+ const expected = { name: { first: "Ada", last: "Lovelace" }, dateOfBirth: "1990-01-01" };
94
+ expect(parsePatientSearchQuery("Ada Lovelace 1/1/1990")).toEqual(expected);
95
+ expect(parsePatientSearchQuery("1/1/1990 Ada Lovelace")).toEqual(expected);
96
+ });
97
+
98
+ it("name, date of birth, phone and email at once: each part parsed", () => {
99
+ expect(parsePatientSearchQuery("Ada Lovelace 1/1/1990 4155550172 ada@example.com")).toEqual({
100
+ name: { first: "Ada", last: "Lovelace" },
101
+ dateOfBirth: "1990-01-01",
102
+ phone: "+14155550172",
103
+ email: "ada@example.com",
104
+ });
105
+ });
106
+ });
107
+ });
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import { toE164 } from "../format.ts";
12
12
 
13
- export interface ParsedQuery {
13
+ export interface ParsedPatientSearchQuery {
14
14
  name?: { first?: string; last?: string };
15
15
  dateOfBirth?: string;
16
16
  phone?: string;
@@ -37,11 +37,11 @@ function asPhone(token: string): string | undefined {
37
37
 
38
38
  /**
39
39
  * What was typed, as the server takes it. Anything that reads as a date, a phone or an email is taken as
40
- * one; what's left is the name, first word first. A single word is a first name — `searchBoth` says when
40
+ * one; what's left is the name, first word first. A single word is a first name — PatientSearch's `searchBoth` says when
41
41
  * it's worth trying as a last name too.
42
42
  */
43
- export function parseQuery(text: string): ParsedQuery {
44
- const parsed: ParsedQuery = {};
43
+ export function parsePatientSearchQuery(text: string): ParsedPatientSearchQuery {
44
+ const parsed: ParsedPatientSearchQuery = {};
45
45
  const words: string[] = [];
46
46
  for (const token of text.trim().split(/\s+/).filter(Boolean)) {
47
47
  const date = asDate(token);
@@ -64,14 +64,3 @@ export function parseQuery(text: string): ParsedQuery {
64
64
  if (first) parsed.name = rest.length ? { first, last: rest.join(" ") } : { first };
65
65
  return parsed;
66
66
  }
67
-
68
- /** Whether a query says anything the server can match on. */
69
- export const isSearchable = (q: ParsedQuery) =>
70
- Boolean(q.name?.first || q.name?.last || q.dateOfBirth || q.phone || q.email);
71
-
72
- /**
73
- * One word could be either name. It goes as a first name; if nothing comes back, it's worth asking again
74
- * as a last name — "Lovelace" is as likely as "Ada".
75
- */
76
- export const searchBoth = (q: ParsedQuery): ParsedQuery | null =>
77
- q.name?.first && !q.name.last && !q.dateOfBirth && !q.phone && !q.email ? { name: { last: q.name.first } } : null;
@@ -0,0 +1,247 @@
1
+ import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
2
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
3
+ import { alert, type change, fakeNetworkApiClient, payload, rx } from "@photonhealth/client/testing";
4
+ import { PrescriptionCard } from "./PrescriptionCard.tsx";
5
+ import {
6
+ fakeNetworkApi,
7
+ patient,
8
+ screeningUnavailableChange,
9
+ tapDrug,
10
+ withPhoton,
11
+ } from "../../../test/cards.fixtures.tsx";
12
+ import {
13
+ meAsPrescriber,
14
+ recordAnalytics,
15
+ type RecordedAnalytics,
16
+ unmountAndRestoreFetch,
17
+ withAnalytics,
18
+ } from "../../../test/analytics.fixtures.tsx";
19
+
20
+ const allergyAlertTitle = "allergen · moderate";
21
+ const anyScreeningAlertTitle = /^(allergen|drug|condition) · /;
22
+
23
+ describe("PrescriptionCard", () => {
24
+ it("finds a drug, picks its form and strength, takes the server's directions, and is signed", async () => {
25
+ const { client, names } = fakeNetworkApiClient({
26
+ GetPatient: () => payload("patient", "PatientPayload", patient),
27
+ ...fakeNetworkApi({
28
+ prescriptions: {
29
+ amox: [
30
+ ["Amoxicillin", "Capsule", "250 MG"],
31
+ ["Amoxicillin", "Capsule", "500 MG"],
32
+ ["Amoxicillin", "Tablet", "875 MG"],
33
+ ],
34
+ },
35
+ }),
36
+ });
37
+ render(<PrescriptionCard patient="pat_1" />, { wrapper: withPhoton(client) });
38
+
39
+ const treatment = await screen.findByLabelText("Treatment");
40
+ treatment.focus();
41
+ fireEvent.change(treatment, { target: { value: "amox" } });
42
+ await tapDrug(/^Amoxicillin/);
43
+ fireEvent.click(within(screen.getByRole("group", { name: "Form" })).getByText("Capsule"));
44
+ fireEvent.click(within(screen.getByRole("group", { name: "Strength" })).getByText("500 mg"));
45
+
46
+ expect(await screen.findByRole("heading", { name: "Amoxicillin" })).toBeTruthy();
47
+ expect(((await screen.findByLabelText("Directions (sig)")) as HTMLTextAreaElement).value).toBe("Take as directed");
48
+ expect((screen.getByLabelText("Quantity") as HTMLInputElement).value).toBe("30");
49
+
50
+ fireEvent.click(await screen.findByRole("button", { name: "Sign" }));
51
+ expect(await screen.findByText("Signed")).toBeTruthy();
52
+ await waitFor(() => expect(screen.queryByLabelText("Directions (sig)")).toBeNull()); // signed is read-only
53
+ expect(names()).toContain("SignPrescription");
54
+ });
55
+
56
+ it("doesn't sign while a required field has an error", async () => {
57
+ const { client, names } = fakeNetworkApiClient({
58
+ GetPatient: () => payload("patient", "PatientPayload", patient),
59
+ ...fakeNetworkApi({ prescriptions: { amox: [["Amoxicillin", "Capsule", "500 MG"]] } }),
60
+ });
61
+ render(<PrescriptionCard patient="pat_1" />, { wrapper: withPhoton(client) });
62
+
63
+ const treatment = await screen.findByLabelText("Treatment");
64
+ treatment.focus();
65
+ fireEvent.change(treatment, { target: { value: "amox" } });
66
+ await tapDrug(/^Amoxicillin/);
67
+ await screen.findByLabelText("Directions (sig)");
68
+ fireEvent.change(screen.getByLabelText("Quantity"), { target: { value: "" } });
69
+
70
+ fireEvent.click(screen.getByRole("button", { name: "Sign" }));
71
+ expect(await screen.findByText("Required")).toBeTruthy();
72
+ expect(names()).not.toContain("SignPrescription");
73
+ });
74
+
75
+ it("offers Sign once a product is picked before there's a patient, and says a patient is required", async () => {
76
+ const { client, names } = fakeNetworkApiClient({
77
+ ...fakeNetworkApi({ prescriptions: { amox: [["Amoxicillin", "Capsule", "500 MG"]] } }),
78
+ });
79
+ render(<PrescriptionCard />, { wrapper: withPhoton(client) });
80
+
81
+ const treatment = await screen.findByLabelText("Treatment");
82
+ treatment.focus();
83
+ fireEvent.change(treatment, { target: { value: "amox" } });
84
+ await tapDrug(/^Amoxicillin/);
85
+ await screen.findByLabelText("Directions (sig)");
86
+ // Nothing is drafted without a patient, so the required fields start empty.
87
+ fireEvent.change(screen.getByLabelText("Directions (sig)"), { target: { value: "1 cap PO TID" } });
88
+ fireEvent.change(screen.getByLabelText("Quantity"), { target: { value: "21" } });
89
+ fireEvent.change(screen.getByLabelText("Days supply"), { target: { value: "7" } });
90
+
91
+ fireEvent.click(screen.getByRole("button", { name: "Sign" }));
92
+ expect(await screen.findByText("A patient is required for signing")).toBeTruthy();
93
+ expect(names()).not.toContain("SyncPrescription");
94
+ expect(names()).not.toContain("SignPrescription");
95
+ });
96
+ });
97
+
98
+ describe("PrescriptionCard: screening alerts", () => {
99
+ it("a picked drug's alert shows above its directions, and Sign is still offered", async () => {
100
+ renderCardDraftingAmoxicillin({ screeningAlerts: [alert] });
101
+ await pickAmoxicillin();
102
+
103
+ const alertTitle = await screen.findByText(allergyAlertTitle);
104
+ const directions = await screen.findByLabelText("Directions (sig)");
105
+ expect(alertTitle.compareDocumentPosition(directions) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
106
+ expect(screen.getByText(`${alert.description} (amoxicillin)`)).toBeInTheDocument();
107
+ expect(screen.getByRole("button", { name: "Sign" })).toBeEnabled();
108
+ });
109
+
110
+ it("Sign signs a prescription that has alerts without asking for confirmation", async () => {
111
+ const { names } = renderCardDraftingAmoxicillin({ screeningAlerts: [alert] });
112
+ await pickAmoxicillin();
113
+ await screen.findByText(allergyAlertTitle);
114
+
115
+ fireEvent.click(await screen.findByRole("button", { name: "Sign" }));
116
+
117
+ expect(await screen.findByText("Signed")).toBeInTheDocument();
118
+ expect(names()).toContain("SignPrescription");
119
+ expect(screen.queryByRole("dialog")).toBeNull();
120
+ expect(screen.queryByRole("alertdialog")).toBeNull();
121
+ });
122
+
123
+ it("the alerts are no longer shown once the prescription is signed", async () => {
124
+ renderCardDraftingAmoxicillin({ screeningAlerts: [alert] });
125
+ await pickAmoxicillin();
126
+ await screen.findByText(allergyAlertTitle);
127
+
128
+ fireEvent.click(await screen.findByRole("button", { name: "Sign" }));
129
+
130
+ await screen.findByText("Signed");
131
+ await waitFor(() => expect(screen.queryByText(allergyAlertTitle)).toBeNull());
132
+ });
133
+
134
+ it("a locked prescription that isn't signed still shows its alerts", async () => {
135
+ renderCardOpening(rx({ screeningAlerts: [alert] }), { locked: true });
136
+ expect(await screen.findByText(allergyAlertTitle)).toBeInTheDocument();
137
+ expect(screen.queryByRole("button", { name: "Sign" })).toBeNull();
138
+ });
139
+
140
+ it("a signed prescription opened later shows none of its alerts", async () => {
141
+ renderCardOpening(rx({ screeningAlerts: [alert], signing: { ...rx().signing, state: "SIGNED" } }));
142
+ expect(await screen.findByText("Signed")).toBeInTheDocument();
143
+ expect(screen.queryByText(allergyAlertTitle)).toBeNull();
144
+ });
145
+
146
+ it("screening that failed while drafting shows a dismissible notice in the info tone and no alerts", async () => {
147
+ renderCardDraftingAmoxicillin({ screeningAlerts: null });
148
+ await pickAmoxicillin();
149
+
150
+ const notice = (await screen.findByText("Prescription screening")).closest<HTMLElement>("[data-tone]")!;
151
+ expect(notice).toHaveAttribute("data-tone", "info");
152
+ expect(within(notice).getByText("Prescription screening could not be completed.")).toBeInTheDocument();
153
+ expect(screen.queryByText(anyScreeningAlertTitle)).toBeNull();
154
+
155
+ fireEvent.click(within(notice).getByRole("button", { name: "Dismiss" }));
156
+ expect(screen.queryByText("Prescription screening")).toBeNull();
157
+ });
158
+
159
+ it("screening that failed while drafting doesn't stop Sign from signing", async () => {
160
+ const { names } = renderCardDraftingAmoxicillin({ screeningAlerts: null });
161
+ await pickAmoxicillin();
162
+ await screen.findByText("Prescription screening");
163
+
164
+ fireEvent.click(await screen.findByRole("button", { name: "Sign" }));
165
+
166
+ expect(await screen.findByText("Signed")).toBeInTheDocument();
167
+ expect(names()).toContain("SignPrescription");
168
+ });
169
+
170
+ it("a prescription whose screening failed, opened later, shows neither alerts nor the notice", async () => {
171
+ renderCardOpening(rx({ screeningAlerts: null }), { changes: [screeningUnavailableChange] });
172
+ expect(await screen.findByLabelText("Directions (sig)")).toBeInTheDocument();
173
+ expect(screen.queryByText(anyScreeningAlertTitle)).toBeNull();
174
+ expect(screen.queryByText("Prescription screening")).toBeNull();
175
+ });
176
+ });
177
+
178
+ describe("PrescriptionCard: screening alert analytics", () => {
179
+ let analytics: RecordedAnalytics;
180
+ beforeEach(() => {
181
+ analytics = recordAnalytics();
182
+ });
183
+ afterEach(unmountAndRestoreFetch);
184
+
185
+ it("signing a prescription that has alerts sends no screening alert event: Prescription Signed counts them", async () => {
186
+ const { client } = fakeNetworkApiClient({
187
+ ...meAsPrescriber,
188
+ GetPatient: () => payload("patient", "PatientPayload", patient),
189
+ ...fakeNetworkApi({ prescriptions: amoxicillinSearch, screeningAlerts: [alert] }),
190
+ });
191
+ render(<PrescriptionCard patient="pat_1" />, { wrapper: withAnalytics(client) });
192
+ await pickAmoxicillin();
193
+ await screen.findByText(allergyAlertTitle);
194
+
195
+ fireEvent.click(await screen.findByRole("button", { name: "Sign" }));
196
+ await screen.findByText("Signed");
197
+
198
+ await analytics.expectSentOnce("Field Interaction treatment focus");
199
+ await analytics.expectSentOnce("Field Interaction treatment change");
200
+ await analytics.expectSentOnce("Field Interaction treatment blur");
201
+ await analytics.expectSentOnce("Draft Prescription Added");
202
+ await analytics.expectSentOnce("Prescription Signed");
203
+ await analytics.expectEventCount(5);
204
+ expect(prescriptionSignedSent(analytics)).toMatchObject({ screeningAlertCount: 1 });
205
+ });
206
+ });
207
+
208
+ const amoxicillinSearch = { amox: [["Amoxicillin", "Capsule", "500 MG"]] } satisfies Parameters<
209
+ typeof fakeNetworkApi
210
+ >[0]["prescriptions"];
211
+
212
+ type ScreeningAlertsFromServer = Parameters<typeof fakeNetworkApi>[0]["screeningAlerts"];
213
+
214
+ function renderCardDraftingAmoxicillin({ screeningAlerts }: { screeningAlerts: ScreeningAlertsFromServer }) {
215
+ const { client, names } = fakeNetworkApiClient({
216
+ GetPatient: () => payload("patient", "PatientPayload", patient),
217
+ ...fakeNetworkApi({ prescriptions: amoxicillinSearch, screeningAlerts }),
218
+ });
219
+ render(<PrescriptionCard patient="pat_1" />, { wrapper: withPhoton(client) });
220
+ return { names };
221
+ }
222
+
223
+ function renderCardOpening(
224
+ prescription: ReturnType<typeof rx>,
225
+ { locked, changes = [] }: { locked?: boolean; changes?: ReturnType<typeof change>[] } = {},
226
+ ) {
227
+ const { client } = fakeNetworkApiClient({
228
+ GetPatient: () => payload("patient", "PatientPayload", patient),
229
+ GetPrescription: () => payload("prescription", "PrescriptionPayload", prescription, { changes } as never),
230
+ });
231
+ render(<PrescriptionCard prescription={prescription.id} locked={locked} />, { wrapper: withPhoton(client) });
232
+ }
233
+
234
+ async function pickAmoxicillin() {
235
+ const treatment = await screen.findByLabelText("Treatment");
236
+ treatment.focus();
237
+ fireEvent.change(treatment, { target: { value: "amox" } });
238
+ await tapDrug(/^Amoxicillin/);
239
+ }
240
+
241
+ function prescriptionSignedSent(analytics: RecordedAnalytics) {
242
+ const sent = analytics
243
+ .bodies()
244
+ .map((body) => JSON.parse(body) as { event: string; properties: Record<string, unknown> })
245
+ .find(({ event }) => event === "Prescription Signed");
246
+ return sent?.properties;
247
+ }