co-pilot
Here are some effective ways to work with GitHub Copilot in JetBrains IDEs like IntelliJ IDEA:
1. Inline Chat (Ctrl + Shift + I)
- This allows you to interact with Copilot directly in the code editor.
- You can ask questions or request code suggestions related to your current context.
2. Inline Prompts
- You can type prompts directly in the code editor, starting with a comment (e.g., `//`).
- After typing your prompt, press Enter and then type the code to get suggestions based on your prompt.
3. Copilot Chat (Ctrl + Shift + C)
- This opens a dedicated chat window for Copilot.
- You can have a more extensive conversation with Copilot, asking for help or explanations about your code.
4. Inline Suggestions
- As you type, Copilot provides inline suggestions that you can accept or reject.
- This feature helps you write code faster by suggesting completions based on your current context.
5. Keyboard Shortcuts
- Use keyboard shortcuts to navigate through suggestions and accept them quickly.
- For example, you can use Tab to accept a suggestion or Esc to dismiss it.
3. Command Palette (Ctrl + Shift + P)
- This opens a command palette where you can search for Copilot commands and features.
- You can use it to quickly access various functionalities of Copilot without leaving your coding environment.
_____________________________________________________________________________________________
/help
/clear
@workspace - Ask about your workspace
/doc - creates documentation
/explain - Explain how the selected code works
/tests - Generate unit tests for the selected code
/fix - Propose a fix for the problems in the selected code
/new - Scaffold code for a new workspace
/newNotebook - Create a new Jupyter Notebook
/simplify
@vscode - Ask about VS Code
/api - Ask about VS Code extension development
/search - Generate query parameters for workspace search
@terminal - Ask how to do something in the terminal
_____________________________________________________________________________________________
Creating the code :
prompt1: function that calculates the factorial of given number
prompt2: html page that uses the factoral.js, prompts the user for a number, and displays the result.
html page that uses the factoral.js, renders the products in html table and allow users to add, remove, update product.
Review and Refactor :
Improvement prompts:
Prompt1 : Review and improve the code
Prompt2 : Review and suggest potential improvements
Fix prompts:
Prompt1 :While rendering the products in table, table headings are not being rendered.
Prompt2 :When click the add product button, product details are not being added to the table.
Checking Errors:
Add error handling
How can I handle exceptions in spring boot controllers
Logging:
How to configure and use logging
How to configure and use logging to log in file
Testing with errors:
Error checking: Test the function with negative number , it throws error. copy the error from console and check github co-pilot for a fix snippet:
Add reference:
copy the file directly in chat or click the + button in chat button to add the file reference.
Code Testing:
npm install --save-dev jest
npx jest taskmanager.test.js
/tests Generate the tests for the selected code.
Testing the code:
Generate Test cases:
Github co-pilot gives automatic suggestions for testing the code.
select the auto suggestion to get the test code.
or
Type How can I test the factorial function to ensure its working correctly.
open file and select all content with ctrl + a and type /tests in chat box.
__________________________________________________________________________________________________________________________________
Project: Java Spring boot and Mysql Project
I am a java developer. I want to create the application that captures the patient and his clinical data.
Suggest a good tech stack for rest apis and single page frontend.
Prompt#1 :
Create a database called clinicals and use it.
Create tables with normalized design to properly capture patient and his clinical data and join them.
Insert sample data for 5 patients with 2 sample data each.
-- Create the database
CREATE DATABASE clinic;
-- Use the database
USE clinic;
-- Create Patients table
CREATE TABLE patient (
id INT NOT NULL AUTO_INCREMENT,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
age INT,
PRIMARY KEY (id)
);
-- Create Clinical Data table (normalized, joined to patient)
CREATE TABLE clinical_data (
id INT NOT NULL AUTO_INCREMENT,
patient_id INT NOT NULL,
component_name VARCHAR(255) NOT NULL,
component_value VARCHAR(255) NOT NULL,
measured_date_time TIMESTAMP,
PRIMARY KEY (id),
FOREIGN KEY (patient_id) REFERENCES patient(id)
);
-- Insert sample patients
INSERT INTO patient (first_name, last_name, age) VALUES
('John', 'Doe', 52),
('Jane', 'Smith', 32),
('Alice', 'Johnson', 22),
('Bob', 'Williams', 33),
('Emily', 'Brown', 55);
-- Insert sample clinical data (2 records per patient)
INSERT INTO clinical_data (patient_id, component_name, component_value, measured_date_time) VALUES
(1, 'bp', '120/80', '2025-08-01 10:00:00'),
(1, 'heartrate', '72', '2025-08-01 10:05:00'),
(2, 'bp', '130/85', '2025-08-02 11:00:00'),
(2, 'heartrate', '75', '2025-08-02 11:05:00'),
(3, 'bp', '110/70', '2025-08-03 12:00:00'),
(3, 'heartrate', '68', '2025-08-03 12:05:00'),
(4, 'bp', '125/82', '2025-08-04 13:00:00'),
(4, 'heartrate', '80', '2025-08-04 13:05:00'),
(5, 'bp', '118/78', '2025-08-05 14:00:00'),
(5, 'heartrate', '70', '2025-08-05 14:05:00');
insert into patient values(1,'John','Mccain',52);
insert into patient values(2,'Siva','Shankar',32);
insert into patient values(3,'Anthony','Simon',22);
insert into patient values(4,'Bruce','Sanhurst',33);
insert into patient values(5,'Abhram','Mani',55);
insert into patient values(6,'Gandhi','Singh',12);
insert into patient values(7,'Antti','Krovinan',27);
insert into patient values(8,'Simba','White',24);
insert into patient values(9,'Rose','Tanic',29);
insert into patient values(10,'Rowling','Lte',49);
insert into clinical_data values('1', '1', 'bp', '67/119', '2018-07-09 19:34:24');
insert into clinical_data values('2', '2', 'bp', '63/115', '2018-06-19 19:34:24');
insert into clinical_data values('3', '3', 'bp', '72/129', '2018-07-26 19:34:24');
insert into clinical_data values('4', '4', 'bp', '74/139', '2018-08-03 19:34:24');
insert into clinical_data values('5', '5', 'bp', '67/119', '2018-08-29 19:34:24');
insert into clinical_data values('6', '6', 'bp', '62/109', '2018-07-12 19:34:24');
insert into clinical_data values('7', '7', 'bp', '55/102', '2018-06-13 19:34:24');
insert into clinical_data values('8', '8', 'bp', '47/90', '2018-08-02 19:34:24');
insert into clinical_data values('9', '9', 'bp', '90/149', '2018-06-01 19:34:24');
insert into clinical_data values('10', '10', 'bp', '50/109', '2018-07-09 19:34:24');
insert into clinical_data values('11', '1', 'bp', '55/102', '2018-11-02 19:34:24');
insert into clinical_data values('12', '2', 'bp', '67/119', '2018-08-09 19:34:24');
insert into clinical_data values('13', '3', 'bp', '63/115', '2018-09-09 19:34:24');
insert into clinical_data values('14', '4', 'bp', '55/102', '2018-09-13 19:34:24');
insert into clinical_data values('15', '5', 'bp', '50/109', '2018-10-12 19:34:24');
insert into clinical_data values('16', '6', 'bp', '67/119', '2018-11-29 19:34:24');
insert into clinical_data values('17', '7', 'bp', '63/115', '2018-11-03 19:34:24');
insert into clinical_data values('18', '8', 'bp', '63/115', '2018-10-26 19:34:24');
insert into clinical_data values('19', '9', 'bp', '55/102', '2018-09-11 19:34:24');
insert into clinical_data values('20', '10', 'bp', '72/129', '2018-09-29 19:34:24');
insert into clinical_data values('21', '1', 'bp', '55/102', '2018-10-09 19:34:24');
insert into clinical_data values('22', '2', 'bp', '63/115', '2018-10-20 19:34:24');
insert into clinical_data values('23', '3', 'bp', '55/102', '2018-11-19 19:34:24');
insert into clinical_data values('24', '5', 'bp', '72/129', '2018-12-30 19:34:24');
insert into clinical_data values('25', '6', 'bp', '63/115', '2018-10-21 19:34:24');
insert into clinical_data values('26', '7', 'bp', '47/90', '2018-12-29 19:34:24');
insert into clinical_data values('27', '8', 'bp', '63/115', '2018-11-08 19:34:24');
insert into clinical_data values('28', '9', 'bp', '90/149', '2018-10-03 19:34:24');
insert into clinical_data values('29', '10', 'bp', '55/102', '2018-10-29 19:34:24');
insert into clinical_data values('30', '1', 'bp', '90/149', '2018-03-19 19:34:24');
insert into clinical_data values('31', '2', 'bp', '55/102', '2018-04-03 19:34:24');
insert into clinical_data values('32', '3', 'bp', '63/115', '2018-05-21 19:34:24');
insert into clinical_data values('33', '4', 'bp', '47/90', '2018-03-31 19:34:24');
insert into clinical_data values('34', '5', 'bp', '55/102', '2018-04-19 19:34:24');
insert into clinical_data values('35', '6', 'bp', '72/129', '2018-04-28 19:34:24');
insert into clinical_data values('36', '7', 'bp', '67/119', '2018-03-19 19:34:24');
insert into clinical_data values('37', '8', 'bp', '50/109', '2018-05-21 19:34:24');
insert into clinical_data values('38', '9', 'bp', '67/119', '2018-04-12 19:34:24');
insert into clinical_data values('39', '10', 'bp', '67/119', '2018-03-19 19:34:24');
insert into clinical_data values('40', '1', 'bp', '67/119', '2019-06-09 19:34:24');
insert into clinical_data values('41', '2', 'bp', '55/102', '2019-05-23 19:34:24');
insert into clinical_data values('42', '3', 'bp', '67/119', '2019-06-01 19:34:24');
insert into clinical_data values('43', '4', 'bp', '90/149', '2019-03-01 19:34:24');
insert into clinical_data values('44', '5', 'bp', '55/102', '2019-01-06 19:34:24');
insert into clinical_data values('45', '6', 'bp', '67/119', '2019-03-29 19:34:24');
insert into clinical_data values('46', '7', 'bp', '55/102', '2019-02-21 19:34:24');
insert into clinical_data values('47', '8', 'bp', '50/109', '2019-02-15 19:34:24');
insert into clinical_data values('48', '9', 'bp', '67/119', '2019-04-19 19:34:24');
insert into clinical_data values('49', '10', 'bp', '37/89', '2019-05-29 19:34:24');
insert into clinical_data values('51', '1', 'heartrate', '67', '2018-07-09 19:34:24');
insert into clinical_data values('52', '2', 'heartrate', '115', '2018-06-19 19:34:24');
insert into clinical_data values('53', '3', 'heartrate', '72', '2018-07-26 19:34:24');
insert into clinical_data values('54', '4', 'heartrate', '74', '2018-08-03 19:34:24');
insert into clinical_data values('55', '5', 'heartrate', '119', '2018-08-29 19:34:24');
insert into clinical_data values('56', '6', 'heartrate', '62', '2018-07-12 19:34:24');
insert into clinical_data values('57', '7', 'heartrate', '102', '2018-06-13 19:34:24');
insert into clinical_data values('58', '8', 'heartrate', '90', '2018-08-02 19:34:24');
insert into clinical_data values('59', '9', 'heartrate', '90', '2018-06-01 19:34:24');
insert into clinical_data values('50', '10', 'heartrate', '109', '2018-07-09 19:34:24');
insert into clinical_data values('61', '1', 'heartrate', '55', '2018-11-02 19:34:24');
insert into clinical_data values('62', '2', 'heartrate', '67', '2018-08-09 19:34:24');
insert into clinical_data values('63', '3', 'heartrate', '63', '2018-09-09 19:34:24');
insert into clinical_data values('64', '4', 'heartrate', '55', '2018-09-13 19:34:24');
insert into clinical_data values('65', '5', 'heartrate', '50', '2018-10-12 19:34:24');
insert into clinical_data values('66', '6', 'heartrate', '119', '2018-11-29 19:34:24');
insert into clinical_data values('67', '7', 'heartrate', '115', '2018-11-03 19:34:24');
insert into clinical_data values('68', '8', 'heartrate', '63', '2018-10-26 19:34:24');
insert into clinical_data values('69', '9', 'heartrate', '55', '2018-09-11 19:34:24');
insert into clinical_data values('60', '10', 'heartrate', '72', '2018-09-29 19:34:24');
insert into clinical_data values('71', '1', 'heartrate', '55', '2018-10-09 19:34:24');
insert into clinical_data values('72', '2', 'heartrate', '115', '2018-10-20 19:34:24');
insert into clinical_data values('73', '3', 'heartrate', '55', '2018-11-19 19:34:24');
insert into clinical_data values('74', '5', 'heartrate', '129', '2018-12-30 19:34:24');
insert into clinical_data values('75', '6', 'heartrate', '63', '2018-10-21 19:34:24');
insert into clinical_data values('76', '7', 'heartrate', '90', '2018-12-29 19:34:24');
insert into clinical_data values('77', '8', 'heartrate', '63', '2018-11-08 19:34:24');
insert into clinical_data values('78', '9', 'heartrate', '149', '2018-10-03 19:34:24');
insert into clinical_data values('79', '10', 'heartrate', '55', '2018-10-29 19:34:24');
insert into clinical_data values('70', '1', 'heartrate', '149', '2018-03-19 19:34:24');
insert into clinical_data values('81', '2', 'heartrate', '55', '2018-04-03 19:34:24');
insert into clinical_data values('82', '3', 'heartrate', '115', '2018-05-21 19:34:24');
insert into clinical_data values('83', '4', 'heartrate', '47', '2018-03-31 19:34:24');
insert into clinical_data values('84', '5', 'heartrate', '102', '2018-04-19 19:34:24');
insert into clinical_data values('85', '6', 'heartrate', '72', '2018-04-28 19:34:24');
insert into clinical_data values('86', '7', 'heartrate', '67', '2018-03-19 19:34:24');
insert into clinical_data values('87', '8', 'heartrate', '109', '2018-05-21 19:34:24');
insert into clinical_data values('88', '9', 'heartrate', '67', '2018-04-12 19:34:24');
insert into clinical_data values('89', '10', 'heartrate', '119', '2018-03-19 19:34:24');
insert into clinical_data values('80', '1', 'heartrate', '119', '2019-06-09 19:34:24');
insert into clinical_data values('91', '2', 'heartrate', '55/102', '2019-05-23 19:34:24');
insert into clinical_data values('92', '3', 'heartrate', '67', '2019-06-01 19:34:24');
insert into clinical_data values('93', '4', 'heartrate', '149', '2019-03-01 19:34:24');
insert into clinical_data values('94', '5', 'heartrate', '102', '2019-01-06 19:34:24');
insert into clinical_data values('95', '6', 'heartrate', '67/119', '2019-03-29 19:34:24');
insert into clinical_data values('96', '7', 'heartrate', '55', '2019-02-21 19:34:24');
insert into clinical_data values('97', '8', 'heartrate', '50', '2019-02-15 19:34:24');
insert into clinical_data values('98', '9', 'heartrate', '67', '2019-04-19 19:34:24');
insert into clinical_data values('99', '10', 'heartrate', '89', '2019-05-29 19:34:24');
select first_name, last_name, age, component_name, component_value, measured_date_time from patient p , clinical_data d where p.id = d.patient_id;
drop table patient;
drop table clinical_data;
drop database clinic;
__________________________________________________________________________________________________________________________________
prompt#2: Open the command pallete
@vscode create java project
VCC > Java project > Spring boot > maven project >
spring web
spring jpa
mysql driver
package name : com.example.clinic
clinic_demo
create a folders
model
__________________________________________________________________________________________________________________________________
JPA can be defined as Java Persistence API
Creating the JPA Models :
Prompt#3:
Create a JPA model class for the below table
TABLE patient (
id INT NOT NULL AUTO_INCREMENT,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
age INT,
PRIMARY KEY (id)
);
Check for the below:
import jakarta.persistence.*;
@Entity
@Table(name = "patient")
public class Patient {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Prompt#4:
Create a JPA model class for the below table
TABLE clinical_data (
id INT NOT NULL AUTO_INCREMENT,
patient_id INT NOT NULL,
component_name VARCHAR(255) NOT NULL,
component_value VARCHAR(255) NOT NULL,
measured_date_time TIMESTAMP,
PRIMARY KEY (id),
FOREIGN KEY (patient_id) REFERENCES patient(id)
);
Check for the below:
import jakarta.persistence.*;
@Entity
@Table(name = "clinical_data")
public class ClinicalData {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name = "patient_id", nullable = false)
change the package to import java.sql.Timestamp;
Check the ManyToOne and OneToMany dependancies in JPA.
_____________________________________________________________________________________________
Create the JPA Model Repositories:
Create the JPA Model Repository for the JPA Model Patient.java in repos folder
Create the JPA Model Repository for the JPA Model ClinicalData.java in repos folder
_____________________________________________________________________________________________
Rest Controllers
Prompt:
Create a Rest controller that uses PatienetRepository.java and exposes a rest api to perform CRUD operations
Checks:
import section
model class
repo class
Annotations:
@RestController
@RequestMapping("/api/patients")
@CrossOrigin(origins = "*")
CRUD operations
Prompt:
Create a Rest controller that uses ClinicalDataRepository.java and exposes a rest api to perform CRUD operations
import section
model class
repo class
Annotations:
@RestController
@RequestMapping("/api/patients")
@CrossOrigin(origins = "*")
CRUD operations
_____________________________________________________________________________________________
Configure Data Source and properties
spring.application.name=clinicals_demo
spring.datasource.url=jdbc:mysql://localhost:3306/clinicals_demo
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.servlet.context-path=/clinicalservices/
_____________________________________________________________________________________________
Run the stand alone application
Run the
ClinicalsDemoApplication.java
Test
localhost:8080/clinicalservices/patients
_____________________________________________________________________________________________
Create a React project
1. npx create-react-app@latest clinicals-app
2. npm install react-router-dom
3. npm install axios
4. npm install react-toastify
cd clinicals-app
npm start
Open the clinicals-app in Code editor
create a component folder
Create a place holder files
Home.js
Patient.js
Clinical.js
export default function Home (){
return (
<b> Home </b>
);
}
App.js
1. Create a Header with light background and minimum height 10vh
2. Create a <NAV> and nav list with background , flex type , list style none , horizontal menu type, left sided
3. Add Routing details
<BrowseRouter>
<Routes>
<Route>
<Route>
<Route>
</Routes>
</BrowseRouter>
4. Create a Footer
5. Add ToastContainer
_________________________________________________________________________________________________________________________________
Impement Home.js
Prompt : react component that makes a api call using axios to fetch the patient details and then renders them as html table.
check the Name Home
Check the constants patients and set patients
fetch() - set the path axios.get ('http://localhost:8080/patientservices/patients')
useeffect as soon as mounted ( [] )
rendering - return statement
CORS issue - (No access is allowed for cross origint request )
__________________________________________________________________________________________________________________________________
CORS Error fix in Spring boot
Add the annotation
@CrossOrigin(origins="*")
__________________________________________________________________________________________________________________________________
Add Patient.js
prompt : Create a React component that gathers patinet information like first name, last name , age and makes axios api call to save the patient object.
check the name
check the constatnts for each field
check the functions to set the values
check the handle submit function
check the axios api call
__________________________________________________________________________________________________________________________________
React Toastify
<ToastContainer autoClose={2000}/>
import { toast} from 'react-toastify'
__________________________________________________________________________________________________________________________________
Add Clinical Data - Part 1
Prompt: Retrieve the patient details for a given Patient Id and render the details in table.
Check the name
Check the constatnts - parent
Check the param -
Add Clinical Data - Part 2
Prompt: Gather the component name , value using html forms and make an api call using axios to save the data.
submit function - axios fetch
__________________________________________________________________________________________________________________________________
Add Back links
__________________________________________________________________________________________________________________________________
Styling
_____________________________________________________________________________________________
Create a React project
1. npx create-react-app@latest clinicals-app
2. npm install react-router-dom
3. npm install axios
4. npm install react-toastify
cd clinicals-app
npm start
Open the clinicals-app in Code editor
create a component folder
Create a place holder files
Home.js
Patient.js
Clinical.js
export default function Home (){
return (
<b> Home </b>
);
}
App.js
1. Create a Header with light background and minimum height 10vh
2. Create a <NAV> and nav list with background , flex type , list style none , horizontal menu type, left sided
3. Add Routing details
<BrowseRouter>
<Routes>
<Route>
<Route>
<Route>
</Routes>
</BrowseRouter>
4. Create a Footer
5. Add ToastContainer
_________________________________________________________________________________________________________________________________
Impement Home.js
Prompt : react component that makes a api call using axios to fetch the patient details and then renders them as html table.
check the Name Home
Check the constants patients and set patients
fetch() - set the path axios.get ('http://localhost:8080/patientservices/patients')
useeffect as soon as mounted ( [] )
rendering - return statement
CORS issue - (No access is allowed for cross origint request )
__________________________________________________________________________________________________________________________________
CORS Error fix in Spring boot
Add the annotation
@CrossOrigin(origins="*")
__________________________________________________________________________________________________________________________________
Add Patient.js
prompt : Create a React component that gathers patinet information like first name, last name , age and makes axios api call to save the patient object.
check the name
check the constatnts for each field
check the functions to set the values
check the handle submit function
check the axios api call
__________________________________________________________________________________________________________________________________
React Toastify
<ToastContainer autoClose={2000}/>
import { toast} from 'react-toastify'
__________________________________________________________________________________________________________________________________
Add Clinical Data - Part 1
Prompt: Retrieve the patient details for a given Patient Id and render the details in table.
Check the name
Check the constatnts - parent
Check the param -
Add Clinical Data - Part 2
Prompt: Gather the component name , value using html forms and make an api call using axios to save the data.
submit function - axios fetch
__________________________________________________________________________________________________________________________________
Add Back links
__________________________________________________________________________________________________________________________________
Styling
_____________________________________________________________________________________________
__________________________________________________________________________________________________________________________________
Comments
Post a Comment