Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having difficulty designing tests for some code. The requirements for the tests are mainly that the system allows the user to add a medical

I'm having difficulty designing tests for some code. The requirements for the tests are mainly that the system allows the user to add a medical record to a patient. However, I need to test that I can add a patient and add a medical record with treatments, medications, and allergies. In addition, it is required that, when a medical record is created, the code creates a patient history, which will contain 1 to many treatments, 1 to many medications, and 1 to many allergies. Also, medications cannot be assigned to a patient history unless there has been a treatment first. Some of these features are covered in the model tests, but I wouldn't mind including more testing. The code is provided below.

package medical.com.medicalApplication.services;

import java.util.ArrayList; import java.util.Collections; import java.util.List;

import medical.com.medicalApplication.model.MedicalRecord; import medical.com.medicalApplication.model.Patient; /** * * This class uses a singleton pattern to mock a service instead of using dependency injection * * In addition, it stores data in memory only using Lists * */ public class MedicalRecordService { private static MedicalRecordService reference = new MedicalRecordService(); private List patients; private List medicalRecords;

public static MedicalRecordService getReference() { return reference; } MedicalRecordService() { this.patients = new ArrayList(); this.medicalRecords = new ArrayList(); }

public boolean addPatient(String name, String id) { boolean patientAdded = !patients.stream() .anyMatch(patient -> patient.getId().equals(id)); if (patientAdded) { Patient newPatient = new Patient(name, id); patients.add(newPatient); medicalRecords.add(new MedicalRecord(newPatient, null)); } return patientAdded; } public MedicalRecord getMedicalRecord(String patientId) { return medicalRecords.stream() .filter(medicalRecord -> medicalRecord.getPatient().getId().equals(patientId)).findFirst().get(); }

public Patient getPatient(String patientId) { return patients.stream().filter(person -> person.getId().equals(patientId)) .findFirst().get(); }

public List getAllPatients() { return patients; } public List getPatientsWithAllergies(String allergyName){ for(Patient patient : getAllPatients()){ if(getMedicalRecord(patient.getId()).getHistory().getAllergies().stream().filter(allergy -> allergy.getName().equals(allergyName)).findFirst().get() != null){ return Collections.singletonList(patient); } } return Collections.emptyList(); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions