11import Oystehr , { BatchInputPostRequest } from '@oystehr/sdk' ;
2+ import { Page } from '@playwright/test' ;
23import {
34 Address ,
45 Appointment ,
56 ClinicalImpression ,
67 Consent ,
8+ ContactPoint ,
79 DocumentReference ,
810 Encounter ,
911 FhirResource ,
@@ -20,8 +22,10 @@ import {
2022import { readFileSync } from 'fs' ;
2123import { DateTime } from 'luxon' ;
2224import { dirname , join } from 'path' ;
25+ import { VisitDetailsPage } from 'tests/e2e/page/VisitDetailsPage' ;
2326import { fileURLToPath } from 'url' ;
2427import {
28+ CancellationReasonOptionsInPerson ,
2529 cleanAppointmentGraph ,
2630 CreateAppointmentResponse ,
2731 createFetchClientWithOystehrAuth ,
@@ -30,6 +34,7 @@ import {
3034 FHIR_APPOINTMENT_INTAKE_HARVESTING_COMPLETED_TAG ,
3135 FHIR_APPOINTMENT_PREPROCESSED_TAG ,
3236 formatPhoneNumber ,
37+ genderMap ,
3338 GetPaperworkAnswers ,
3439 RelationshipOption ,
3540 ServiceMode ,
@@ -65,18 +70,22 @@ export function getAccessTokenFromUserJson(): string {
6570 return token ;
6671}
6772
73+ const IS_SMOKE_TEST = process . env . SMOKE_TEST === 'true' || false ;
74+
6875const EightDigitsString = '20250519' ;
6976
70- export const PATIENT_FIRST_NAME = 'Jon' ;
71- export const PATIENT_LAST_NAME = 'Snow' ;
72- export const PATIENT_GENDER = 'Male' ;
77+ export const PATIENT_FIRST_NAME = IS_SMOKE_TEST ? 'Katie' : 'Jon' ;
78+ export const PATIENT_LAST_NAME = IS_SMOKE_TEST ? 'Patient' : 'Snow' ;
79+ export const PATIENT_GENDER = IS_SMOKE_TEST ? 'Female' : 'Male' ;
7380
7481export const PATIENT_BIRTHDAY = '2002-07-07' ;
7582export const PATIENT_BIRTH_DATE_SHORT = '07/07/2002' ;
7683export const PATIENT_BIRTH_DATE_LONG = 'July 07, 2002' ;
7784
7885export const PATIENT_PHONE_NUMBER = '21' + EightDigitsString ;
79- export const PATIENT_EMAIL = `john.doe.${ EightDigitsString } 3@example.com` ;
86+ export const PATIENT_EMAIL = IS_SMOKE_TEST
87+ ? `ykulik+${ PATIENT_FIRST_NAME } ${ PATIENT_LAST_NAME } @masslight.com`
88+ : `john.doe.${ EightDigitsString } 3@example.com` ;
8089export const PATIENT_CITY = 'New York' ;
8190export const PATIENT_LINE = `${ EightDigitsString } Test Line` ;
8291export const PATIENT_LINE_2 = 'Apt 4B' ;
@@ -171,6 +180,25 @@ export class ResourceHandler {
171180 } ) ;
172181 }
173182
183+ private async findTestPatientResource ( ) : Promise < Patient | null > {
184+ const oystehr = await this . apiClient ;
185+ const patientSearchResults = await oystehr . fhir . search < Patient > ( {
186+ resourceType : 'Patient' ,
187+ params : [
188+ {
189+ name : 'given' ,
190+ value : 'Katie' ,
191+ } ,
192+ {
193+ name : 'family' ,
194+ value : 'Patient' ,
195+ } ,
196+ ] ,
197+ } ) ;
198+ const patient = patientSearchResults . unbundle ( ) [ 0 ] as Patient ;
199+ return patient ;
200+ }
201+
174202 public async createAppointment ( inputParams ?: CreateTestAppointmentInput ) : Promise < CreateAppointmentResponse > {
175203 try {
176204 const address : Address = {
@@ -180,17 +208,53 @@ export class ResourceHandler {
180208 postalCode : inputParams ?. postalCode ?? PATIENT_POSTAL_CODE ,
181209 } ;
182210
183- const patientData = {
184- firstNames : [ inputParams ?. firstName ?? PATIENT_FIRST_NAME ] ,
185- lastNames : [ inputParams ?. lastName ?? PATIENT_LAST_NAME ] ,
186- numberOfAppointments : 1 ,
187- reasonsForVisit : [ inputParams ?. reasonsForVisit ?? PATIENT_REASON_FOR_VISIT ] ,
188- phoneNumbers : [ inputParams ?. phoneNumber ?? PATIENT_PHONE_NUMBER ] ,
189- emails : [ inputParams ?. email ?? PATIENT_EMAIL ] ,
190- gender : inputParams ?. gender ?? PATIENT_GENDER . toLowerCase ( ) ,
191- birthDate : inputParams ?. birthDate ?? PATIENT_BIRTHDAY ,
192- address : [ address ] ,
193- } ;
211+ let patientData = { } ;
212+ let phoneNumber = formatPhoneNumber ( PATIENT_PHONE_NUMBER ) ! ;
213+
214+ console . log ( 'Initial phone number:' , phoneNumber ) ;
215+
216+ if ( IS_SMOKE_TEST ) {
217+ console . log ( 'In SMOKE_TEST mode using Katie Patient' ) ;
218+ // if it's SMOKE_TEST mode - find Katie Patient patient resource and use it to create appointment
219+ const testPatient = await this . findTestPatientResource ( ) ;
220+
221+ if ( ! testPatient ) {
222+ console . log ( 'Katie Patient not found, will create new patient for Katie Patient' ) ;
223+ } else {
224+ patientData = {
225+ firstNames : [ testPatient ?. name ?. [ 0 ] ?. given ?. [ 0 ] ?? '' ] ,
226+ lastNames : [ testPatient ?. name ?. [ 0 ] ?. family ?? '' ] ,
227+ numberOfAppointments : 1 ,
228+ reasonsForVisit : [ inputParams ?. reasonsForVisit ?? PATIENT_REASON_FOR_VISIT ] ,
229+ phoneNumbers : [
230+ testPatient ?. telecom
231+ ?. find ( ( telecom : ContactPoint ) => telecom . system === 'phone' )
232+ ?. value ?. replace ( '+1' , '' ) || PATIENT_PHONE_NUMBER ,
233+ ] ,
234+ emails : [ testPatient ?. telecom ?. find ( ( telecom : ContactPoint ) => telecom . system === 'email' ) ?. value ?? '' ] ,
235+ gender : testPatient ?. gender ?? genderMap . female ,
236+ birthDate : testPatient ?. birthDate ?? '' ,
237+ } ;
238+ phoneNumber = formatPhoneNumber (
239+ testPatient ?. telecom ?. find ( ( telecom : ContactPoint ) => telecom . system === 'phone' ) ?. value ||
240+ PATIENT_PHONE_NUMBER
241+ ) ! ;
242+ }
243+ }
244+
245+ if ( ! IS_SMOKE_TEST || Object . keys ( patientData ) . length === 0 ) {
246+ patientData = {
247+ firstNames : [ inputParams ?. firstName ?? PATIENT_FIRST_NAME ] ,
248+ lastNames : [ inputParams ?. lastName ?? PATIENT_LAST_NAME ] ,
249+ numberOfAppointments : 1 ,
250+ reasonsForVisit : [ inputParams ?. reasonsForVisit ?? PATIENT_REASON_FOR_VISIT ] ,
251+ phoneNumbers : [ inputParams ?. phoneNumber ?? PATIENT_PHONE_NUMBER ] ,
252+ emails : [ inputParams ?. email ?? PATIENT_EMAIL ] ,
253+ gender : inputParams ?. gender ?? PATIENT_GENDER . toLowerCase ( ) ,
254+ birthDate : inputParams ?. birthDate ?? PATIENT_BIRTHDAY ,
255+ address : [ address ] ,
256+ } ;
257+ }
194258
195259 if ( ! process . env . PROJECT_API_ZAMBDA_URL ) {
196260 throw new Error ( 'PROJECT_API_ZAMBDA_URL is not set' ) ;
@@ -208,11 +272,13 @@ export class ResourceHandler {
208272 throw new Error ( 'PROJECT_ID is not set' ) ;
209273 }
210274
275+ console . log ( formatPhoneNumber ( PATIENT_PHONE_NUMBER ) ! , phoneNumber ) ;
276+
211277 // Create appointment and related resources using zambda
212278 const appointmentData = await createSampleAppointments ( {
213279 oystehr : await this . apiClient ,
214280 authToken : getAccessTokenFromUserJson ( ) ,
215- phoneNumber : formatPhoneNumber ( PATIENT_PHONE_NUMBER ) ! ,
281+ phoneNumber,
216282 createAppointmentZambdaId : this . #createAppointmentZambdaId,
217283 zambdaUrl : process . env . PROJECT_API_ZAMBDA_URL ,
218284 serviceMode : this . #flow === 'telemed' ? ServiceMode . virtual : ServiceMode [ 'in-person' ] ,
@@ -347,7 +413,19 @@ export class ResourceHandler {
347413 } ;
348414 }
349415
350- public async cleanupResources ( ) : Promise < void > {
416+ public async cleanupResources ( page ?: Page ) : Promise < void > {
417+ if ( process . env . SMOKE_TEST === 'true' ) {
418+ console . log ( 'Smoke test mode detected, canceling visits through UI' ) ;
419+ if ( ! page ) {
420+ throw new Error ( 'Page instance parameter is required to cancel visit in smoke test mode' ) ;
421+ }
422+ await page ?. goto ( `/visit/${ this . appointment . id ! } ` ) ;
423+ const visitDetails = new VisitDetailsPage ( page ! ) ;
424+ await visitDetails . clickCancelVisitButton ( ) ;
425+ await visitDetails . selectCancelationReason ( CancellationReasonOptionsInPerson [ 'Patient improved' ] ) ;
426+ await visitDetails . clickCancelButtonFromDialogue ( ) ;
427+ return ;
428+ }
351429 console . log ( '------------------------------------------------------------' ) ;
352430 console . log ( 'Starting resource cleanup' ) ;
353431 // TODO: here we should change appointment id to encounter id when we'll fix this bug in frontend,
0 commit comments