io.toffees.mvc.model.BloodSample.java Source code

Java tutorial

Introduction

Here is the source code for io.toffees.mvc.model.BloodSample.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package io.toffees.mvc.model;

import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.persistence.Entity;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import org.springframework.stereotype.Repository;

/**
 * Blood Sample resource for XML/JSON representation and also
 * Entity bean with JPA annotations
 * Hibernate provides JPA implementation
 * @author ptsilopoulos
 */
@Entity
@Repository
@SuppressWarnings("restriction")
@XmlRootElement(name = "blood_sample")
@XmlAccessorType(XmlAccessType.FIELD)
@Table(name = "BLOOD_SAMPLE")
public class BloodSample implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final String unitsReferenceMethod = "mg/dL";

    @Id
    @XmlElement(name = "id")
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    @NotNull
    @Temporal(javax.persistence.TemporalType.DATE)
    //TO-DO need to figure out line 49
    //@XmlJavaTypeAdapter(LocalDateTime.class) 
    //@BloodSampleDetailedView
    @Column(name = "SAMPLE_DATE_TIME")
    private LocalDateTime sampleDateTime;

    @NotNull
    @XmlElement(name = "sample_value")
    @Column(name = "SAMPLE_VALUE")
    private int sampleValue;

    @NotNull
    @XmlElement(name = "tag")
    @Column(name = "TAG")
    private String tag;

    public BloodSample(int sampleValue, String tag, LocalDateTime sampleDateTime) {
        this.sampleValue = sampleValue;
        this.tag = tag;
        this.sampleDateTime = sampleDateTime;
    }

    public BloodSample() {
    }

    public static String getUnitsReferenceMethod() {
        return unitsReferenceMethod;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setSampleTimeDate(LocalDateTime sampleDateTime) {
        this.sampleDateTime = LocalDateTime.now();
    }

    public LocalDateTime getSampleTimeDate() {
        return sampleDateTime;
    }

    public void setSampleValue(Integer sampleValue) {
        this.sampleValue = sampleValue;
    }

    public int getSampleValue() {
        return sampleValue;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public String getTag() {
        return tag;
    }

}