Crud
Crud
1. CREATE:
The requirement that needed to be implemented as Create operation from CRUD using both
MVC (Model View Controller) and REST (Representational State Transfer) is:
Identifier HMS 001_01
Title Register New Patients.
Implementation By MVC:
Model:
Controller:
import java.util.ArrayList;
import java.util.List;
public PatientController() {
patients.add(newPatient);
return newPatient;
}
View
this.name = name;
this.age = age;
this.gender = gender;
return name;
return age;
this.name = name;
this.age = age;
}
REST Controller:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Autowired
@PostMapping("/patients")
return savedPatient;
}
2. Read
The requirement that needed to be implemented as READ operation from CRUD using both
MVC (Model View Controller) and REST (Representational State Transfer) is:
Identifier HMS 001_25
Title Generate Patient Visit Summaries.
Implementation By MVC:
Model:
private PatientVisitServicethis.patientName
visitService; = patientName;
this.visitDate = visitDate;{
public List<PatientVisit> generateVisitSummaries()
this.diagnosis
List<PatientVisit> visitData = diagnosis;
= visitService.getPatientVisitData();
}
List<PatientVisit> summaries = new ArrayList<>();
public String getVisitDate() {
for (PatientVisit visit : visitData) {
return visitDate;
String patientName = visit.getPatientName();
}
String visitDate = visit.getVisitDate();
public void setVisitDate(String visitDate) {
String diagnosis = visit.getDiagnosis();
this.visitDate = visitDate;
String summary = "Patient: " + patientName + ", Visit Date: " + visitDate + ", Diagnosis: " + diagnosis;
}
PatientVisit summaryVisit = new PatientVisit(patientName, visitDate, diagnosis);
}
summaries.add(summaryVisit);
return summaries;
}
View:
import java.util.List;
System.out.println("---------------------------------");
}
Implementation By REST:
REST Controller
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@Autowired
@GetMapping("/visit-summaries")
return visitService.generateVisitSummaries();
}
Service:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
@Autowired
String summary = "Patient: " + patientName + ", Visit Date: " + visitDate + ", Diagnosis: " + diagnosis;
summaries.add(summaryVisit);
return summaries;
}
3. Update
The requirement that needed to be implemented as Update operation from CRUD using both
MVC (Model View Controller) and REST (Representational State Transfer) is:
Identifier HMS 002_02
Title Edit Registered Doctor’s Details.
Implementation By MVC:
Model
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/doctors")
@Autowired
@PutMapping("/{id}")
}
Service
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Service
public DoctorService() {
doctors.put(doctor1.getId(), doctor1);
if (doctors.containsKey(id)) {
doctor.setName(updatedDoctor.getName());
doctor.setSpecialization(updatedDoctor.getSpecialization());
return doctor;
} else {
}
4. Delete
The requirement that needed to be implemented as Delete operation from CRUD using both
MVC (Model View Controller) and REST (Representational State Transfer) is:
Identifier HMS 002_03
Title Delete Registered Doctor from the System
Implementation By MVC:
Model
public class Doctor {
private String id;
private String name;
private String specialization;
controller.addDoctor(doctor1);
controller.addDoctor(doctor2);
controller.addDoctor(doctor3);
controller.deleteDoctor("2");
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/doctors")
@Autowired
@DeleteMapping("/{id}")
doctorService.deleteDoctor(id);
}
Service
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Service
public DoctorService() {
doctors.put(doctor1.getId(), doctor1);
if (doctors.containsKey(id)) {
doctors.remove(id);
} else {