Skip to content

Commit

Permalink
Added BloodBankData by Shedulding and removed some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sayeedajmal committed Feb 18, 2024
1 parent 54acbba commit b369581
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 118 deletions.
15 changes: 10 additions & 5 deletions Senario.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ email: Email address of the donor.
address: Address of the donor.
lastDonationDate: Date of the donor's last blood donation.

Donation Entity:
# Donation Entity:

Purpose: Represents information about blood donations.
Attributes:
donationId: Unique identifier for each donation.
Expand All @@ -22,7 +23,8 @@ donationStatus: Status of the donation (using a DonationStatus enum).
bloodType: Blood type of the donated blood (using a BloodType enum).
quantity: Quantity of blood donated.

BloodBank Entity:
# BloodBank Entity:

Purpose: Represents information about blood banks.
Attributes:
bloodBankId: Unique identifier for each blood bank.
Expand All @@ -32,7 +34,8 @@ contactNumber: Contact number of the blood bank.
email: Email address of the blood bank.
availableBloodGroups: Set of available blood groups (using a BloodType enum).

Staff Entity:
# Staff Entity:

Purpose: Represents information about staff members involved in the blood donation system.
Attributes:
staffId: Unique identifier for each staff member.
Expand All @@ -42,7 +45,8 @@ contactNumber: Contact number of the staff member.
email: Email address of the staff member.
Additional security-related fields can be added based on your requirements.

Appointment Entity:
# Appointment Entity:

Purpose: Represents information about donor appointments.
Attributes:
appointmentId: Unique identifier for each appointment.
Expand All @@ -52,7 +56,8 @@ appointmentTime: Time of the appointment.
location: Location of the appointment.
status: Status of the appointment.

MedicalHistory Entity:
# MedicalHistory Entity

Purpose: Represents the medical history of blood donors.
Attributes:
historyId: Unique identifier for each medical history entry.
Expand Down
30 changes: 18 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@
- Addressed Challenges With Innovative Problem-Solving And Continuous Improvement.
- Excited To Contribute To The Healthcare Ecosystem With The Blood Donation API? Download This Project And Start Running Setup .

### Swagger API URL `http://localhost:8080/swagger-ui.html`
## Variables

bloodDonation.organisation.Id=${ORG_ID}
bloodDonation.organisation.name=${ORG_NAME}
bloodDonation.organisation.website=https://sayeedthedev.web.app
bloodDonation.organisation.PhoneNumber=${NUMBER}
bloodDonation.organisation.Location=${LOCATION}
bloodDonation.organisation.OrganisationEmail=${EMAIL}
bloodDonation.organisation.OrganisationEmailPassword=${PASSWORD}

# DataSource Configuration
spring.datasource.url=jdbc:mysql://${PROD_DB_HOST}:${PROD_DB_PORT}/${PROD_DB_NAME}
spring.datasource.username=${PROD_DB_USERNAME}
spring.datasource.password=${PROD_DB_PASSWORD}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

## Swagger API URL `http://localhost:8080/swagger-ui.html`

## POSITION OF STAFF

Expand Down Expand Up @@ -155,7 +171,7 @@

- **POST** `createDonation`

- @Require Donation, Integer donationId
- @Require Donation, Integer appointId
- @Return HttpStatus

- **GET** `showDonation`
Expand All @@ -167,11 +183,6 @@
- @Param `donationId`: Integer, the unique identifier of the donation
- @Return HttpStatus With Donation

- **DELETE** `/{donationId}`

- @Param `donationId`: Integer, the unique identifier of the donation
- @Return HttpStatus

- **PATCH** `updateDonation`
- @Require Donation, Integer donationId
- @Return HttpStatus
Expand All @@ -194,11 +205,6 @@
- @Param `bloodBankId`: Integer, the unique identifier of the BloodBank
- @Return HttpStatus With BloodBank

- **DELETE** `/{bloodBankId}`

- @Param `bloodBankId`: Integer, the unique identifier of the BloodBank
- @Return HttpStatus

- **PATCH** `updateBloodBank`
- @Require BloodBank, Integer bloodBankId
- @Return HttpStatus
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class BloodDonationApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -36,17 +33,11 @@ public class BloodBankController {
* @param bloodBankId The unique identifier of the bloodBank associated with the
* BloodBank.
* @return A response indicating the success or failure of the operation.
* @throws BloodException
*/
@PostMapping("createBank")
public ResponseEntity<String> createBank(@ModelAttribute BloodBank bloodBank,
@RequestParam Integer bloodBankId) throws BloodException {
BloodBank findById = bloodBankService.findById(bloodBankId);
if (findById != null) {
bloodBankService.saveBlood(bloodBank);
return new ResponseEntity<>("Created Successfully", HttpStatus.CREATED);
} else {
throw new BloodException("Can't Find BloodBank with ID: " + bloodBankId);
}
public ResponseEntity<String> createBank(BloodBank bloodBank) throws BloodException {
bloodBankService.saveBlood(bloodBank);
return new ResponseEntity<>("Created Successfully", HttpStatus.CREATED);
}

/**
Expand All @@ -73,20 +64,6 @@ public ResponseEntity<BloodBank> showByIdBloodBank(@PathVariable("bloodBankId")
return new ResponseEntity<>(BloodBank, HttpStatus.OK);
}

/**
* DELETE endpoint to delete an BloodBank by ID.
*
* @param bloodBankId The unique identifier of the BloodBank to be deleted.
* @return A response indicating the success or failure of the operation.
*/
@Transactional
@DeleteMapping("{bloodBankId}")
public ResponseEntity<?> deleteBloodBank(@PathVariable("bloodBankId") Integer bloodBankId)
throws BloodException {
bloodBankService.deleteBlood(bloodBankId);
return new ResponseEntity<>("Sucessfully Deleted",HttpStatus.NO_CONTENT);
}

/**
* PATCH endpoint to update an existing BloodBank.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.strong.BloodDonation.Controller;

import java.sql.Date;
import java.time.LocalDate;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
Expand All @@ -18,10 +18,13 @@
import org.springframework.web.bind.annotation.RestController;

import com.strong.BloodDonation.Email.MailService;
import com.strong.BloodDonation.Model.Appointment;
import com.strong.BloodDonation.Model.Donation;
import com.strong.BloodDonation.Model.Donor;
import com.strong.BloodDonation.Service.AppointmentService;
import com.strong.BloodDonation.Service.DonationService;
import com.strong.BloodDonation.Service.DonorService;
import com.strong.BloodDonation.Utils.AppointmentStatus;
import com.strong.BloodDonation.Utils.BloodException;

import jakarta.transaction.Transactional;
Expand All @@ -39,25 +42,40 @@ public class DonationController {
@Autowired
private DonorService donorService;

@Autowired
private AppointmentService appointmentService;

/**
*
* POST endpoint to create a new Donation.
*
* @param donation The Donation object to be created.
* @param donationId The unique identifier of the Donation associated with the
* Donation.
* @param donation The Donation object to be created.
* @param donorId The unique identifier of the Donor associated with the
* Donation.
* @return A response indicating the success or failure of the operation.
* @throws BloodException If there's an error processing the donation.
*/
@PostMapping("createDonation")
public ResponseEntity<String> createDonation(@ModelAttribute Donation donation,
@RequestParam Integer donorId) throws BloodException {
@RequestParam Integer appointId) throws BloodException {

Appointment appointment = appointmentService.findById(appointId);
Donor donor = donorService.findById(appointment.getDonor().getDonorId());

donation.setDonor(donor);

Donor byId = donorService.findById(donorId);
donation.setDonor(byId);
donation.setDonationDate(LocalDate.now());
donationService.saveDonation(donation);

donor.setLastDonationDate(Date.valueOf(LocalDate.now()));
donorService.updateDonor(donor);

appointment.setStatus(AppointmentStatus.CONFIRMED);
appointmentService.updateAppointment(appointment);

// Send donation confirmation email
mailService.sendDonationConfirmation(donation);
return new ResponseEntity<>("Created Successfully", HttpStatus.CREATED);

return new ResponseEntity<>("Donation created successfully", HttpStatus.CREATED);
}

/**
Expand All @@ -84,20 +102,6 @@ public ResponseEntity<Donation> showByIdDonation(@PathVariable("donationId") Int
return new ResponseEntity<>(Donation, HttpStatus.OK);
}

/**
* DELETE endpoint to delete an Donation by ID.
*
* @param donationId The unique identifier of the Donation to be deleted.
* @return A response indicating the success or failure of the operation.
*/
@Transactional
@DeleteMapping("{donationId}")
public ResponseEntity<?> deleteDonation(@PathVariable("donationId") Integer donationId)
throws BloodException {
donationService.deleteDonation(donationId);
return new ResponseEntity<>("Sucessfully Deleted", HttpStatus.NO_CONTENT);
}

/**
* PATCH endpoint to update an existing Donation.
*
Expand All @@ -112,7 +116,7 @@ public ResponseEntity<String> updateDonation(@RequestBody Donation updatedDonati
@RequestParam("donationId") Integer donationId) throws BloodException {
Donation existDonation = donationService.findById(donationId);
if (existDonation != null) {

existDonation.setDonationDate(updatedDonation.getDonationDate());
existDonation.setDonationStatus(updatedDonation.getDonationStatus());
existDonation.setQuantity(updatedDonation.getQuantity());
Expand Down
37 changes: 16 additions & 21 deletions src/main/java/com/strong/BloodDonation/Model/BloodBank.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.strong.BloodDonation.Model;

import java.util.List;
import java.time.LocalDate;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;

import com.strong.BloodDonation.Utils.BloodType;

Expand All @@ -9,11 +12,10 @@
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.MapKeyColumn;
import jakarta.persistence.MapKeyEnumerated;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
Expand All @@ -27,7 +29,7 @@
public class BloodBank {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Value("${bloodDonation.organisation.Id}")
private Integer bloodBankId;

@Column(nullable = false)
Expand All @@ -44,20 +46,13 @@ public class BloodBank {
@Email
private String email;

@ElementCollection(targetClass = BloodType.class)
@Enumerated(EnumType.STRING)
@CollectionTable(name = "blood_bank_available_groups", joinColumns = @JoinColumn(name = "bloodBankId"))
@Column(name = "available_blood_group")
private List<BloodType> availableBloodGroups;

/*
* - The availableBloodGroups field is a Set of BloodType enums.
* - The @ElementCollection annotation is used to indicate that
* availableBloodGroups is a collection of simple types (enums in this case).
* - The @Enumerated(EnumType.STRING) annotation specifies that the enums should
* be stored as strings in the database.
* - The @CollectionTable annotation is used to specify the name of the table that
* will store the blood groups, and the @Column annotation specifies the name of
* the column.
*/
@Column(nullable = false)
private LocalDate donationDate;

@ElementCollection
@CollectionTable(name = "blood_bank_available_blood", joinColumns = @JoinColumn(name = "bloodBankId"))
@MapKeyEnumerated(EnumType.STRING)
@MapKeyColumn(name = "blood_type")
@Column(name = "quantity")
private Map<BloodType, Double> availableBloodGroups;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.strong.BloodDonation.Repository;

import java.time.LocalDate;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.strong.BloodDonation.Model.Donation;

public interface DonationRepo extends JpaRepository<Donation, Integer> {

@Query("SELECT d FROM Donation d WHERE d.donationDate= :donationDate")
public List<Donation> findByDonationDate(@Param("donationDate") LocalDate donationDate);

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public List<Appointment> findAll() throws BloodException {
return findAll;
}

@SuppressWarnings("null")
public void deleteAppointment(Integer appointId) throws BloodException {
try {
appointRepo.delete(findById(appointId));
Expand Down
Loading

0 comments on commit b369581

Please sign in to comment.