Guest User

Untitled

a guest
Apr 3rd, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.48 KB | None | 0 0
  1. package edu.ncsu.csc.itrust2.cucumber;
  2.  
  3. import static org.junit.Assert.assertEquals;
  4. import static org.junit.Assert.assertTrue;
  5. import static org.junit.Assert.fail;
  6.  
  7. import java.time.ZonedDateTime;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10.  
  11. import org.openqa.selenium.By;
  12. import org.openqa.selenium.JavascriptExecutor;
  13. import org.openqa.selenium.WebElement;
  14.  
  15. import cucumber.api.java.en.Given;
  16. import cucumber.api.java.en.Then;
  17. import cucumber.api.java.en.When;
  18. import edu.ncsu.csc.itrust2.forms.admin.ICDCodeForm;
  19. import edu.ncsu.csc.itrust2.forms.hcp.GeneralCheckupForm;
  20. import edu.ncsu.csc.itrust2.forms.hcp.OphthalmologySurgeryForm;
  21. import edu.ncsu.csc.itrust2.models.enums.AppointmentType;
  22. import edu.ncsu.csc.itrust2.models.enums.EyeSurgeryType;
  23. import edu.ncsu.csc.itrust2.models.enums.Gender;
  24. import edu.ncsu.csc.itrust2.models.enums.HouseholdSmokingStatus;
  25. import edu.ncsu.csc.itrust2.models.enums.PatientSmokingStatus;
  26. import edu.ncsu.csc.itrust2.models.enums.Role;
  27. import edu.ncsu.csc.itrust2.models.persistent.BasicHealthMetrics;
  28. import edu.ncsu.csc.itrust2.models.persistent.Diagnosis;
  29. import edu.ncsu.csc.itrust2.models.persistent.DomainObject;
  30. import edu.ncsu.csc.itrust2.models.persistent.GeneralCheckup;
  31. import edu.ncsu.csc.itrust2.models.persistent.GeneralOphthalmology;
  32. import edu.ncsu.csc.itrust2.models.persistent.Hospital;
  33. import edu.ncsu.csc.itrust2.models.persistent.ICDCode;
  34. import edu.ncsu.csc.itrust2.models.persistent.OfficeVisit;
  35. import edu.ncsu.csc.itrust2.models.persistent.OphthalmologySurgery;
  36. import edu.ncsu.csc.itrust2.models.persistent.Patient;
  37. import edu.ncsu.csc.itrust2.models.persistent.User;
  38.  
  39. /**
  40. * Step definitions for and HCP to view all of the patients' office visits.
  41. *
  42. * @author Domenick DiBiase (dndibias)
  43. */
  44. public class PatientViewObstetricsOfficeVisitStepDefs extends CucumberTest {
  45.  
  46. private final String baseUrl = "http://localhost:8080/iTrust2";
  47. private final String patientString = "sallymay";
  48.  
  49. /**
  50. * Asserts that the text is on the page
  51. *
  52. * @param text
  53. * text to check
  54. */
  55. public void assertTextPresent ( final String text ) {
  56. try {
  57. assertTrue( driver.getPageSource().contains( text ) );
  58. }
  59. catch ( final Exception e ) {
  60. fail();
  61. }
  62. }
  63.  
  64. /**
  65. * A function used to check that the patient can select the correct
  66. * Obstetrics office visit record
  67. *
  68. * @param viewPatient
  69. */
  70. private void clickAndCheckPatientButton ( final String viewPatient ) {
  71. final List<WebElement> radioList = driver.findElements( By.name( "patients" ) );
  72.  
  73. for ( final WebElement element : radioList ) {
  74. if ( element.getAttribute( "value" ).equals( viewPatient ) ) {
  75. element.click();
  76. assertTextPresent( "Obstetrics Records for: " + viewPatient );
  77. return;
  78. }
  79. }
  80.  
  81. fail( "The patient isn't in the radio list." );
  82. }
  83.  
  84. /**
  85. * Creates an Patient and saves them to the iTrust system
  86. */
  87. @Given ( "^a valid Obstetrics patient exists in the iTrust system$" )
  88. public void HCPExists () {
  89. attemptLogout();
  90.  
  91. final User user = new User( patientString, "$2a$10$EblZqNptyYvcLm/VwDCVAuBjzZOI7khzdyGPBr08PpIi0na624b8.",
  92. Role.ROLE_PATIENT, 1 );
  93. user.save();
  94. // The User must also be a female in order to have a valid obstetrics
  95. // record
  96. final Patient patient = new Patient( user.getUsername() );
  97. patient.setSelf( user );
  98. patient.setGender( Gender.Female );
  99. patient.save();
  100.  
  101. }
  102.  
  103. /**
  104. * Deletes all current office visits and creates one of each type for the
  105. * patient
  106. */
  107. @Given ( "^the patient has office visits of types General Opthalmolgoy and Obstetrics visit$" )
  108. public void allOfficeVisitTypesExist () {
  109. DomainObject.deleteAll( GeneralOphthalmology.class );
  110. DomainObject.deleteAll( OphthalmologySurgery.class );
  111.  
  112. final GeneralOphthalmology genOph = getOphOfficeVisit();
  113. genOph.save();
  114.  
  115. final OphthalmologySurgery ophSurgery = getOphSurgery();
  116. if ( ophSurgery != null ) {
  117. ophSurgery.save();
  118. }
  119. }
  120.  
  121. /**
  122. * The given type of HCP logs in and navigates to the view patient office
  123. * visits page
  124. */
  125. @Then ( "^the patient logs in and goes to the past office visits page$" )
  126. public void hcpLoginNavToView () {
  127. attemptLogout();
  128.  
  129. driver.get( baseUrl );
  130. final WebElement username = driver.findElement( By.name( "username" ) );
  131. username.clear();
  132.  
  133. username.sendKeys( patientString );
  134.  
  135. final WebElement password = driver.findElement( By.name( "password" ) );
  136. password.clear();
  137. password.sendKeys( "123456" );
  138. final WebElement submit = driver.findElement( By.className( "btn" ) );
  139. submit.click();
  140.  
  141. assertEquals( "iTrust2: Patient Home", driver.getTitle() );
  142.  
  143. ( (JavascriptExecutor) driver ).executeScript( "document.getElementById('viewOfficeVisits').click();" );
  144.  
  145. assertEquals( "iTrust2: View Office Visits", driver.getTitle() );
  146. assertTextPresent( "Select an Office Visit to View" );
  147. }
  148.  
  149. /**
  150. * The HCP selects the given type of office visit from the list shown and
  151. * validates the information shown
  152. *
  153. * @param visitType
  154. * type of office visit
  155. */
  156. @When ( "^the patient selects the visit of type (.+) , and correct information is displayed$" )
  157. public void HPCSelectOfficeVisit ( final String visitType ) {
  158. waitForAngular();
  159. int value = 1;
  160. if ( visitType.equals( "General Ophthalmology" ) ) {
  161. value = 2;
  162. }
  163. else if ( visitType.equals( "Ophthalmology Surgery" ) ) {
  164. value = 3;
  165. }
  166.  
  167. final List<OfficeVisit> visits = OfficeVisit.getOfficeVisits();
  168. long targetId = 0;
  169.  
  170. for ( int i = 0; i < visits.size(); i++ ) {
  171. if ( visits.get( i ).getType().getCode() == value ) {
  172. targetId = visits.get( i ).getId();
  173. }
  174. }
  175.  
  176. final WebElement smokingElement = driver.findElement( By.cssSelector( "input[value=\"" + targetId + "\"]" ) );
  177. smokingElement.click();
  178.  
  179. waitForAngular();
  180.  
  181. switch ( value ) {
  182. case 1:
  183. validateGenCheckup();
  184. break;
  185. case 2:
  186. validateGenOph();
  187. break;
  188. case 3:
  189. validateOphSurgery();
  190. break;
  191. default:
  192. break;
  193. }
  194. }
  195.  
  196. /**
  197. * Generates a general checkup office visit with mock data
  198. */
  199. private GeneralCheckup getGenCheckup () {
  200. // Set First Diagnosis Code for APIEmergencyRecordFormTest
  201. ICDCodeForm codeForm = new ICDCodeForm();
  202. codeForm.setCode( "T49" );
  203. codeForm.setDescription( "Poisoned by topical agents. Probably in Blighttown" );
  204. final ICDCode poisoned = new ICDCode( codeForm );
  205. poisoned.save();
  206.  
  207. // Create Second Diagnosis Code for APIEmergencyRecordFormTest
  208. codeForm = new ICDCodeForm();
  209. codeForm.setCode( "S34" );
  210. codeForm.setDescription( "Injury of lumbar and sacral spinal cord. Probably carrying teammates." );
  211. final ICDCode backPain = new ICDCode( codeForm );
  212. backPain.save();
  213.  
  214. final GeneralCheckupForm form = new GeneralCheckupForm();
  215. form.setDate( "2036-02-14T15:50:00.000-05:00" ); // 2/14/2036 3:50 PM
  216. // EST
  217. form.setHcp( "hcp" );
  218. form.setPatient( patientString );
  219. form.setNotes( "Office Visit For SiegwardOf Catarina" );
  220. form.setType( AppointmentType.GENERAL_CHECKUP.toString() );
  221. form.setHospital( "General Hospital" );
  222. form.setHdl( 1 );
  223. form.setHeight( 1f );
  224. form.setWeight( 1f );
  225. form.setLdl( 1 );
  226. form.setTri( 100 );
  227. form.setDiastolic( 1 );
  228. form.setSystolic( 1 );
  229. form.setHouseSmokingStatus( HouseholdSmokingStatus.NONSMOKING );
  230. form.setPatientSmokingStatus( PatientSmokingStatus.NEVER );
  231. final List<Diagnosis> diagnoses = new ArrayList<Diagnosis>();
  232. final Diagnosis estusD = new Diagnosis();
  233. estusD.setCode( backPain );
  234. estusD.setNote( "Maybe try a bandaid" );
  235. diagnoses.add( estusD );
  236. final Diagnosis peach = new Diagnosis();
  237. peach.setCode( poisoned );
  238. peach.setNote( "This guy is poisoned! Give him a peach" );
  239. diagnoses.add( peach );
  240. form.setDiagnoses( diagnoses );
  241. try {
  242. return new GeneralCheckup( form );
  243. }
  244. catch ( final Exception e ) {
  245. // Do nothing
  246. return null;
  247. }
  248. }
  249.  
  250. /**
  251. * Generates a general ophthalmology office visit with mock data
  252. */
  253. private GeneralOphthalmology getOphOfficeVisit () {
  254. final Hospital hosp = new Hospital( "Dr. Jenkins' Insane Asylum", "123 Main St", "12345", "NC" );
  255. hosp.save();
  256.  
  257. final GeneralOphthalmology visit = new GeneralOphthalmology();
  258.  
  259. final BasicHealthMetrics bhm = new BasicHealthMetrics();
  260.  
  261. bhm.setDiastolic( 150 );
  262. bhm.setHcp( User.getByName( "bobbyOD" ) );
  263. bhm.setPatient( User.getByName( patientString ) );
  264. bhm.setHdl( 75 );
  265. bhm.setLdl( 75 );
  266. bhm.setHeight( 75f );
  267. bhm.setWeight( 130f );
  268. bhm.setTri( 300 );
  269. bhm.setSystolic( 150 );
  270. bhm.setHouseSmokingStatus( HouseholdSmokingStatus.NONSMOKING );
  271. bhm.setPatientSmokingStatus( PatientSmokingStatus.NEVER );
  272.  
  273. bhm.save();
  274. visit.setBasicHealthMetrics( bhm );
  275. visit.setType( AppointmentType.GENERAL_OPHTHALMOLOGY );
  276. visit.setHospital( hosp );
  277. visit.setPatient( User.getByName( patientString ) );
  278. visit.setHcp( User.getByName( "bobbyOD" ) );
  279. visit.setDate( ZonedDateTime.now() );
  280. visit.save();
  281.  
  282. visit.setVisualAcuityOD( 20 );
  283. visit.setVisualAcuityOS( 40 );
  284. visit.setSphereOD( 1.5 );
  285. visit.setSphereOS( -1.5 );
  286. visit.setCylinderOD( 1.0 );
  287. visit.setCylinderOS( -1.0 );
  288. visit.setAxisOD( 45 );
  289. visit.setAxisOS( 90 );
  290. visit.save();
  291.  
  292. final List<String> diagnoses = new ArrayList<String>();
  293. diagnoses.add( "Cataracts" );
  294. diagnoses.add( "Glaucoma" );
  295. visit.setDiagnosis( diagnoses );
  296.  
  297. visit.save();
  298.  
  299. return visit;
  300. }
  301.  
  302. /**
  303. * Generates a ophthalmology surgery office visit with mock data
  304. */
  305. private OphthalmologySurgery getOphSurgery () {
  306. final Hospital hosp = new Hospital( "iTrust Test Hospital 2", "Rainbow Road", "32923", "NC" );
  307. hosp.save();
  308. final OphthalmologySurgeryForm visit = new OphthalmologySurgeryForm();
  309. visit.setPreScheduled( null );
  310. visit.setDate( "2048-04-16T09:50:00.000-04:00" ); // 4/16/2048 9:50 AM
  311. // EDT
  312. visit.setHcp( "hcp" );
  313. visit.setPatient( patientString );
  314. visit.setNotes( "Test office visit" );
  315. visit.setType( AppointmentType.OPHTHALMOLOGY_SURGERY.toString() );
  316. visit.setHospital( "iTrust Test Hospital 2" );
  317. visit.setDiastolic( 150 );
  318. visit.setHdl( 75 );
  319. visit.setLdl( 75 );
  320. visit.setHeight( 75f );
  321. visit.setWeight( 130f );
  322. visit.setTri( 300 );
  323. visit.setSystolic( 150 );
  324. visit.setHouseSmokingStatus( HouseholdSmokingStatus.NONSMOKING );
  325. visit.setPatientSmokingStatus( PatientSmokingStatus.NEVER );
  326.  
  327. visit.setVisualAcuityOD( 20 );
  328. visit.setVisualAcuityOS( 40 );
  329. visit.setSphereOD( 1.5 );
  330. visit.setSphereOS( -1.5 );
  331. visit.setCylinderOD( 1.0 );
  332. visit.setCylinderOS( -1.0 );
  333. visit.setAxisOD( 45 );
  334. visit.setAxisOS( 90 );
  335.  
  336. visit.setSurgeryType( EyeSurgeryType.CATARACT );
  337.  
  338. try {
  339. return new OphthalmologySurgery( visit );
  340. }
  341. catch ( final Exception e ) {
  342. // Do nothing
  343. return null;
  344. }
  345. }
  346.  
  347. /**
  348. * Validates the data shown is correct for the general checkup office visit
  349. */
  350. private void validateGenCheckup () {
  351. waitForAngular();
  352.  
  353. assertEquals( "General Hospital", driver.findElement( By.name( "hospitalName" ) ).getText() );
  354. assertEquals( "1", driver.findElement( By.name( "diastolic" ) ).getText() );
  355. assertEquals( patientString, driver.findElement( By.name( "patientName" ) ).getText() );
  356. assertEquals( "1", driver.findElement( By.name( "hdl" ) ).getText() );
  357. assertEquals( "1", driver.findElement( By.name( "ldl" ) ).getText() );
  358. assertEquals( "1", driver.findElement( By.name( "height" ) ).getText() );
  359. assertEquals( "1", driver.findElement( By.name( "weight" ) ).getText() );
  360. assertEquals( "100", driver.findElement( By.name( "tri" ) ).getText() );
  361. assertEquals( "1", driver.findElement( By.name( "systolic" ) ).getText() );
  362. assertEquals( "NONSMOKING", driver.findElement( By.name( "houseSmokingStatus" ) ).getText() );
  363. assertEquals( "NEVER", driver.findElement( By.name( "patientSmokingStatus" ) ).getText() );
  364. assertEquals( "General Checkup", driver.findElement( By.name( "visitType" ) ).getText() );
  365. assertEquals( "Date: 02/14/2036", driver.findElement( By.name( "date" ) ).getText() );
  366. assertEquals( "Time: 3:50 PM", driver.findElement( By.name( "time" ) ).getText() );
  367. assertEquals( "Office Visit For SiegwardOf Catarina", driver.findElement( By.name( "notes" ) ).getText() );
  368. assertEquals( "Injury of lumbar and sacral spinal cord. Probably carrying teammates.",
  369. driver.findElement( By.name( "diagnoseDesc" ) ).getText() );
  370. assertEquals( "Maybe try a bandaid", driver.findElement( By.name( "diagnoseNote" ) ).getText() );
  371. }
  372.  
  373. /**
  374. * Validates the data shown is correct for the general ophthalmology office
  375. * visit
  376. */
  377. private void validateGenOph () {
  378. assertEquals( "Dr. Jenkins' Insane Asylum", driver.findElement( By.name( "hospitalName" ) ).getText() );
  379. assertEquals( "150", driver.findElement( By.name( "diastolic" ) ).getText() );
  380. assertEquals( patientString, driver.findElement( By.name( "patientName" ) ).getText() );
  381. assertEquals( "75", driver.findElement( By.name( "hdl" ) ).getText() );
  382. assertEquals( "75", driver.findElement( By.name( "ldl" ) ).getText() );
  383. assertEquals( "75", driver.findElement( By.name( "height" ) ).getText() );
  384. assertEquals( "130", driver.findElement( By.name( "weight" ) ).getText() );
  385. assertEquals( "300", driver.findElement( By.name( "tri" ) ).getText() );
  386. assertEquals( "150", driver.findElement( By.name( "systolic" ) ).getText() );
  387. assertEquals( "NONSMOKING", driver.findElement( By.name( "houseSmokingStatus" ) ).getText() );
  388. assertEquals( "NEVER", driver.findElement( By.name( "patientSmokingStatus" ) ).getText() );
  389. assertEquals( "General Ophthalmology", driver.findElement( By.name( "visitType" ) ).getText() );
  390. assertEquals( "20", driver.findElement( By.name( "acuityOD" ) ).getText() );
  391. assertEquals( "40", driver.findElement( By.name( "acuityOS" ) ).getText() );
  392. assertEquals( "1.5", driver.findElement( By.name( "sphereOD" ) ).getText() );
  393. assertEquals( "-1.5", driver.findElement( By.name( "sphereOS" ) ).getText() );
  394. assertEquals( "1", driver.findElement( By.name( "cylinderOD" ) ).getText() );
  395. assertEquals( "-1", driver.findElement( By.name( "cylinderOS" ) ).getText() );
  396. assertEquals( "45", driver.findElement( By.name( "axisOD" ) ).getText() );
  397. assertEquals( "90", driver.findElement( By.name( "axisOS" ) ).getText() );
  398. }
  399.  
  400. /**
  401. * Validates the data shown is correct for the ophthalmology surgery office
  402. * visit
  403. */
  404. private void validateOphSurgery () {
  405. assertEquals( "iTrust Test Hospital 2", driver.findElement( By.name( "hospitalName" ) ).getText() );
  406. assertEquals( "150", driver.findElement( By.name( "diastolic" ) ).getText() );
  407. assertEquals( patientString, driver.findElement( By.name( "patientName" ) ).getText() );
  408. assertEquals( "75", driver.findElement( By.name( "hdl" ) ).getText() );
  409. assertEquals( "75", driver.findElement( By.name( "ldl" ) ).getText() );
  410. assertEquals( "75", driver.findElement( By.name( "height" ) ).getText() );
  411. assertEquals( "130", driver.findElement( By.name( "weight" ) ).getText() );
  412. assertEquals( "300", driver.findElement( By.name( "tri" ) ).getText() );
  413. assertEquals( "150", driver.findElement( By.name( "systolic" ) ).getText() );
  414. assertEquals( "NONSMOKING", driver.findElement( By.name( "houseSmokingStatus" ) ).getText() );
  415. assertEquals( "NEVER", driver.findElement( By.name( "patientSmokingStatus" ) ).getText() );
  416. assertEquals( "Ophthalmology Surgery", driver.findElement( By.name( "visitType" ) ).getText() );
  417. assertEquals( "20", driver.findElement( By.name( "acuityOD" ) ).getText() );
  418. assertEquals( "40", driver.findElement( By.name( "acuityOS" ) ).getText() );
  419. assertEquals( "1.5", driver.findElement( By.name( "sphereOD" ) ).getText() );
  420. assertEquals( "-1.5", driver.findElement( By.name( "sphereOS" ) ).getText() );
  421. assertEquals( "1", driver.findElement( By.name( "cylinderOD" ) ).getText() );
  422. assertEquals( "-1", driver.findElement( By.name( "cylinderOS" ) ).getText() );
  423. assertEquals( "45", driver.findElement( By.name( "axisOD" ) ).getText() );
  424. assertEquals( "90", driver.findElement( By.name( "axisOS" ) ).getText() );
  425. assertEquals( "Date: 04/16/2048", driver.findElement( By.name( "date" ) ).getText() );
  426.  
  427. final String time = driver.findElement( By.name( "time" ) ).getText();
  428. assertTrue( time.equals( "Time: 10:50 AM" ) || time.equals( "Time: 9:50 AM" ) );
  429.  
  430. assertEquals( "Test office visit", driver.findElement( By.name( "notes" ) ).getText() );
  431. assertEquals( "CATARACT", driver.findElement( By.name( "surgeryType" ) ).getText() );
  432. }
  433.  
  434. }
Add Comment
Please, Sign In to add comment