Skip to content

Commit

Permalink
Merge pull request #36 from tsowa48/dev
Browse files Browse the repository at this point in the history
dev -> master
  • Loading branch information
tsowa48 authored Jun 24, 2021
2 parents 132b403 + 681dd18 commit f273e16
Show file tree
Hide file tree
Showing 99 changed files with 5,177 additions and 317 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ RUN ./gradlew -x test build
FROM openjdk:11.0
COPY --from=build /app/build/libs/dent-*-all.jar dent.jar
EXPOSE 8090
CMD java -Dfile.encoding=UTF-8 -Dcom.sun.management.jmxremote -noverify ${JAVA_OPTS} -jar dent.jar
CMD java -Dfile.encoding=UTF-8 -Dcom.sun.management.jmxremote -Dhibernate.types.print.banner=false -noverify ${JAVA_OPTS} -jar dent.jar
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'gcg.dent'
version '0.1'
version '0.3'

repositories {
mavenCentral()
Expand Down Expand Up @@ -90,4 +90,4 @@ shadowJar {


run.classpath += configurations.developmentOnly
run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1', '-Dcom.sun.management.jmxremote')
run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1', '-Dcom.sun.management.jmxremote', '-Dhibernate.types.print.banner=false')
12 changes: 3 additions & 9 deletions src/main/java/gcg/dent/controller/CalendarController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package gcg.dent.controller;

import gcg.dent.entity.Employee;
import gcg.dent.repository.CompanyRepository;
import gcg.dent.repository.EmployeeRepository;
import gcg.dent.repository.ScheduleRepository;
import gcg.dent.repository.ReferenceRepository;
import gcg.dent.service.CalendarService;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.annotation.Controller;
Expand All @@ -25,10 +24,7 @@ public class CalendarController {
EmployeeRepository employeeRepository;

@Inject
ScheduleRepository scheduleRepository;

@Inject
CompanyRepository companyRepository;
ReferenceRepository referenceRepository;

@View("calendar")
@Get
Expand All @@ -39,9 +35,7 @@ public HttpResponse<HashMap<String, Object>> calendar() throws URISyntaxExceptio
@View("calendar")
@Get(uri = "/week/{week}")
public HttpResponse<HashMap<String, Object>> calendar(Short week) throws URISyntaxException {
boolean isEmpty = scheduleRepository.isEmpty();
isEmpty |= employeeRepository.isEmpty();
isEmpty |= companyRepository.isEmpty();
boolean isEmpty = referenceRepository.isEmpty();
if(isEmpty) {
return HttpResponse.temporaryRedirect(new URI("/reference"));
}
Expand Down
87 changes: 87 additions & 0 deletions src/main/java/gcg/dent/controller/PatientController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package gcg.dent.controller;

import gcg.dent.entity.*;
import gcg.dent.repository.*;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.views.View;

import javax.inject.Inject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Controller("/patient")
public class PatientController {

@Inject
PatientRepository patientRepository;

@Inject
ClientRepository clientRepository;

@Inject
FindOutRepository findOutRepository;

@Inject
DocumentRepository documentRepository;

@Inject
ActTypeRepository actTypeRepository;

@Inject
EmployeeRepository employeeRepository;

@View("patients")
@Get
public HttpResponse<Map<String, Object>> getAllPatient() {
Map<String, Object> params = new HashMap<>();
List<Patient> allPatients = patientRepository.getAll();
List<Client> unattachedClients = clientRepository.getUnattached();
List<FindOut> allFindOut = findOutRepository.getAll();
params.put("patients", allPatients);
params.put("clients", unattachedClients);
params.put("findOut", allFindOut);
return HttpResponse.ok(params);
}

@View("patient")
@Get("/{id}")
public HttpResponse<Map<String, Object>> getPatient(Long id) {
Map<String, Object> params = new HashMap<>();
Patient patient = patientRepository.findById(id);

List<Document> docs = documentRepository.getAll();
List<Document> otherDocs = docs.stream()
.filter(d -> "other".equals(d.getType()))
.collect(Collectors.toList());
Document actUid = docs.stream()
.filter(d -> "act".equals(d.getType()))
.findFirst()
.orElse(null);
Document cardUid = docs.stream()
.filter(d -> "card".equals(d.getType()))
.findFirst()
.orElse(null);
Document contractUid = docs.stream()
.filter(d -> "contract".equals(d.getType()))
.findFirst()
.orElse(null);

List<ActType> actTypes = actTypeRepository.getAll();
List<Employee> employee = employeeRepository.getScheduled();

params.put("patient", patient);

params.put("act_uid", actUid);
params.put("card_uid", cardUid);
params.put("contract_uid", contractUid);
params.put("docs", otherDocs);

params.put("act_type", actTypes);
params.put("employee", employee);
return HttpResponse.ok(params);
}
}
25 changes: 25 additions & 0 deletions src/main/java/gcg/dent/controller/StatisticsController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gcg.dent.controller;

import gcg.dent.repository.StatisticsRepository;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.views.View;

import javax.inject.Inject;
import java.util.Map;

@Controller("/statistics")
public class StatisticsController {

@Inject
StatisticsRepository statisticsRepository;

@View("statistics")
@Get
public HttpResponse<Map<String, Object>> getStatistics() {
//Map<String, Object> params = statisticsRepository.getAll();

return HttpResponse.ok();//return HttpResponse.ok(params);
}
}
76 changes: 76 additions & 0 deletions src/main/java/gcg/dent/controller/api/ActController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package gcg.dent.controller.api;

import com.fasterxml.jackson.databind.JsonNode;
import gcg.dent.entity.*;
import gcg.dent.repository.*;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Post;

import javax.inject.Inject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

@Controller("/api/act")
public class ActController {

@Inject
ActRepository actRepository;

@Inject
EmployeeRepository employeeRepository;

@Inject
ActTypeRepository actTypeRepository;

@Inject
ContractRepository contractRepository;

@Inject
ServiceRepository serviceRepository;

@Post(produces = MediaType.APPLICATION_JSON)
public Act add(JsonNode rawAct) throws ParseException {
Act act = new Act();
Long aid = rawAct.get("aid").asLong();
Long did = rawAct.get("did").asLong();
Long atid = rawAct.get("atid").asLong();
Long doc = rawAct.get("doc").asLong();
Long number = rawAct.get("number").asLong();
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(rawAct.get("date").asText());
Iterator<JsonNode> services = rawAct.get("services").elements();

Employee doctor = employeeRepository.findById(doc);
ActType actType = actTypeRepository.findById(atid);
Contract contract = contractRepository.findById(did);

if(aid != 0) {
act.setId(aid);
}
act.setContract(contract);
act.setActType(actType);
act.setDoctor(doctor);
act.setNumber(number);
act.setDate(date);
final Act result = actRepository.update(act);

List<ActService> actServices = new ArrayList<>();
services.forEachRemaining(s -> {
Long sid = s.get("sid").asLong();
Integer count = s.get("count").asInt();
Service service = serviceRepository.findById(sid);
ActService actService = new ActService();
actService.setAmount(count);
actService.setService(service);
actService.setDate(result.getDateAsDate());
actService.setAct(result);
actServices.add(actService);
});
actRepository.batchUpdate(actServices);
return result;
}
}
43 changes: 43 additions & 0 deletions src/main/java/gcg/dent/controller/api/ActTypeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package gcg.dent.controller.api;

import gcg.dent.entity.ActType;
import gcg.dent.repository.ActTypeRepository;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;

import javax.inject.Inject;
import java.util.List;

@Controller("/api/act_type")
public class ActTypeController {

@Inject
ActTypeRepository actTypeRepository;

@Get(uri = "/{id}", produces = MediaType.APPLICATION_JSON)
public ActType get(Long id) {
return actTypeRepository.findById(id);
}

@Get(produces = MediaType.APPLICATION_JSON)
public List<ActType> getAll() {
return actTypeRepository.getAll();
}

@Post(produces = MediaType.APPLICATION_JSON)
public ActType add(ActType actType) {
return actTypeRepository.addActType(actType);
}

@Put(produces = MediaType.APPLICATION_JSON)
public ActType change(ActType actType) {
return actTypeRepository.update(actType);
}

@Delete(uri = "/{id}", produces = MediaType.APPLICATION_JSON)
public HttpResponse remove(Long id) {
actTypeRepository.removeById(id);
return HttpResponse.ok();
}
}
87 changes: 87 additions & 0 deletions src/main/java/gcg/dent/controller/api/DocumentController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package gcg.dent.controller.api;

import com.fasterxml.jackson.databind.JsonNode;
import gcg.dent.entity.Document;
import gcg.dent.repository.DocumentRepository;
import gcg.dent.util.Templates;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;
import io.micronaut.http.server.types.files.StreamedFile;

import javax.annotation.Nullable;
import javax.inject.Inject;
import java.io.OutputStreamWriter;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller("/api/document")
public class DocumentController {

@Inject
DocumentRepository documentRepository;

@Inject
Templates templates;

/*@Get(uri = "/{id}", produces = MediaType.APPLICATION_JSON)
public Document get(Long id) {
return documentRepository.findById(id);
}*/

@Get(produces = MediaType.APPLICATION_JSON)
public List<Document> getAll() {
return documentRepository.getAll();
}

@Post(produces = MediaType.APPLICATION_JSON)
public Document add(Document document) {
return documentRepository.addDocument(document);
}

@Put(produces = MediaType.APPLICATION_JSON)
public Document change(Document document) {
return documentRepository.update(document);
}

@Delete(uri = "/{id}", produces = MediaType.APPLICATION_JSON)
public HttpResponse remove(Long id) {
documentRepository.removeById(id);
return HttpResponse.ok();
}

@Get(uri = "/download")
public HttpResponse<byte[]> download(Long uid,
@Nullable Long act,
@Nullable Long card,
@Nullable Long client,
@Nullable Long contract,
@Nullable Long employee,
@Nullable Long history,
@Nullable Long patient)
throws Exception {
Document document = documentRepository.findById(uid);
String fileName = URLEncoder.encode(document.getName(), "UTF-8").replace("+", "%20") + ".doc";

Map<String, Object> params = new HashMap<>();
params.put("act", act);
params.put("card", card);
params.put("client", client);
params.put("contract", contract);
params.put("employee", employee);
params.put("history", history);
params.put("patient", patient);

String content = templates.load(document, params);

return HttpResponse.ok(content.getBytes())
.header("Content-type", "application/octet-stream")
.header("Content-disposition", "attachment; filename=\"" + fileName + "\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class EmployeeController {

@Get(uri = "/{id}", produces = MediaType.APPLICATION_JSON)
public Employee get(Long id) {
return employeeRepository.getById(id);
return employeeRepository.findById(id);
}

@Get(produces = MediaType.APPLICATION_JSON)
Expand Down
Loading

0 comments on commit f273e16

Please sign in to comment.