PAM Lab6
PAM Lab6
RAPORT
Lucrarea de laborator nr. 6
Programarea aplicatiilor mobile
Tema: Telemedicine - SPRINT2
A verificat:
asist. univ. C. Rusu
Chisinau 2020
Scopul lucrarii
Pentru designul ofert in laboratorul nr. 5 să se implementeze partea funcțională a proiectului conform
serviciului API descris mai jos.
Metodele oferite de Servicu:
• Auth (autentificare)
• Reg (inregistrare)
• UserProfie (extragerea avansată despre utilizatorul curent autentificat)
• UpdateUserProfile (NotImplemented) - nu cred că o voi implementa
• GetDocList (vizualizarea listei de medici activi in sistem)
• GetDoc (vizualizarea unui anumit medici activ in sistem)
• UserRequestConsultation (Adaugarea unei programari la medic)
1. Register
Server:
[API REG] POST
~/api/Register/UserReg
Header - Content-Type:application/x-www-form-urlencoded
Body
Content-Type:application/x-www-form-urlencoded
FullName=
Birthday= {FORMAT yyyy/MM/dd}
Email=
Phone=
Address=
Username=
Password=
Base64Photo {string:base64}=
[Link](new Callback<UserReg>() {
@Override
public void onResponse(Call<UserReg> call, Response<UserReg> response) {
[Link](getApplicationContext(), "Este necesara logarea.",
Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), [Link]));
}
@Override
public void onFailure(Call<UserReg> call, Throwable t) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
});
Design:
RESULT
"Status": "SUCCESS",
"Message": "TOKEN" < - need to be saved for future usage.
}
Android:
([Link])
@FormUrlEncoded
@POST("api/Login/UserAuth/")
Call<UserAuth> auth(
@Field("Email") String email,
@Field("Password") String password
);
([Link])
Retrofit retrofit = new [Link]()
.baseUrl("[Link]
.addConverterFactory([Link]())
.build();
[Link](new Callback<UserAuth>() {
@Override
public void onResponse(Call<UserAuth> call, Response<UserAuth> response) {
if ([Link]() != null) {
Log.e("TOKEN: ", [Link]().getMessage());
[Link] editor = getSharedPreferences("TOKEN",
MODE_PRIVATE).edit();
[Link]("TOKEN", [Link]().getMessage());
[Link]();
startActivity(new Intent(getApplicationContext(), Home_screen.class));
} else {
[Link](getApplicationContext(), "Login sau Parola incorecta.",
Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<UserAuth> call, Throwable t) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
});
Design:
In cazul in care Login/Parola este gresita utilizatorul este informat. In caz contrar, de la server se va
primi token-ul, iar utilizatorul este redirictionat catre urmatoarea pagina.
3. Doctor List
Server:
[API DOC LIST] GET
~/api/Doctor/GetDoctorList
Header - Content-Type:application/x-www-form-urlencoded
token=TOKEN
RESULT
{
"DocId": 1,
"FullName": "Arseni Andrei",
"Specs": "Oculist",
"Address": "str. Vasile Alecsandri 45A",
"About": "Medic Oculist cu experienta de 12 ani in domeniu.",
"Stars": 4.2,
"Photo": "base64:string"
},
{
"DocId": 2,
"FullName": "Stratila Alina",
"Specs": "Pediatru",
"Address": "str. Mihai Eminescu 12/3",
"About": "Medic Pediatru cu experienta de 7 ani in domeniu.",
"Stars": 4.8,
"Photo": "base64:string"
},
Android:
([Link])
@GET("api/Doctor/GetDoctorList/")
Call<List<API_Doctor_list>> docList(
@Header("token") String token,
@Header("Content-Type") String content_type
);
(Doctor_list.java)
Retrofit retrofit = new [Link]()
.baseUrl("[Link]
.addConverterFactory([Link]())
.build();
}
}
@Override
public void onFailure(Call<List<API_Doctor_list>> call, Throwable t) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
});
Design:
Fiecare field se genereaza apare pentru fiecare doctor in mod automat (cu ajutorul functie
structure()) vezi anexa.
4. Doc Info
Server:
[API DOC {id}] GET
~/api/Doctor/GetDoctor/1
Header - Content-Type:application/x-www-form-urlencoded
token=TOKEN
RESULT
{
"DocId": 1,
"FullName": "Arseni Andrei",
"Specs": "Oculist",
"Address": "str. Vasile Alecsandri 45A",
"About": "Medic Oculist cu experienta de 12 ani in domeniu.",
"Stars": 4.2,
"Photo": "base64:string"
},
Android:
([Link])
@GET("api/Doctor/GetDoctor/{id}")
Call<API_DocInfo> docInfo(
@Path("id") Integer id,
@Header("token") String token,
@Header("Content-Type") String content_type
);
(Doctor_details.java)
Retrofit retrofit = new [Link]()
.baseUrl("[Link]
.addConverterFactory([Link]())
.build();
profile_image.setImageBitmap(decodedByte);
[Link]([Link]().getFullName());
[Link]([Link]().getSpecs());
[Link]([Link]([Link]().getStars()));
[Link]([Link]().getAbout());
[Link]([Link]().getAddress());
address = [Link]().getAddress();
name = [Link]().getFullName();
}
@Override
public void onFailure(Call<API_DocInfo> call, Throwable t) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
});
Design:
Am implement si GMap care afiseaza pe harta locatia. De aceasta determinarea Lat Long se ocupa
Geocoder (vezi anexa).
5. Consulatie Request
Server:
[API CONSULTATION REQUEST] POST
~/api/Doctor/AddConsultation
Header - Content-Type:application/x-www-form-urlencoded
token=TOKEN
RESULT
"ConsId": 1,
"Name": "",
"Disease": "",
"Address": "",
"Description": "",
"DocId": 5,
"IsConfirmed": false
}
Android:
([Link])
@FormUrlEncoded
@POST("api/Doctor/AddConsultation/")
Call<ConsDet> approve(
@Field("ConsId") int consid,
@Field("Name") String name,
@Field("Disease") String disease,
@Field("Address") String address,
@Field("Description") String desc,
@Field("DocId") int docid,
@Field("IsConfirmed") Boolean bool
);
(Approve_notification.java)
Retrofit retrofit = new [Link]()
.baseUrl("[Link]
.addConverterFactory([Link]())
.build();
[Link](new Callback<ConsDet>() {
@Override
public void onResponse(Call<ConsDet> call, Response<ConsDet> response) {
[Link](getApplicationContext(), "Cerere plasata",
Toast.LENGTH_LONG).show();
startActivity(new Intent(getApplicationContext(), Home_screen.class));
}
@Override
public void onFailure(Call<ConsDet> call, Throwable t) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
});
Design:
Anexe:
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@FormUrlEncoded
@POST("api/Register/UserReg/")
Call<UserReg> register(
@Field("FullName") String fullname,
@Field("Birthday") String birthday,
@Field("Email") String email,
@Field("Phone") String phone,
@Field("Address") String address,
@Field("Username") String username,
@Field("Password") String password,
@Field("Base64Photo") String photo
);
@FormUrlEncoded
@POST("api/Login/UserAuth/")
Call<UserAuth> auth(
@Field("Email") String email,
@Field("Password") String password
);
@GET("api/Doctor/GetDoctorList/")
Call<List<API_Doctor_list>> docList(
@Header("token") String token,
@Header("Content-Type") String content_type
);
@GET("api/Doctor/GetDoctor/{id}")
Call<API_DocInfo> docInfo(
@Path("id") Integer id,
@Header("token") String token,
@Header("Content-Type") String content_type
);
@FormUrlEncoded
@POST("api/Doctor/AddConsultation/")
Call<ConsDet> approve(
@Field("ConsId") int consid,
@Field("Name") String name,
@Field("Disease") String disease,
@Field("Address") String address,
@Field("Description") String desc,
@Field("DocId") int docid,
@Field("IsConfirmed") Boolean bool
);
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].Base64;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Button btnNext;
ImageButton btnBack;
String photo =
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNMT0zfBA
AESQHjMAmi3AAAAABJRU5ErkJggg==";
EditText name, birthday, email, phone, address, username, password;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_sign_up);
btnBack = findViewById([Link]);
btnNext = findViewById([Link]);
name = findViewById([Link]);
birthday = findViewById([Link]);
email = findViewById([Link]);
phone = findViewById([Link]);
address = findViewById([Link]);
username = findViewById([Link]);
password = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
try {
while ((bytesRead = [Link](buffer)) != -1) {
[Link](buffer, 0, bytesRead);
}
}
catch (IOException e) {
[Link]();
}
bytes = [Link]();
String encodedString = [Link](bytes, [Link]);
*/
[Link](new Callback<UserReg>() {
@Override
public void onResponse(Call<UserReg> call, Response<UserReg> response) {
[Link](getApplicationContext(), "Este necesara logarea.",
Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), [Link]));
}
@Override
public void onFailure(Call<UserReg> call, Throwable t) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
});
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), [Link]));
}
});
}
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Button login;
TextView signUp;
EditText editEmail, editPass;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_login);
login = findViewById([Link]);
signUp = findViewById([Link]);
editEmail = findViewById([Link]);
editPass = findViewById([Link]);
[Link](v -> {
if ([Link]() != null) {
Log.e("TOKEN: ", [Link]().getMessage());
[Link] editor = getSharedPreferences("TOKEN",
MODE_PRIVATE).edit();
[Link]("TOKEN", [Link]().getMessage());
[Link]();
startActivity(new Intent(getApplicationContext(), Home_screen.class));
} else {
[Link](getApplicationContext(), "Login sau Parola incorecta.",
Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<UserAuth> call, Throwable t) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
});
});
}
}
Home_Screen.java
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Button btnRequest;
EditText name, desease, location, description;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_home_screen);
btnRequest = findViewById([Link]);
name = findViewById([Link]);
desease = findViewById([Link]);
location = findViewById([Link]);
description = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link] editor = getSharedPreferences("Request", MODE_PRIVATE).edit();
[Link]("name", [Link]().toString());
[Link]("desease", [Link]().toString());
[Link]("location", [Link]().toString());
[Link]("description", [Link]().toString());
[Link]();
startActivity(new Intent(getApplicationContext(), Doctor_list.class));
}
});
}
}
Doctor_List.java
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].Base64;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
ConstraintLayout docSelect;
LinearLayout parentLayout;
CircleImageView profile_image;
TextView textView9, nota, textView10, address;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_doctor_list);
docSelect = findViewById([Link]);
parentLayout = findViewById([Link]);
profile_image = findViewById([Link].profile_image);
textView9 = findViewById([Link].textView9);
nota = findViewById([Link]);
textView10 = findViewById([Link].textView10);
address = findViewById([Link]);
[Link]([Link]);
structure(
[Link](),
[Link](),
[Link](),
[Link]([Link]()),
[Link](),
[Link]());
}
}
@Override
public void onFailure(Call<List<API_Doctor_list>> call, Throwable t) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
});
void structure(int docID, String ph, String nam, String st, String spe, String loc){
ConstraintLayout doc = new ConstraintLayout(getApplicationContext());
[Link]([Link]());
[Link]([Link]);
[Link](decodedByte);
[Link](photo);
TextView name = (TextView)getLayoutInflater().inflate([Link], null);
[Link]([Link]());
[Link](nam);
[Link](name);
[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getBaseContext(), Doctor_details.class);
[Link]("docID", [Link](docID));
startActivity(intent);
}
});
[Link](doc);
}
}
Doctor_details.java
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].Base64;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Button btnRequest1;
TextView textView9, textView10, textView7, descr, textView8;
MapView gmap;
CircleImageView profile_image;
GoogleMap map;
String name, address;
Address locatie;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_doctor_details);
btnRequest1 = findViewById([Link].btnRequest1);
textView9 = findViewById([Link].textView9);
textView10 = findViewById([Link].textView10);
textView7 = findViewById([Link].textView7);
descr = findViewById([Link]);
textView8 = findViewById([Link].textView8);
gmap = findViewById([Link]);
profile_image = findViewById([Link].profile_image);
[Link](savedInstanceState);
[Link](this);
[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getBaseContext(), Approve_notification.class);
[Link]("docID", [Link](docID));
startActivity(intent);
}
});
profile_image.setImageBitmap(decodedByte);
[Link]([Link]().getFullName());
[Link]([Link]().getSpecs());
[Link]([Link]([Link]().getStars()));
[Link]([Link]().getAbout());
[Link]([Link]().getAddress());
address = [Link]().getAddress();
name = [Link]().getFullName();
}
@Override
public void onFailure(Call<API_DocInfo> call, Throwable t) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
});
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
[Link]().setMyLocationButtonEnabled(false);
if ([Link](this, [Link].ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && [Link](this,
[Link].ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
[Link](getApplicationContext(), "Reject Permissions", Toast.LENGTH_SHORT).show();
return;
}
[Link](true);
try {
[Link](getApplicationContext());
} catch (Exception e) {
[Link]();
}
@Override
public void onResume() {
[Link]();
[Link]();
}
}
Approve_notification.java
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].Base64;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_approve_notification);
name = findViewById([Link]);
desease = findViewById([Link]);
location = findViewById([Link]);
description = findViewById([Link]);
docname = findViewById([Link].textView9);
profile_image = findViewById([Link].profile_image);
docspec = findViewById([Link].textView10);
star = findViewById([Link].textView7);
btnRequest2 = findViewById([Link].btnRequest2);
cancelRequest = findViewById([Link]);
profile_image.setImageBitmap(decodedByte);
[Link]([Link]().getFullName());
[Link]([Link]().getSpecs());
[Link]([Link]([Link]().getStars()));
docid = [Link]().getDocId();
}
@Override
public void onFailure(Call<API_DocInfo> call, Throwable t) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link](new Callback<ConsDet>() {
@Override
public void onResponse(Call<ConsDet> call, Response<ConsDet> response) {
[Link](getApplicationContext(), "Cerere plasata",
Toast.LENGTH_LONG).show();
startActivity(new Intent(getApplicationContext(), Home_screen.class));
}
@Override
public void onFailure(Call<ConsDet> call, Throwable t) {
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();
}
});
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link](getApplicationContext(), "Canceled", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), Home_screen.class));
}
});
}
}