diff --git a/Dockerfile b/Dockerfile index 84ebc76..73792db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/build.gradle b/build.gradle index 9175db5..0d08505 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'gcg.dent' -version '0.1' +version '0.3' repositories { mavenCentral() @@ -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') diff --git a/src/main/java/gcg/dent/controller/CalendarController.java b/src/main/java/gcg/dent/controller/CalendarController.java index 9aa7219..b517615 100644 --- a/src/main/java/gcg/dent/controller/CalendarController.java +++ b/src/main/java/gcg/dent/controller/CalendarController.java @@ -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; @@ -25,10 +24,7 @@ public class CalendarController { EmployeeRepository employeeRepository; @Inject - ScheduleRepository scheduleRepository; - - @Inject - CompanyRepository companyRepository; + ReferenceRepository referenceRepository; @View("calendar") @Get @@ -39,9 +35,7 @@ public HttpResponse> calendar() throws URISyntaxExceptio @View("calendar") @Get(uri = "/week/{week}") public HttpResponse> 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")); } diff --git a/src/main/java/gcg/dent/controller/PatientController.java b/src/main/java/gcg/dent/controller/PatientController.java new file mode 100644 index 0000000..e843198 --- /dev/null +++ b/src/main/java/gcg/dent/controller/PatientController.java @@ -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> getAllPatient() { + Map params = new HashMap<>(); + List allPatients = patientRepository.getAll(); + List unattachedClients = clientRepository.getUnattached(); + List 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> getPatient(Long id) { + Map params = new HashMap<>(); + Patient patient = patientRepository.findById(id); + + List docs = documentRepository.getAll(); + List 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 actTypes = actTypeRepository.getAll(); + List 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); + } +} diff --git a/src/main/java/gcg/dent/controller/StatisticsController.java b/src/main/java/gcg/dent/controller/StatisticsController.java new file mode 100644 index 0000000..a82ba4f --- /dev/null +++ b/src/main/java/gcg/dent/controller/StatisticsController.java @@ -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> getStatistics() { + //Map params = statisticsRepository.getAll(); + + return HttpResponse.ok();//return HttpResponse.ok(params); + } +} diff --git a/src/main/java/gcg/dent/controller/api/ActController.java b/src/main/java/gcg/dent/controller/api/ActController.java new file mode 100644 index 0000000..e0bfbb2 --- /dev/null +++ b/src/main/java/gcg/dent/controller/api/ActController.java @@ -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 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 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; + } +} diff --git a/src/main/java/gcg/dent/controller/api/ActTypeController.java b/src/main/java/gcg/dent/controller/api/ActTypeController.java new file mode 100644 index 0000000..f71a769 --- /dev/null +++ b/src/main/java/gcg/dent/controller/api/ActTypeController.java @@ -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 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(); + } +} diff --git a/src/main/java/gcg/dent/controller/api/DocumentController.java b/src/main/java/gcg/dent/controller/api/DocumentController.java new file mode 100644 index 0000000..0855c25 --- /dev/null +++ b/src/main/java/gcg/dent/controller/api/DocumentController.java @@ -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 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 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 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 + "\""); + } +} diff --git a/src/main/java/gcg/dent/controller/api/EmployeeController.java b/src/main/java/gcg/dent/controller/api/EmployeeController.java index 602a8c7..2fccf3d 100644 --- a/src/main/java/gcg/dent/controller/api/EmployeeController.java +++ b/src/main/java/gcg/dent/controller/api/EmployeeController.java @@ -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) diff --git a/src/main/java/gcg/dent/controller/api/ErrorController.java b/src/main/java/gcg/dent/controller/api/ErrorController.java new file mode 100644 index 0000000..cf9b4e5 --- /dev/null +++ b/src/main/java/gcg/dent/controller/api/ErrorController.java @@ -0,0 +1,28 @@ +package gcg.dent.controller.api; + +import io.micronaut.http.HttpRequest; +import io.micronaut.http.HttpResponse; +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Post; +import io.micronaut.http.annotation.Error; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Controller("/api/js") +public class ErrorController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Post("/error") + public HttpResponse jsError(String msg, String url, Long line) { + logger.error("JS error in '{}' at line {}: \"{}\"", url, line, msg); + return HttpResponse.ok(); + } + + @Error(global = true) + public HttpResponse appError(HttpRequest request, Exception ex) { + String stacktrace = ExceptionUtils.getStackTrace(ex); + logger.error("Request: {}, ExceptionWithStacktrace: {}", request, stacktrace, ex); + return HttpResponse.ok(); + } +} diff --git a/src/main/java/gcg/dent/controller/api/HistoryController.java b/src/main/java/gcg/dent/controller/api/HistoryController.java new file mode 100644 index 0000000..a5c5fec --- /dev/null +++ b/src/main/java/gcg/dent/controller/api/HistoryController.java @@ -0,0 +1,33 @@ +package gcg.dent.controller.api; + +import gcg.dent.entity.History; +import gcg.dent.repository.HistoryRepository; +import io.micronaut.http.MediaType; +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; +import io.micronaut.http.annotation.Post; +import io.micronaut.http.annotation.Put; + +import javax.inject.Inject; + +@Controller("/api/history") +public class HistoryController { + + @Inject + HistoryRepository historyRepository; + + @Get(uri = "/{id}", produces = MediaType.APPLICATION_JSON) + public History get(Long id) { + return historyRepository.findById(id); + } + + @Post(produces = MediaType.APPLICATION_JSON) + public History add(History history) { + return historyRepository.addHistory(history); + } + + @Put(produces = MediaType.APPLICATION_JSON) + public History change(History history) { + return historyRepository.update(history); + } +} diff --git a/src/main/java/gcg/dent/controller/api/PatientController.java b/src/main/java/gcg/dent/controller/api/PatientController.java index c7c4e26..ac9c31a 100644 --- a/src/main/java/gcg/dent/controller/api/PatientController.java +++ b/src/main/java/gcg/dent/controller/api/PatientController.java @@ -41,4 +41,9 @@ public HttpResponse remove(Long id) { return HttpResponse.ok(); } + @Post(value = "/find", produces = MediaType.APPLICATION_JSON) + public List findByFio(String fio) { + return patientRepository.findByFio(fio); + } + } \ No newline at end of file diff --git a/src/main/java/gcg/dent/controller/api/ServiceController.java b/src/main/java/gcg/dent/controller/api/ServiceController.java index 3bfab59..4e3def9 100644 --- a/src/main/java/gcg/dent/controller/api/ServiceController.java +++ b/src/main/java/gcg/dent/controller/api/ServiceController.java @@ -41,4 +41,8 @@ public HttpResponse remove(Long id) { return HttpResponse.ok(); } + @Get(uri = "/type/{actType}", produces = MediaType.APPLICATION_JSON) + public List getByActType(Long actType) { + return serviceRepository.getByActType(actType); + } } \ No newline at end of file diff --git a/src/main/java/gcg/dent/controller/api/SlotController.java b/src/main/java/gcg/dent/controller/api/SlotController.java index 1ccf133..719d4f9 100644 --- a/src/main/java/gcg/dent/controller/api/SlotController.java +++ b/src/main/java/gcg/dent/controller/api/SlotController.java @@ -5,6 +5,7 @@ import gcg.dent.entity.Slot; import gcg.dent.repository.ClientRepository; import gcg.dent.repository.EmployeeRepository; +import gcg.dent.repository.PatientRepository; import gcg.dent.repository.SlotRepository; import io.micronaut.http.HttpResponse; import io.micronaut.http.MediaType; @@ -12,15 +13,20 @@ import io.micronaut.http.annotation.Delete; import io.micronaut.http.annotation.Get; import io.micronaut.http.annotation.Post; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.persistence.EntityManager; import javax.transaction.Transactional; import java.sql.Time; import java.util.Date; +import java.util.Optional; @Controller("/api/slot") public class SlotController { + private static final Logger logger = LoggerFactory.getLogger(SlotController.class); @Inject SlotRepository slotRepository; @@ -31,6 +37,9 @@ public class SlotController { @Inject EmployeeRepository employeeRepository; + @Inject + PatientRepository patientRepository; + @Inject EntityManager entityManager; @@ -41,15 +50,28 @@ public Slot get(Long id) { @Transactional @Post(uri = "/add", produces = MediaType.APPLICATION_JSON) - public Slot add(String fio, String phone, Long doc, Date date, String time, Integer size) { - Client client = clientRepository.find(fio, phone); - Employee doctor = employeeRepository.getById(doc); - String sizeTime = String.format("%02d:%02d:00", (size / 60), size % 60); - Slot slot = slotRepository.makeSlot(date, Time.valueOf(time + ":00"), Time.valueOf(sizeTime)); - slot.setClient(client); - slot.setDoctor(doctor); - entityManager.persist(slot); - return slot; + public Slot add(Optional fio, Optional phone, Long doc, Date date, String time, Integer size, Optional note, Optional pid) throws Exception { + try { + Employee doctor = employeeRepository.findById(doc); + String sizeTime = String.format("%02d:%02d:00", (size / 60), size % 60); + Slot slot = slotRepository.makeSlot(date, Time.valueOf(time + ":00"), Time.valueOf(sizeTime)); + if (fio.isPresent() && phone.isPresent()) { + Client client = clientRepository.find(fio.get(), phone.get()); + if (pid.isPresent() && pid.get() > 0) { + client.setPatient(patientRepository.findById(pid.get())); + } + slot.setNote(note.get()); + slot.setClient(client); + slot.setEnabled(true); + } + slot.setDoctor(doctor); + entityManager.persist(slot); + return slot; + } catch(Exception ex) { + String stacktrace = ExceptionUtils.getStackTrace(ex); + logger.error("Can't add slot: {}", stacktrace, ex); + throw new Exception("Can't add slot"); + } } @Delete(uri="/{id}", produces = MediaType.APPLICATION_JSON) diff --git a/src/main/java/gcg/dent/controller/api/SqlController.java b/src/main/java/gcg/dent/controller/api/SqlController.java new file mode 100644 index 0000000..dfcba38 --- /dev/null +++ b/src/main/java/gcg/dent/controller/api/SqlController.java @@ -0,0 +1,40 @@ +package gcg.dent.controller.api; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.micronaut.http.HttpResponse; +import io.micronaut.http.MediaType; +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Put; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import javax.transaction.Transactional; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Controller("/api/sql") +public class SqlController { + + @PersistenceContext + private EntityManager entityManager; + + static final ObjectMapper mapper = new ObjectMapper(); + + @Put(produces = MediaType.APPLICATION_JSON) + @Transactional + public HttpResponse executeUpdate(String sql, JsonNode params) { + HashMap mapParams = mapper.convertValue(params, new TypeReference>() {}); + List> arrParams = (List)mapParams.get("params"); + Query query = entityManager.createNativeQuery(sql); + arrParams.forEach(p -> { + Map.Entry entry = p.entrySet().iterator().next(); + query.setParameter(entry.getKey(), entry.getValue()); + }); + query.executeUpdate(); + return HttpResponse.ok(); + } +} diff --git a/src/main/java/gcg/dent/entity/Act.java b/src/main/java/gcg/dent/entity/Act.java index 5d1c250..5fd3b92 100644 --- a/src/main/java/gcg/dent/entity/Act.java +++ b/src/main/java/gcg/dent/entity/Act.java @@ -1,11 +1,17 @@ package gcg.dent.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; +import gcg.dent.util.ObjectUtils; + import javax.persistence.*; +import java.io.Serializable; +import java.util.ArrayList; import java.util.Date; +import java.util.List; @Entity @Table(name = "act", schema = "public") -public class Act { +public class Act implements Serializable { @Id @SequenceGenerator(name = "act_id_seq", sequenceName = "public.act_id_seq", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "act_id_seq") @@ -15,16 +21,24 @@ public class Act { @Column(name = "number", nullable = false) private Long number; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "doc") + private Employee doctor; + @Column(name = "date", nullable = false) private Date date; - @Column(name = "type", nullable = false) - private Integer type; - + @JsonIgnore @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "did", nullable = false) private Contract contract; + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "atid", nullable = false) + private ActType actType; + + @OneToMany(mappedBy = "act", fetch = FetchType.EAGER) + private List actServices = new ArrayList<>(); public Long getId() { return id; @@ -42,22 +56,14 @@ public void setNumber(Long number) { this.number = number; } - public Date getDate() { - return date; + public String getDate() { + return ObjectUtils.dateFormat.format(date); } public void setDate(Date date) { this.date = date; } - public Integer getType() { - return type; - } - - public void setType(Integer type) { - this.type = type; - } - public Contract getContract() { return contract; } @@ -65,4 +71,32 @@ public Contract getContract() { public void setContract(Contract contract) { this.contract = contract; } -} + + public ActType getActType() { + return actType; + } + + public void setActType(ActType actType) { + this.actType = actType; + } + + public Employee getDoctor() { + return doctor; + } + + public void setDoctor(Employee doctor) { + this.doctor = doctor; + } + + public List getActServices() { + return actServices; + } + + public void setActServices(List actServices) { + this.actServices = actServices; + } + + public Date getDateAsDate() { + return this.date; + } +} \ No newline at end of file diff --git a/src/main/java/gcg/dent/entity/ActService.java b/src/main/java/gcg/dent/entity/ActService.java new file mode 100644 index 0000000..42c4a21 --- /dev/null +++ b/src/main/java/gcg/dent/entity/ActService.java @@ -0,0 +1,80 @@ +package gcg.dent.entity; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; +import java.util.Objects; + +@Entity +@Table(name = "act_service", schema = "public") +public class ActService implements Serializable { + @Id + private Long aid; + @Id + private Long sid; + + @JsonIgnore + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "aid") + private Act act; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "sid") + private Service service; + + @Column(name = "amount", nullable = false) + private Integer amount; + + @Column(name = "date", nullable = false) + private Date date; + + public Act getAct() { + return act; + } + + public void setAct(Act act) { + this.act = act; + } + + public Service getService() { + return service; + } + + public void setService(Service service) { + this.service = service; + } + + public Integer getAmount() { + return amount; + } + + public void setAmount(Integer amount) { + this.amount = amount; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ActService that = (ActService) o; + return aid.equals(that.aid) && + sid.equals(that.sid) && + amount.equals(that.amount) && + date.equals(that.date); + } + + @Override + public int hashCode() { + return Objects.hash(aid, sid, amount, date); + } +} \ No newline at end of file diff --git a/src/main/java/gcg/dent/entity/ActType.java b/src/main/java/gcg/dent/entity/ActType.java new file mode 100644 index 0000000..d1563fd --- /dev/null +++ b/src/main/java/gcg/dent/entity/ActType.java @@ -0,0 +1,32 @@ +package gcg.dent.entity; + +import javax.persistence.*; + +@Entity +@Table(name = "act_type", schema = "public") +public class ActType { + @Id + @SequenceGenerator(name = "act_type_id_seq", sequenceName = "public.act_type_id_seq", allocationSize = 1) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "act_type_id_seq") + @Column(name = "id", nullable = false, unique = true) + private Long id; + + @Column(name = "name", nullable = false) + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/gcg/dent/entity/Card.java b/src/main/java/gcg/dent/entity/Card.java index 0168b32..39e0a28 100644 --- a/src/main/java/gcg/dent/entity/Card.java +++ b/src/main/java/gcg/dent/entity/Card.java @@ -1,7 +1,12 @@ package gcg.dent.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; +import gcg.dent.util.ObjectUtils; + import javax.persistence.*; +import java.util.ArrayList; import java.util.Date; +import java.util.List; @Entity @Table(name = "card", schema = "public") @@ -18,22 +23,21 @@ public class Card { @Column(name = "date", nullable = false) private Date date; - @Column(name = "diagnosis", nullable = false) - private String diagnosis; - - @Column(name = "complaints", nullable = false) - private String complaints; + @JsonIgnore + @Column(name = "pid", nullable = false, insertable = false, updatable = false) + private Long pid; - @Column(name = "anamnesis", nullable = false) - private String anamnesis; + @JsonIgnore + @OneToOne + @JoinColumn(name = "pid", insertable = false, updatable = false) + private Patient patient; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "doc") - private Employee doc; + @JoinColumn(name = "cid", nullable = false) + private Company company; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "pid") - private Patient patient; + @OneToMany(mappedBy = "card", fetch = FetchType.LAZY) + private List history = new ArrayList<>(); public void setId(Long id) { this.id = id; @@ -43,22 +47,6 @@ public Long getId() { return id; } - public void setDiagnosis(String diagnosis) { - this.diagnosis = diagnosis; - } - - public String getDiagnosis() { - return diagnosis; - } - - public void setComplaints(String complaints) { - this.complaints = complaints; - } - - public String getComplaints() { - return complaints; - } - public void setNumber(Long number) { this.number = number; } @@ -67,35 +55,35 @@ public Long getNumber() { return number; } - public void setAnamnesis(String anamnesis) { - this.anamnesis = anamnesis; + public void setDate(Date date) { + this.date = date; } - public String getAnamnesis() { - return anamnesis; + public String getDate() { + return ObjectUtils.dateFormat.format(this.date); } - public void setDate(Date date) { - this.date = date; + public Long getPid() { + return pid; } - public Date getDate() { - return date; + public void setPid(Long pid) { + this.pid = pid; } - public Employee getDoc() { - return doc; + public Company getCompany() { + return company; } - public void setDoc(Employee doc) { - this.doc = doc; + public void setCompany(Company company) { + this.company = company; } - public void setPatient(Patient patient) { - this.patient = patient; + public List getHistory() { + return history; } - public Patient getPatient() { - return patient; + public void setHistory(List history) { + this.history = history; } } \ No newline at end of file diff --git a/src/main/java/gcg/dent/entity/Client.java b/src/main/java/gcg/dent/entity/Client.java index d35aaf7..545d2d4 100644 --- a/src/main/java/gcg/dent/entity/Client.java +++ b/src/main/java/gcg/dent/entity/Client.java @@ -52,4 +52,5 @@ public Patient getPatient() { public void setPatient(Patient patient) { this.patient = patient; } + } diff --git a/src/main/java/gcg/dent/entity/Contract.java b/src/main/java/gcg/dent/entity/Contract.java index b712c49..ff9165b 100644 --- a/src/main/java/gcg/dent/entity/Contract.java +++ b/src/main/java/gcg/dent/entity/Contract.java @@ -1,10 +1,19 @@ package gcg.dent.entity; +import com.fasterxml.jackson.databind.JsonNode; +import com.vladmihalcea.hibernate.type.json.JsonBinaryType; +import gcg.dent.util.ObjectUtils; +import org.hibernate.annotations.Type; +import org.hibernate.annotations.TypeDef; + import javax.persistence.*; +import java.util.ArrayList; import java.util.Date; +import java.util.List; @Entity @Table(name = "contract", schema = "public") +@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class, defaultForType = JsonNode.class) public class Contract { @Id @SequenceGenerator(name = "contract_id_seq", sequenceName = "public.contract_id_seq", allocationSize = 1) @@ -18,25 +27,12 @@ public class Contract { @Column(name = "date", nullable = false) private Date date; - @Column(name = "warranty", nullable = false) - private String warranty; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "cid", nullable = false) - private Company company; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name ="doc", nullable = false) - private Employee doctor; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "pid") - private Patient patient; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "tech") - private Employee tech; + @Type(type = "jsonb") + @Column(name = "props", columnDefinition = "jsonb") + private JsonNode props; + @OneToMany(mappedBy = "contract", fetch = FetchType.EAGER) + private List acts = new ArrayList<>(); public void setId(Long id) { this.id = id; @@ -58,47 +54,23 @@ public void setDate(Date date) { this.date = date; } - public Date getDate() { - return date; - } - - public void setWarranty(String warranty) { - this.warranty = warranty; - } - - public String getWarranty() { - return warranty; - } - - public void setCompany(Company company) { - this.company = company; - } - - public Company getCompany() { - return company; - } - - public Employee getDoctor() { - return doctor; - } - - public void setDoctor(Employee doctor) { - this.doctor = doctor; + public String getDate() { + return ObjectUtils.dateFormat.format(this.date); } - public Patient getPatient() { - return patient; + public JsonNode getProps() { + return props; } - public void setPatient(Patient patient) { - this.patient = patient; + public void setProps(JsonNode props) { + this.props = props; } - public Employee getTech() { - return tech; + public void setActs(List acts) { + this.acts = acts; } - public void setTech(Employee tech) { - this.tech = tech; + public List getActs() { + return acts; } } \ No newline at end of file diff --git a/src/main/java/gcg/dent/entity/Document.java b/src/main/java/gcg/dent/entity/Document.java new file mode 100644 index 0000000..5c94493 --- /dev/null +++ b/src/main/java/gcg/dent/entity/Document.java @@ -0,0 +1,55 @@ +package gcg.dent.entity; + +import javax.persistence.*; + +@Entity +@Table(name = "docs", schema = "public") +public class Document { + @Id + @SequenceGenerator(name = "docs_id_seq", sequenceName = "public.docs_id_seq", allocationSize = 1) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "docs_id_seq") + @Column(name = "id", nullable = false, unique = true) + private Long id; + + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "type", nullable = false) + private String type; + + @Column(name = "hbs", nullable = false) + private String template; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getTemplate() { + return template; + } + + public void setTemplate(String template) { + this.template = template; + } +} diff --git a/src/main/java/gcg/dent/entity/Employee.java b/src/main/java/gcg/dent/entity/Employee.java index 442424c..ce4042a 100644 --- a/src/main/java/gcg/dent/entity/Employee.java +++ b/src/main/java/gcg/dent/entity/Employee.java @@ -25,7 +25,7 @@ public class Employee { private boolean isScheduled; @Column(name = "is_disabled", nullable = false) - private boolean isDisabled; + private boolean faired; public Long getId() { @@ -68,11 +68,11 @@ public Company getCompany() { return company; } - public boolean isDisabled() { - return isDisabled; + public boolean isFaired() { + return faired; } - public void setDisabled(boolean disabled) { - isDisabled = disabled; + public void setFaired(boolean faired) { + this.faired = faired; } } \ No newline at end of file diff --git a/src/main/java/gcg/dent/entity/History.java b/src/main/java/gcg/dent/entity/History.java new file mode 100644 index 0000000..83ce07f --- /dev/null +++ b/src/main/java/gcg/dent/entity/History.java @@ -0,0 +1,92 @@ +package gcg.dent.entity; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import com.vladmihalcea.hibernate.type.json.JsonBinaryType; +import gcg.dent.util.ObjectUtils; +import org.hibernate.annotations.Type; +import org.hibernate.annotations.TypeDef; +import javax.persistence.*; +import javax.transaction.Transactional; +import java.util.Date; + +@Entity +@Table(name = "history", schema = "public") +@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class, defaultForType = JsonNode.class) +public class History { + @Id + @SequenceGenerator(name = "history_id_seq", sequenceName = "public.history_id_seq", allocationSize = 1) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "history_id_seq") + @Column(name = "id", nullable = false, unique = true) + private Long id; + + @JsonIgnore + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "cid") + private Card card; + + @Type(type = "jsonb") + @Column(name = "props", columnDefinition = "jsonb") + private JsonNode props; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "did") + private Contract contract; + + @Column(name = "date", nullable = false) + private Date date; + + @Transient + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private Long cid; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Card getCard() { + return card; + } + + public void setCard(Card card) { + this.card = card; + } + + public Long getCid() { + return cid; + } + + public void setProps(JsonNode props) { + this.props = props; + } + + public JsonNode getProps() { + return props; + } + + public void setContract(Contract contract) { + this.contract = contract; + } + + public Contract getContract() { + return contract; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getDate() { + return ObjectUtils.dateFormat.format(date); + } + + public Date getDateAsDate() { + return this.date; + } +} \ No newline at end of file diff --git a/src/main/java/gcg/dent/entity/Manipulation.java b/src/main/java/gcg/dent/entity/Manipulation.java index 8e34f5b..58a4319 100644 --- a/src/main/java/gcg/dent/entity/Manipulation.java +++ b/src/main/java/gcg/dent/entity/Manipulation.java @@ -1,5 +1,7 @@ package gcg.dent.entity; +import com.fasterxml.jackson.annotation.JsonProperty; + import javax.persistence.*; @Entity @@ -14,6 +16,7 @@ public class Manipulation { @Column(name = "name", nullable = false) private String name; + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "sid", nullable = false) private Service service; @@ -41,4 +44,9 @@ public Service getService() { public void setService(Service service) { this.service = service; } + + @JsonProperty(value = "sid", access = JsonProperty.Access.READ_ONLY) + public Long getSid() { + return this.service.getId(); + } } diff --git a/src/main/java/gcg/dent/entity/Patient.java b/src/main/java/gcg/dent/entity/Patient.java index 9d5b956..971d9c3 100644 --- a/src/main/java/gcg/dent/entity/Patient.java +++ b/src/main/java/gcg/dent/entity/Patient.java @@ -1,10 +1,18 @@ package gcg.dent.entity; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import com.vladmihalcea.hibernate.type.json.JsonBinaryType; +import gcg.dent.util.ObjectUtils; +import org.hibernate.annotations.Type; +import org.hibernate.annotations.TypeDef; + import javax.persistence.*; import java.util.Date; @Entity @Table(name = "patient", schema = "public") +@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class, defaultForType = JsonNode.class) public class Patient { @Id @SequenceGenerator(name = "patient_id_seq", sequenceName = "public.patient_id_seq", allocationSize = 1) @@ -25,12 +33,29 @@ public class Patient { private Date birth; @Column(name = "sex", nullable = false) - private Boolean isMale; + private boolean isMale; + + @Type(type = "jsonb") + @Column(name = "props", columnDefinition = "jsonb") + private JsonNode props; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "fid") private FindOut findOut; + @OneToOne(mappedBy = "patient", fetch = FetchType.LAZY) + private Card card; + + + public Patient() { + } + + public Patient(Long id, String fio, String phone) { + this.id = id; + this.fio = fio; + this.phone = phone; + this.birth = new Date(); + } public Long getId() { return id; @@ -64,22 +89,27 @@ public void setAddress(String address) { this.address = address; } - public Date getBirth() { - return birth; + public String getBirth() { + return ObjectUtils.dateFormat.format(birth); } public void setBirth(Date birth) { this.birth = birth; } - public Boolean getMale() { + public boolean isMale() { return isMale; } - public void setMale(Boolean male) { + public void setMale(boolean male) { isMale = male; } + @JsonProperty(value = "sex", access = JsonProperty.Access.READ_ONLY) + public String getSex() { + return isMale() ? "мужской" : "женский"; + } + public FindOut getFindOut() { return findOut; } @@ -87,4 +117,12 @@ public FindOut getFindOut() { public void setFindOut(FindOut findOut) { this.findOut = findOut; } + + public Card getCard() { + return card; + } + + public void setCard(Card card) { + this.card = card; + } } \ No newline at end of file diff --git a/src/main/java/gcg/dent/entity/Schedule.java b/src/main/java/gcg/dent/entity/Schedule.java index f090ced..caee5d4 100644 --- a/src/main/java/gcg/dent/entity/Schedule.java +++ b/src/main/java/gcg/dent/entity/Schedule.java @@ -1,5 +1,8 @@ package gcg.dent.entity; +import com.fasterxml.jackson.annotation.JsonProperty; +import gcg.dent.util.ObjectUtils; + import javax.persistence.*; import java.sql.Time; @@ -15,8 +18,8 @@ public class Schedule { @Column(name = "start", nullable = false) private Time start; - @Column(name = "end", nullable = false) - private Time end; + @Column(name = "finish", nullable = false) + private Time finish; @Column(name = "dow", nullable = false) private int dow; @@ -37,12 +40,12 @@ public void setStart(Time start) { this.start = start; } - public Time getEnd() { - return end; + public Time getFinish() { + return finish; } - public void setEnd(Time end) { - this.end = end; + public void setFinish(Time finish) { + this.finish = finish; } public int getDow() { @@ -52,4 +55,19 @@ public int getDow() { public void setDow(int dow) { this.dow = dow; } + + @JsonProperty(value = "dayOfWeek", access = JsonProperty.Access.READ_ONLY) + public String getDayOfWeek() { + return ObjectUtils.weekDaysFull[getDow()]; + } + + @JsonProperty(value = "timeStart", access = JsonProperty.Access.READ_ONLY) + public String getTimeStart() { + return ObjectUtils.timeFormat.format(this.start); + } + + @JsonProperty(value = "timeFinish", access = JsonProperty.Access.READ_ONLY) + public String getTimeFinish() { + return ObjectUtils.timeFormat.format(this.finish); + } } diff --git a/src/main/java/gcg/dent/entity/Service.java b/src/main/java/gcg/dent/entity/Service.java index 85c6ca8..0cca949 100644 --- a/src/main/java/gcg/dent/entity/Service.java +++ b/src/main/java/gcg/dent/entity/Service.java @@ -1,10 +1,13 @@ package gcg.dent.entity; import javax.persistence.*; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; @Entity @Table(name = "service", schema = "public") -public class Service { +public class Service implements Serializable { @Id @SequenceGenerator(name = "service_id_seq", sequenceName = "public.service_id_seq", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "service_id_seq") @@ -17,6 +20,13 @@ public class Service { @Column(name = "price", nullable = false) private Double price; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "atid", nullable = false) + private ActType actType; + + @OneToMany(mappedBy = "service", fetch = FetchType.LAZY) + private List manipulations = new ArrayList<>(); + public void setId(Long id) { this.id = id; } @@ -40,4 +50,20 @@ public void setPrice(Double price) { public Double getPrice() { return price; } + + public ActType getActType() { + return actType; + } + + public void setActType(ActType actType) { + this.actType = actType; + } + + public List getManipulations() { + return manipulations; + } + + public void setManipulations(List manipulations) { + this.manipulations = manipulations; + } } diff --git a/src/main/java/gcg/dent/entity/Slot.java b/src/main/java/gcg/dent/entity/Slot.java index 0a643e6..c1845f2 100644 --- a/src/main/java/gcg/dent/entity/Slot.java +++ b/src/main/java/gcg/dent/entity/Slot.java @@ -14,7 +14,7 @@ public class Slot { private Long id; @Column(name = "enabled", nullable = false) - private Boolean enabled; + private boolean enabled; @Column(name = "date", nullable = false) private Date date; @@ -25,6 +25,9 @@ public class Slot { @Column(name = "size", nullable = false) private Time size; + @Column(name = "note") + private String note; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "cid") private Client client; @@ -42,11 +45,11 @@ public void setId(Long id) { this.id = id; } - public Boolean getEnabled() { + public boolean isEnabled() { return enabled; } - public void setEnabled(Boolean enabled) { + public void setEnabled(boolean enabled) { this.enabled = enabled; } @@ -89,4 +92,12 @@ public Employee getDoctor() { public void setDoctor(Employee doctor) { this.doctor = doctor; } + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } } diff --git a/src/main/java/gcg/dent/repository/ActRepository.java b/src/main/java/gcg/dent/repository/ActRepository.java new file mode 100644 index 0000000..cbecb2e --- /dev/null +++ b/src/main/java/gcg/dent/repository/ActRepository.java @@ -0,0 +1,45 @@ +package gcg.dent.repository; + +import gcg.dent.entity.Act; +import gcg.dent.entity.ActService; + +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.Transactional; +import java.util.List; + +@Singleton +public class ActRepository { + + @PersistenceContext + private EntityManager entityManager; + + @Transactional + public Act update(Act act) { + Act result = entityManager.merge(act); + entityManager.flush(); + return result; + } + + @Transactional + public boolean batchUpdate(List actServices) { + if(actServices.size() > 0) { + entityManager + .createNativeQuery("delete from act_service where aid=(:aid)") + .setParameter("aid", actServices.get(0).getAct().getId()) + .executeUpdate(); + } + actServices.forEach(as -> { + entityManager + .createNativeQuery("insert into act_service(sid, aid, amount, date) values (:sid, :aid, :amount, :date);") + .setParameter("sid", as.getService().getId()) + .setParameter("aid", as.getAct().getId()) + .setParameter("amount", as.getAmount()) + .setParameter("date", as.getDate()) + .executeUpdate(); + }); + entityManager.flush(); + return true; + } +} diff --git a/src/main/java/gcg/dent/repository/ActTypeRepository.java b/src/main/java/gcg/dent/repository/ActTypeRepository.java new file mode 100644 index 0000000..ba8ea7a --- /dev/null +++ b/src/main/java/gcg/dent/repository/ActTypeRepository.java @@ -0,0 +1,51 @@ +package gcg.dent.repository; + +import gcg.dent.entity.ActType; +import io.micronaut.transaction.annotation.ReadOnly; + +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.Transactional; +import java.util.List; + +@Singleton +public class ActTypeRepository { + + @PersistenceContext + private EntityManager entityManager; + + @Transactional + @ReadOnly + public List getAll() { + return entityManager + .createQuery("select A from ActType A order by A.name", ActType.class) + .getResultList(); + } + + @Transactional + public ActType addActType(ActType actType) { + actType.setId(null); + entityManager.persist(actType); + return actType; + } + + @Transactional + @ReadOnly + public ActType findById(Long id) { + return entityManager.find(ActType.class, id); + } + + @Transactional + public void removeById(Long id) { + entityManager.createQuery("delete from ActType A where A.id = :id") + .setParameter("id", id) + .executeUpdate(); + } + + @Transactional + public ActType update(ActType actType) { + entityManager.merge(actType); + return actType; + } +} diff --git a/src/main/java/gcg/dent/repository/CardRepository.java b/src/main/java/gcg/dent/repository/CardRepository.java new file mode 100644 index 0000000..18d632c --- /dev/null +++ b/src/main/java/gcg/dent/repository/CardRepository.java @@ -0,0 +1,45 @@ +package gcg.dent.repository; + +import gcg.dent.entity.Card; +import gcg.dent.entity.Patient; +import io.micronaut.transaction.annotation.ReadOnly; + +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.Transactional; + +@Singleton +public class CardRepository { + @PersistenceContext + private EntityManager entityManager; + + /** + * Get medical {@link Card} by {@link Patient} id + * @param pid {@link Patient} id + * @return {@link Card} + */ + @Transactional + @ReadOnly + public Card findByPatientId(Long pid) { + return entityManager + .createQuery("select C from Card C join fetch C.patient P where P.id = :pid", Card.class) + .setParameter("pid", pid) + .getSingleResult(); + } + + @Transactional + @ReadOnly + public Card findById(Long id) { + return entityManager.find(Card.class, id); + } + + @Transactional + public Card makeNew(Patient patient) { + return (Card) entityManager.createNativeQuery("insert into card(number, \"date\", pid, cid) " + + "values ((select coalesce(max(number), 0) + 1 from card), now(), (:pid), (select id from company order by name limit 1)) " + + "returning *;", Card.class) + .setParameter("pid", patient.getId()) + .getSingleResult(); + } +} diff --git a/src/main/java/gcg/dent/repository/ClientRepository.java b/src/main/java/gcg/dent/repository/ClientRepository.java index 9141a29..15a39f3 100644 --- a/src/main/java/gcg/dent/repository/ClientRepository.java +++ b/src/main/java/gcg/dent/repository/ClientRepository.java @@ -7,6 +7,7 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.transaction.Transactional; +import java.util.List; @Singleton public class ClientRepository { @@ -42,4 +43,11 @@ public Client find(String fio, String phone) { return makeClient(fio, phone); } } + + @Transactional + public List getUnattached() { + return entityManager + .createQuery("select C from Client C where C.patient is null order by C.fio", Client.class) + .getResultList(); + } } diff --git a/src/main/java/gcg/dent/repository/ContractRepository.java b/src/main/java/gcg/dent/repository/ContractRepository.java new file mode 100644 index 0000000..df401a1 --- /dev/null +++ b/src/main/java/gcg/dent/repository/ContractRepository.java @@ -0,0 +1,32 @@ +package gcg.dent.repository; + +import gcg.dent.entity.Contract; +import io.micronaut.transaction.annotation.ReadOnly; + +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.Transactional; + +@Singleton +public class ContractRepository { + + @PersistenceContext + private EntityManager entityManager; + + @Transactional + @ReadOnly + public Contract findById(Long id) { + return entityManager.find(Contract.class, id); + } + + @Transactional + public Contract makeContract() { + return (Contract)entityManager + .createNativeQuery("insert into contract(number, date) " + + "select coalesce(max(C.number), 0) + 1, now() " + + "from contract C where extract(year from C.date) = extract(year from now()) " + + "returning *", Contract.class) + .getSingleResult(); + } +} diff --git a/src/main/java/gcg/dent/repository/DocumentRepository.java b/src/main/java/gcg/dent/repository/DocumentRepository.java new file mode 100644 index 0000000..ecd9438 --- /dev/null +++ b/src/main/java/gcg/dent/repository/DocumentRepository.java @@ -0,0 +1,51 @@ +package gcg.dent.repository; + +import gcg.dent.entity.Document; +import io.micronaut.transaction.annotation.ReadOnly; + +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.Transactional; +import java.util.List; + +@Singleton +public class DocumentRepository { + + @PersistenceContext + private EntityManager entityManager; + + @Transactional + public Document addDocument(Document document) { + document.setId(null); + entityManager.persist(document); + return document; + } + + @Transactional + @ReadOnly + public Document findById(Long id) { + return entityManager.find(Document.class, id); + } + + @Transactional + @ReadOnly + public List getAll() { + return entityManager + .createQuery("select D from Document D order by D.name", Document.class) + .getResultList(); + } + + @Transactional + public void removeById(Long id) { + entityManager.createQuery("delete from Document D where D.id = :id") + .setParameter("id", id) + .executeUpdate(); + } + + @Transactional + public Document update(Document document) { + entityManager.merge(document); + return document; + } +} diff --git a/src/main/java/gcg/dent/repository/EmployeeRepository.java b/src/main/java/gcg/dent/repository/EmployeeRepository.java index 45748a7..8a055d4 100644 --- a/src/main/java/gcg/dent/repository/EmployeeRepository.java +++ b/src/main/java/gcg/dent/repository/EmployeeRepository.java @@ -19,7 +19,7 @@ public class EmployeeRepository { @ReadOnly public List getScheduled() { return entityManager - .createQuery("select E from Employee E where E.isScheduled = true and E.isDisabled = false order by E.fio", Employee.class) + .createQuery("select E from Employee E where E.isScheduled = true and E.faired = false order by E.fio", Employee.class) .getResultList(); } @@ -27,13 +27,13 @@ public List getScheduled() { @ReadOnly public List getAll() { return entityManager - .createQuery("select E from Employee E order by E.isDisabled, E.fio") + .createQuery("select E from Employee E order by E.faired, E.fio") .getResultList(); } @Transactional @ReadOnly - public Employee getById(Long id) { + public Employee findById(Long id) { return entityManager.find(Employee.class, id); } diff --git a/src/main/java/gcg/dent/repository/FindOutRepository.java b/src/main/java/gcg/dent/repository/FindOutRepository.java index 6e27e01..2512165 100644 --- a/src/main/java/gcg/dent/repository/FindOutRepository.java +++ b/src/main/java/gcg/dent/repository/FindOutRepository.java @@ -19,7 +19,7 @@ public class FindOutRepository { @ReadOnly public List getAll() { return entityManager - .createQuery("select F from FindOut F", FindOut.class) + .createQuery("select F from FindOut F order by F.name", FindOut.class) .getResultList(); } } diff --git a/src/main/java/gcg/dent/repository/HistoryRepository.java b/src/main/java/gcg/dent/repository/HistoryRepository.java new file mode 100644 index 0000000..b9594c6 --- /dev/null +++ b/src/main/java/gcg/dent/repository/HistoryRepository.java @@ -0,0 +1,67 @@ +package gcg.dent.repository; + +import gcg.dent.entity.Card; +import gcg.dent.entity.Contract; +import gcg.dent.entity.History; +import gcg.dent.entity.Patient; +import io.micronaut.transaction.annotation.ReadOnly; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.Transactional; +import java.util.Date; +import java.util.List; + +@Singleton +public class HistoryRepository { + + @PersistenceContext + private EntityManager entityManager; + + @Inject + private ContractRepository contractRepository; + + /** + * Get medical {@link History} by {@link Patient} id + * @param pid {@link Patient} id + * @return list of {@link History} + */ + @Transactional + @ReadOnly + public List getByPatientId(Long pid) { + return entityManager + .createQuery("select H from History H join fetch H.card C join fetch C.patient P where P.id = :pid", History.class) + .setParameter("pid", pid) + .getResultList(); + } + + @Transactional + @ReadOnly + public History findById(Long id) { + return entityManager.find(History.class, id); + } + + @Transactional + public History addHistory(History history) { + history.setId(null); + history.setDate(new Date()); + + Card card = entityManager.find(Card.class, history.getCid()); + Contract contract = contractRepository.makeContract(); + + history.setCard(card); + history.setContract(contract); + entityManager.persist(history); + return history; + } + + @Transactional + public History update(History history) { + History originalHistory = findById(history.getId()); + originalHistory.setProps(history.getProps()); + entityManager.flush(); + return originalHistory; + } +} diff --git a/src/main/java/gcg/dent/repository/ManipulationRepository.java b/src/main/java/gcg/dent/repository/ManipulationRepository.java index 9c90543..020fbd0 100644 --- a/src/main/java/gcg/dent/repository/ManipulationRepository.java +++ b/src/main/java/gcg/dent/repository/ManipulationRepository.java @@ -19,7 +19,7 @@ public class ManipulationRepository { @ReadOnly public List getAll() { return entityManager - .createQuery("select M from Manipulation M", Manipulation.class) + .createQuery("select M from Manipulation M join fetch M.service S order by S.name, M.name", Manipulation.class) .getResultList(); } diff --git a/src/main/java/gcg/dent/repository/PatientRepository.java b/src/main/java/gcg/dent/repository/PatientRepository.java index f49e594..4a4137c 100644 --- a/src/main/java/gcg/dent/repository/PatientRepository.java +++ b/src/main/java/gcg/dent/repository/PatientRepository.java @@ -3,6 +3,7 @@ import gcg.dent.entity.Patient; import io.micronaut.transaction.annotation.ReadOnly; +import javax.inject.Inject; import javax.inject.Singleton; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @@ -14,24 +15,49 @@ public class PatientRepository { @PersistenceContext private EntityManager entityManager; + @Inject + CardRepository cardRepository; + @Transactional @ReadOnly public List getAll() { return entityManager - .createQuery("select P from Patient P", Patient.class) + .createQuery("select P from Patient P order by P.fio", Patient.class) + .getResultList(); + } + + @Transactional + @ReadOnly + public List findByFio(String fioPart) { + return entityManager + .createQuery("select new Patient(P.id, P.fio, P.phone) from Patient P " + + "where lower(P.fio) like (:fioPart) " + + "order by P.fio", Patient.class) + .setParameter("fioPart", "%" + fioPart.toLowerCase() + "%") + .setMaxResults(10) .getResultList(); } @Transactional @ReadOnly public Patient findById(Long id) { - return entityManager.find(Patient.class, id); + return entityManager + .createQuery("select P from Patient P " + + "left join fetch P.findOut F " + + "left join fetch P.card C " + + "left join fetch C.history H " + + "left join fetch H.contract D " + + "where P.id = :id order by D.date desc", Patient.class) + .setParameter("id", id) + .getSingleResult(); } @Transactional public Patient addRecord(Patient patient) { patient.setId(null); entityManager.persist(patient); + entityManager.flush(); + cardRepository.makeNew(patient); return patient; } diff --git a/src/main/java/gcg/dent/repository/ReferenceRepository.java b/src/main/java/gcg/dent/repository/ReferenceRepository.java index a4b2370..0e4ee6d 100644 --- a/src/main/java/gcg/dent/repository/ReferenceRepository.java +++ b/src/main/java/gcg/dent/repository/ReferenceRepository.java @@ -1,9 +1,13 @@ package gcg.dent.repository; import gcg.dent.entity.*; +import io.micronaut.transaction.annotation.ReadOnly; import javax.inject.Inject; import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.Transactional; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -11,6 +15,9 @@ @Singleton public class ReferenceRepository { + @PersistenceContext + private EntityManager entityManager; + @Inject CompanyRepository companyRepository; @@ -20,25 +27,43 @@ public class ReferenceRepository { @Inject ScheduleRepository scheduleRepository; + @Inject + ActTypeRepository actTypeRepository; + @Inject ServiceRepository serviceRepository; @Inject ManipulationRepository manipulationRepository; + @Inject + DocumentRepository documentRepository; + public Map getReferences() { HashMap params = new HashMap<>(); List company = companyRepository.getAll(); List employee = employeeRepository.getAll(); List schedule = scheduleRepository.getAll(); + List actType = actTypeRepository.getAll(); List service = serviceRepository.getAll(); List manipulation = manipulationRepository.getAll(); + List document = documentRepository.getAll(); params.put("company", company); params.put("schedule", schedule); params.put("employee", employee); + params.put("act_type", actType); params.put("service", service); params.put("manipulation", manipulation); + params.put("document", document); return params; } + + @Transactional + @ReadOnly + public Boolean isEmpty() { + return (Integer)entityManager + .createNativeQuery("select count(*)::::int from (select S.id, E.id, C.id from schedule S, employee E, company C limit 1) R;") + .getSingleResult() == 0; + } } diff --git a/src/main/java/gcg/dent/repository/ScheduleRepository.java b/src/main/java/gcg/dent/repository/ScheduleRepository.java index 24d319f..d5c7854 100644 --- a/src/main/java/gcg/dent/repository/ScheduleRepository.java +++ b/src/main/java/gcg/dent/repository/ScheduleRepository.java @@ -19,25 +19,15 @@ public class ScheduleRepository { @ReadOnly public List getAll() { return entityManager - .createQuery("select S from Schedule S order by S.dow", Schedule.class) + .createQuery("select S from Schedule S order by S.dow, S.start", Schedule.class) .getResultList(); } - @Transactional - @ReadOnly - public Boolean isEmpty() { - return entityManager - .createQuery("select S from Schedule S") - .setMaxResults(1) - .getResultList() - .isEmpty(); - } - @Transactional @ReadOnly public List getByDow(Integer dow){ return entityManager - .createQuery("select S from Schedule S where S.dow = :dow") + .createQuery("select S from Schedule S where S.dow = :dow", Schedule.class) .setParameter("dow", dow) .getResultList(); } diff --git a/src/main/java/gcg/dent/repository/ServiceRepository.java b/src/main/java/gcg/dent/repository/ServiceRepository.java index f29ca45..da435d6 100644 --- a/src/main/java/gcg/dent/repository/ServiceRepository.java +++ b/src/main/java/gcg/dent/repository/ServiceRepository.java @@ -18,7 +18,16 @@ public class ServiceRepository { @ReadOnly public List getAll() { return entityManager - .createQuery("select S from Service S", Service.class) + .createQuery("select S from Service S order by S.actType.name, S.name", Service.class) + .getResultList(); + } + + @Transactional + @ReadOnly + public List getByActType(Long actType) { + return entityManager + .createQuery("select S from Service S left join fetch S.manipulations where S.actType.id = (:id) order by S.name", Service.class) + .setParameter("id", actType) .getResultList(); } diff --git a/src/main/java/gcg/dent/repository/SlotRepository.java b/src/main/java/gcg/dent/repository/SlotRepository.java index 07cb905..cce47b6 100644 --- a/src/main/java/gcg/dent/repository/SlotRepository.java +++ b/src/main/java/gcg/dent/repository/SlotRepository.java @@ -22,7 +22,7 @@ public Slot makeSlot(Date date, Time time, Time size) { slot.setDate(date); slot.setTime(time); slot.setSize(size); - slot.setEnabled(true); + slot.setEnabled(false); return slot; } diff --git a/src/main/java/gcg/dent/repository/StatisticsRepository.java b/src/main/java/gcg/dent/repository/StatisticsRepository.java new file mode 100644 index 0000000..4e3448a --- /dev/null +++ b/src/main/java/gcg/dent/repository/StatisticsRepository.java @@ -0,0 +1,7 @@ +package gcg.dent.repository; + +import javax.inject.Singleton; + +@Singleton +public class StatisticsRepository { +} diff --git a/src/main/java/gcg/dent/service/CalendarService.java b/src/main/java/gcg/dent/service/CalendarService.java index f899844..86cca15 100644 --- a/src/main/java/gcg/dent/service/CalendarService.java +++ b/src/main/java/gcg/dent/service/CalendarService.java @@ -83,12 +83,23 @@ public HashMap get(Date date) { Calendar temp = (Calendar) start.clone(); temp.add(Calendar.DATE, dow); String slotDate = String.format("%d-%02d-%02d", temp.get(Calendar.YEAR), temp.get(Calendar.MONTH) + 1, temp.get(Calendar.DATE)); - htmlSlots.append("
"); + htmlSlots.append("
"); timeSlots.forEach(ts -> { - Client c = ts.getClient(); - htmlSlots.append("
" + ObjectUtils.fio(c.getFio()) + "
" + c.getPhone() + "
"); + if(ts.isEnabled()) { + Client c = ts.getClient(); + String fio = c.getPatient() != null ? c.getPatient().getFio() : c.getFio(); + String phone = c.getPatient() != null ? c.getPatient().getPhone() : c.getPhone(); + String note = ts.getNote(); + htmlSlots.append("
" + + "" + ObjectUtils.fio(fio) + + "
" + phone + "" + + "
" + (note == null ? "" : note) + "
"); + } else { + htmlSlots.append("
"); + } }); htmlSlots.append("
"); } diff --git a/src/main/java/gcg/dent/service/ScheduleService.java b/src/main/java/gcg/dent/service/ScheduleService.java index ed75bb4..2cd6b76 100644 --- a/src/main/java/gcg/dent/service/ScheduleService.java +++ b/src/main/java/gcg/dent/service/ScheduleService.java @@ -22,7 +22,7 @@ public boolean isWork(Time time, int dow) { return schedules.stream() .filter(s -> s.getDow() == dow && time.getTime() >= s.getStart().getTime() && - time.getTime() < s.getEnd().getTime()) + time.getTime() < s.getFinish().getTime()) .count() > 0; } @@ -36,9 +36,9 @@ public Time[] findFirstAndLast(int dow) { .get(); Schedule finish = schedules.stream() .filter(t -> t.getDow() == dow) - .max(Comparator.comparingLong(t -> t.getEnd().getTime())) + .max(Comparator.comparingLong(t -> t.getFinish().getTime())) .get(); - return new Time[] { start.getStart(), finish.getEnd() }; + return new Time[] { start.getStart(), finish.getFinish() }; } public Time[] findFirstAndLast() { @@ -50,7 +50,7 @@ public Time[] findFirstAndLast() { .min(Comparator.comparingLong(Date::getTime)) .get(); Time finish = schedules.stream() - .map(Schedule::getEnd) + .map(Schedule::getFinish) .max(Comparator.comparingLong(Date::getTime)) .get(); return new Time[] { start, finish }; diff --git a/src/main/java/gcg/dent/util/ObjectUtils.java b/src/main/java/gcg/dent/util/ObjectUtils.java index a762310..a00cdb1 100644 --- a/src/main/java/gcg/dent/util/ObjectUtils.java +++ b/src/main/java/gcg/dent/util/ObjectUtils.java @@ -1,10 +1,14 @@ package gcg.dent.util; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class ObjectUtils { private static final String[] weekDays = new String[] {"", "вс", "пн", "вт", "ср", "чт", "пт", "сб"}; + public static final String[] weekDaysFull = new String[] {"Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота", "Воскресенье"}; + public static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); + public static final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm"); private ObjectUtils() {} diff --git a/src/main/java/gcg/dent/util/Templates.java b/src/main/java/gcg/dent/util/Templates.java new file mode 100644 index 0000000..12a69db --- /dev/null +++ b/src/main/java/gcg/dent/util/Templates.java @@ -0,0 +1,234 @@ +package gcg.dent.util; + +import com.fasterxml.jackson.databind.JsonNode; +import com.github.jknack.handlebars.Handlebars; +import com.github.jknack.handlebars.TagType; +import com.github.jknack.handlebars.Template; +import gcg.dent.entity.*; +import gcg.dent.repository.*; +import gcg.dent.util.helpers.*; +import gcg.word.JustifyContent; +import gcg.word.Paragraph; +import gcg.word.table.TableColumn; +import gcg.word.table.TableRow; +import gcg.word.util.Rsid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.Transactional; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.*; + +@Singleton +public class Templates { + private static final Logger logger = LoggerFactory.getLogger(Templates.class); + private static Handlebars handlebars = new Handlebars(); + + static { + handlebars.registerHelper("nullable", new NullableHelper()); + handlebars.registerHelper("declension", new DeclensionHelper()); + handlebars.registerHelper("join", new JoinHelper(", ")); + handlebars.registerHelper("sum", new MathHelper(MathHelper.SIGN.PLUS)); + handlebars.registerHelper("mult", new MathHelper(MathHelper.SIGN.MULT)); + handlebars.registerHelper("date", new DateHelper(new SimpleDateFormat("«dd» MMMM yyyy г."))); + handlebars.registerHelper("lower", new ToCaseHelper(ToCaseHelper.CASE.LOWER)); + handlebars.registerHelper("upper", new ToCaseHelper(ToCaseHelper.CASE.UPPER)); + handlebars.registerHelper("in_words", new InWordsHelper()); + handlebars.registerHelper("yesno", new YesNoHelper()); + handlebars.registerHelper("empty", new EmptyHelper()); + } + + @PersistenceContext + private EntityManager entityManager; + + @Inject + CardRepository cardRepository; + + @Inject + CompanyRepository companyRepository; + + @Inject + ContractRepository contractRepository; + + @Inject + EmployeeRepository employeeRepository; + + @Inject + HistoryRepository historyRepository; + + @Inject + PatientRepository patientRepository; + + public String load(Document templateDocument, Map params) { + try { + Template template = handlebars.compileInline(templateDocument.getTemplate()); + List variables = template.collect(TagType.VAR); + variables.addAll(template.collect(TagType.TRIPLE_VAR)); + return template.apply(variablesToParams(variables, params)); + } catch (IOException iex) { + logger.error("Can't compile raw template '{}'", templateDocument.getName(), iex); + throw new RuntimeException(); + } + } + + @Transactional + Map variablesToParams(List vars, Map params) { + Map filledParams = new HashMap<>(); + + Company company = companyRepository.getAll().get(0); + Employee doctor = null; + Patient patient = null; + Card card = null; + Contract contract = null; + History history = null; + Act act = null; + + Double fullSumm = 0.00; + final StringBuilder actServiceTable = new StringBuilder(); + + if (params.get("employee") != null) { + doctor = employeeRepository.findById((Long) params.get("employee")); + } + if (params.get("patient") != null) { + patient = patientRepository.findById((Long) params.get("patient")); + } + if (params.get("card") != null) { + card = cardRepository.findById((Long) params.get("card")); + } + if (params.get("contract") != null) { + contract = contractRepository.findById((Long) params.get("contract")); + fullSumm = (Double) entityManager + .createNativeQuery("select coalesce(sum(s.price * c.amount), 0)::::double precision " + + "from act a " + + "join act_service c on a.id = c.aid " + + "join service s on c.sid = s.id " + + "where a.atid = s.atid and a.did = (:did)") + .setParameter("did", contract.getId()) + .getSingleResult(); + } + if (params.get("history") != null) { + history = historyRepository.findById((Long) params.get("history")); + if (params.get("card") == null) { + card = cardRepository.findById(history.getCard().getId()); + } + patient = patientRepository.findById(card.getPid()); + JsonNode props = history.getProps(); + Iterator dent = props.get("dent").elements(); + dent.forEachRemaining(d -> { + int tr = d.get("tr").asInt(); + int td = d.get("td").asInt(); + String half = d.get("half").asText(); + String value = d.get("value").asText(); + String key = half.substring(0, 1) + (tr > 0 ? ("u" + tr) : ("d" + (-tr))) + td; + filledParams.put(key, value); + }); + filledParams.put("diagnosis", props.get("diagnosis").asText()); + filledParams.put("complaints", props.get("complaints").asText()); + filledParams.put("gepatit", props.get("gepatit").asBoolean()); + filledParams.put("tuber", props.get("tuber").asBoolean()); + filledParams.put("pedi", props.get("pedi").asBoolean()); + filledParams.put("break", props.get("break").asText()); + filledParams.put("manipulation", props.get("manipulation").asText()); + filledParams.put("sick", props.get("sick").asText()); + filledParams.put("visit", props.get("visit").asText()); + filledParams.put("allergy", props.get("allergy").asText()); + filledParams.put("outer", props.get("outer").asText()); + filledParams.put("bite", props.get("bite").asText()); + filledParams.put("mucous", props.get("mucous").asText()); + filledParams.put("lab", props.get("lab").asText()); + } + if (doctor == null && patient != null) { + doctor = (Employee) entityManager + .createNativeQuery("select D.* from employee D " + + "join slot S on S.doc = D.id " + + "left join client C on C.id = S.cid " + + "left join patient P on P.id = C.pid " + + "where P.id = :id " + + "order by S.date desc, S.time desc", Employee.class) + .setParameter("id", patient.getId()) + .setMaxResults(1) + .getSingleResult(); + } + if (params.get("act") != null) { + act = entityManager.find(Act.class, params.get("act")); + fullSumm = (Double) entityManager + .createNativeQuery("select sum(s.price * c.amount)::::double precision " + + "from act a " + + "join act_service c on a.id = c.aid " + + "join service s on c.sid = s.id " + + "where a.atid = s.atid and a.id = (:aid)") + .setParameter("aid", act.getId()) + .getSingleResult(); + + List tblServiceRows = new ArrayList<>(); + List tblManipulationRows = new ArrayList<>(); + final Rsid rsid1 = new Rsid("00E62517", "0064090B", "00E62517", "00E62517", ""); + final Rsid rsid2 = new Rsid("0064090B", "0064090B", "", "", "00E62517"); + final Rsid rsid3 = new Rsid("0064090B", "0064090B", "", "", "0064090B"); + act.getActServices().forEach(actService -> { + Service service = actService.getService(); + String name = service.getName(); + final Integer amount = actService.getAmount(); + Double price = service.getPrice(); + Double summ = amount * price; + TableColumn tcName = new TableColumn(new Paragraph(rsid1, "Times New Roman", 24, false, JustifyContent.LEFT, name), 4957); + TableColumn tcAmount = new TableColumn(new Paragraph(rsid1, "Times New Roman", 24, false, JustifyContent.LEFT, String.format("%d", amount)), 1701); + TableColumn tcPrice = new TableColumn(new Paragraph(rsid1, "Times New Roman", 24, false, JustifyContent.LEFT, String.format("%.2f", price)), 1701); + TableColumn tcSumm = new TableColumn(new Paragraph(rsid1, "Times New Roman", 24, false, JustifyContent.LEFT, String.format("%.2f", summ)), 1553); + tblServiceRows.add(new TableRow(rsid2, Arrays.asList(tcName, tcAmount, tcPrice, tcSumm))); + + service.getManipulations().forEach(manipulation -> { + String mName = manipulation.getName(); + String mDate = ObjectUtils.dateFormat.format(actService.getDate()); + TableColumn tcMDate = new TableColumn(new Paragraph(rsid1, "Times New Roman", 24, false, JustifyContent.LEFT, mDate), 2143); + TableColumn tcMName = new TableColumn(new Paragraph(rsid1, "Times New Roman", 24, false, JustifyContent.LEFT, mName), 7769); + + tblManipulationRows.add(new TableRow(rsid3, Arrays.asList(tcMDate, tcMName))); + }); + }); + + filledParams.put("tblServiceRows", tblServiceRows); + filledParams.put("tblManipulationRows", tblManipulationRows); + } + + if (vars.contains("act_service_table")) { + List rows = entityManager + .createNativeQuery("select T.name, string_agg(S.name||' - '||A_S.amount||'шт', ', ') from act A " + + "join act_type t on A.atid = t.id " + + "left join act_service A_S on A.id = A_S.aid " + + "left join service s on A_S.sid = s.id " + + "where A.did = (:did) " + + "group by A.id, T.name;") + .setParameter("did", contract.getId()) + .getResultList(); + final String tblHeader = ""; + actServiceTable.append(tblHeader); + rows.forEach(r -> { + String tblRow = "" + + "" + r[0].toString() + "" + + "" + r[1].toString() + ""; + actServiceTable.append(tblRow); + }); + actServiceTable.append(""); + } + + filledParams.put("company", company); + filledParams.put("patient", patient); + filledParams.put("employee", doctor); + filledParams.put("card", card); + filledParams.put("contract", contract); + filledParams.put("history", history); + filledParams.put("act", act); + + filledParams.put("full_summ", String.format("%.2f", fullSumm)); + filledParams.put("act_service_table", actServiceTable.toString()); + + logger.info("VARS={}, PARAMS={}", vars, params); + return filledParams; + } +} diff --git a/src/main/java/gcg/dent/util/helpers/DateHelper.java b/src/main/java/gcg/dent/util/helpers/DateHelper.java new file mode 100644 index 0000000..719c2f9 --- /dev/null +++ b/src/main/java/gcg/dent/util/helpers/DateHelper.java @@ -0,0 +1,30 @@ +package gcg.dent.util.helpers; + +import com.github.jknack.handlebars.Helper; +import com.github.jknack.handlebars.Options; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class DateHelper implements Helper { + private static final SimpleDateFormat standartFormat = new SimpleDateFormat("dd.MM.yyyy"); + private SimpleDateFormat format; + + public DateHelper(SimpleDateFormat format) { + this.format = format; + } + + @Override + public Object apply(Object context, Options options) { + Date date = new Date(); + if (context instanceof Date) { + date = (Date) context; + } else if (context instanceof String) { + try { + date = standartFormat.parse(context.toString()); + } catch (Exception ex) { + } + } + return format.format(date); + } +} diff --git a/src/main/java/gcg/dent/util/helpers/DeclensionHelper.java b/src/main/java/gcg/dent/util/helpers/DeclensionHelper.java new file mode 100644 index 0000000..1343c74 --- /dev/null +++ b/src/main/java/gcg/dent/util/helpers/DeclensionHelper.java @@ -0,0 +1,72 @@ +package gcg.dent.util.helpers; + +import com.github.jknack.handlebars.Helper; +import com.github.jknack.handlebars.Options; + +import java.util.Arrays; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class DeclensionHelper implements Helper { + + @Override + public Object apply(String declension, Options options) { + String fio = options.param(0); + Stream parts = Arrays.stream(fio.split(" ")); + switch(declension.toLowerCase()) { + case "genitive": + parts = parts.map(p -> p = genitive(p));//кого? чего? + break; + case "dative": + parts = parts.map(p -> p = dative(p));//кому? чему? + break; + case "accusative": + parts = parts.map(p -> p = accusative(p));//кого? что? + break; + case "instrumental": + parts = parts.map(p -> p = instrumental(p));//кем? чем? + break; + case "prepositional": + parts = parts.map(p -> p = prepositional(p));//о ком? о чём? + default: + } + return parts.collect(Collectors.joining(" ")); + } + + private static String genitive(String part) { + if(part.endsWith("в") || part.endsWith("ч") || part.endsWith("н") || part.endsWith("р")) { + part += "а"; + } else if(part.endsWith("ва")) { + part = part.substring(0, part.length() - 1) + "ой"; + } else if(part.endsWith("на") || part.endsWith("ра")) { + part = part.substring(0, part.length() - 1) + "ы"; + } else if(part.endsWith("я")) { + part = part.substring(0, part.length() - 1) + "и"; + } else if(part.endsWith("й")) { + part = part.substring(0, part.length() - 1) + "я"; + } else if(part.endsWith("о")) { + //do nothing + } else if(part.endsWith("ел")) { + part = part.substring(0, part.length() - 1) + "ла"; + } else { + part += "_"; + } + return part; + } + + private static String dative(String part) { + return part; + } + + private static String accusative(String part) { + return part; + } + + private static String instrumental(String part) { + return part; + } + + private static String prepositional(String part) { + return part; + } +} diff --git a/src/main/java/gcg/dent/util/helpers/EmptyHelper.java b/src/main/java/gcg/dent/util/helpers/EmptyHelper.java new file mode 100644 index 0000000..08e8f63 --- /dev/null +++ b/src/main/java/gcg/dent/util/helpers/EmptyHelper.java @@ -0,0 +1,12 @@ +package gcg.dent.util.helpers; + +import com.github.jknack.handlebars.Helper; +import com.github.jknack.handlebars.Options; + +public class EmptyHelper implements Helper { + + @Override + public Object apply(Object context, Options options) { + return context == null ? "" : context; + } +} diff --git a/src/main/java/gcg/dent/util/helpers/InWordsHelper.java b/src/main/java/gcg/dent/util/helpers/InWordsHelper.java new file mode 100644 index 0000000..a106a1e --- /dev/null +++ b/src/main/java/gcg/dent/util/helpers/InWordsHelper.java @@ -0,0 +1,44 @@ +package gcg.dent.util.helpers; + +import com.github.jknack.handlebars.Helper; +import com.github.jknack.handlebars.Options; + +import java.io.IOException; + +public class InWordsHelper implements Helper { + @Override + public Object apply(Object context, Options options) throws IOException { + try { + Double money = Double.parseDouble(context.toString()); + return money.intValue() > 0 ? money2str(money.intValue(), "") : "ноль"; + } catch (Exception ex) { + return "не указано"; + } + } + + private static final String[] Low = new String[]{"", "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять", "десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать", "пятнадцать", "шестнадцать", "семьнадцать", "восемьнадцать", "девятнадцать"}; + private static final String[] Ts = new String[]{"", "десять", "двадцать", "тридцать", "сорок", "пятьдесят", "шестьдесят", "семьдесят", "восемьдесят", "девяносто"}; + private static final String[] Hs = new String[]{"", "сто", "двести", "триста", "четыреста", "пятьсот", "шестьсот", "семьсот", "восемьсот", "девятьсот"}; + + private String money2str(int money, String word) { + if (money < 20) { + word += Low[money]; + } else if (money < 100) { + word += Ts[(int) (Math.floor(money / 10.0))] + " " + money2str(money - (int) (Math.floor(money / 10.0)) * 10, word); + } else if (money < 1000) { + word += Hs[(int) (Math.floor(money / 100.0))] + " " + money2str(money - (int) (Math.floor(money / 100.0)) * 100, word); + } else if (money < 1000000) { + int ths = (int) (Math.floor(money / 1000.0)); + String e = ((ths > 4 && ths < 20) || (ths - Math.floor(ths / 10.0) * 10 < 1)) ? "" : (ths - Math.floor(ths / 10.0) * 10 < 2 ? "а" : (ths - Math.floor(ths / 10.0) * 10 < 5 ? "и" : "")); + word += money2str(ths, "").replace("один", "одна").replace("два", "две").replace("дведцать", "двадцать") + + " тысяч" + e + " " + money2str(money - (int) (Math.floor(money / 1000.0)) * 1000, word); + } else if (money < 1000000000) { + int ths = (int) (Math.floor(money / 1000000.0)); + String e = ((ths - Math.floor(ths / 10.0) * 10 == 1) ? "" : (ths - Math.floor(ths / 10.0) * 10 < 5 ? "а" : "ов")); + word += money2str(ths, "") + " миллион" + e + " " + money2str(money - (int) (Math.floor(money / 1000000.0)) * 1000000, word); + } else { + word = String.valueOf(money); + } + return word; + } +} \ No newline at end of file diff --git a/src/main/java/gcg/dent/util/helpers/JoinHelper.java b/src/main/java/gcg/dent/util/helpers/JoinHelper.java new file mode 100644 index 0000000..bb46e7a --- /dev/null +++ b/src/main/java/gcg/dent/util/helpers/JoinHelper.java @@ -0,0 +1,47 @@ +package gcg.dent.util.helpers; + +import com.github.jknack.handlebars.Helper; +import com.github.jknack.handlebars.Options; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +public class JoinHelper implements Helper { + private String separator; + + public JoinHelper(String separator) { + this.separator = separator; + } + + @Override + public String apply(List elements, Options options) { + String field = options.param(0); + List values = new ArrayList<>(); + if(field != null) { + try { + String[] fields = field.split("[.]"); + for(int e = 0; e < elements.size(); e++) { + Object element = elements.get(e); + for (int f = 0; f < fields.length; f++) { + Field subField = element.getClass().getDeclaredField(fields[f]); + boolean isAccessible = subField.isAccessible(); + if (!isAccessible) { + subField.setAccessible(true); + } + + element = subField.get(element); + + if (!isAccessible) { + subField.setAccessible(false); + } + } + values.add(element.toString()); + } + } catch(Exception ex) { + ex.printStackTrace(); + } + } + return String.join(separator, values); + } +} diff --git a/src/main/java/gcg/dent/util/helpers/MathHelper.java b/src/main/java/gcg/dent/util/helpers/MathHelper.java new file mode 100644 index 0000000..1369a39 --- /dev/null +++ b/src/main/java/gcg/dent/util/helpers/MathHelper.java @@ -0,0 +1,62 @@ +package gcg.dent.util.helpers; + +import com.github.jknack.handlebars.Helper; +import com.github.jknack.handlebars.Options; + +public class MathHelper implements Helper { + private SIGN action; + + public MathHelper(SIGN action) { + this.action = action; + } + + @Override + public Object apply(Object context, Options options) { + if(context instanceof Double + || options.param(0) instanceof Double) { + Double param1 = Double.valueOf(context.toString()); + Double param2 = Double.valueOf(options.param(0).toString()); + switch(action) { + case PLUS: + default: + return param1 + param2; + case MINUS: + return param1 - param2; + case MULT: + return param1 * param2; + case DIV: + return param1 / param2; + case POW: + return Math.pow(param1, param2); + } + } else if(context instanceof Long + || options.param(0) instanceof Long + || context instanceof Integer + || options.param(0) instanceof Integer) { + Long param1 = Long.valueOf(context.toString()); + Long param2 = Long.valueOf(options.param(0).toString()); + switch(action) { + case PLUS: + default: + return param1 + param2; + case MINUS: + return param1 - param2; + case MULT: + return param1 * param2; + case DIV: + return param1 / param2; + case POW: + return Math.pow(param1, param2); + } + } + return null; + } + + public enum SIGN { + PLUS, + MINUS, + MULT, + DIV, + POW + } +} diff --git a/src/main/java/gcg/dent/util/helpers/NullableHelper.java b/src/main/java/gcg/dent/util/helpers/NullableHelper.java new file mode 100644 index 0000000..b731465 --- /dev/null +++ b/src/main/java/gcg/dent/util/helpers/NullableHelper.java @@ -0,0 +1,13 @@ +package gcg.dent.util.helpers; + +import com.github.jknack.handlebars.Helper; +import com.github.jknack.handlebars.Options; + +import java.io.IOException; + +public class NullableHelper implements Helper { + @Override + public Object apply(Object context, Options options) throws IOException { + return (context == null ? options.param(0, "не указано") : context); + } +} diff --git a/src/main/java/gcg/dent/util/helpers/ToCaseHelper.java b/src/main/java/gcg/dent/util/helpers/ToCaseHelper.java new file mode 100644 index 0000000..ec5e931 --- /dev/null +++ b/src/main/java/gcg/dent/util/helpers/ToCaseHelper.java @@ -0,0 +1,29 @@ +package gcg.dent.util.helpers; + +import com.github.jknack.handlebars.Helper; +import com.github.jknack.handlebars.Options; + +import java.io.IOException; + +public class ToCaseHelper implements Helper { + private CASE toCase; + + public ToCaseHelper(CASE toCase) { + this.toCase = toCase; + } + + @Override + public Object apply(String context, Options options) throws IOException { + if(toCase == CASE.LOWER) { + return context.toLowerCase(); + } else if(toCase == CASE.UPPER) { + return context.toUpperCase(); + } + return context; + } + + public enum CASE { + LOWER, + UPPER + } +} diff --git a/src/main/java/gcg/dent/util/helpers/YesNoHelper.java b/src/main/java/gcg/dent/util/helpers/YesNoHelper.java new file mode 100644 index 0000000..9d481d3 --- /dev/null +++ b/src/main/java/gcg/dent/util/helpers/YesNoHelper.java @@ -0,0 +1,15 @@ +package gcg.dent.util.helpers; + +import com.github.jknack.handlebars.Helper; +import com.github.jknack.handlebars.Options; + +public class YesNoHelper implements Helper { + + @Override + public Object apply(Object context, Options options) { + if (context instanceof Boolean) { + return (boolean)context ? "Да" :"Нет"; + } + return "Нет"; + } +} diff --git a/src/main/java/gcg/word/Font.java b/src/main/java/gcg/word/Font.java new file mode 100644 index 0000000..44152d4 --- /dev/null +++ b/src/main/java/gcg/word/Font.java @@ -0,0 +1,14 @@ +package gcg.word; + +public class Font { + private String value; + + public Font(String value) { + this.value = value; + } + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/gcg/word/JustifyContent.java b/src/main/java/gcg/word/JustifyContent.java new file mode 100644 index 0000000..fbfc700 --- /dev/null +++ b/src/main/java/gcg/word/JustifyContent.java @@ -0,0 +1,19 @@ +package gcg.word; + +public enum JustifyContent { + CENTER("center"), + BOTH("both"), + RIGHT("right"), + LEFT("left") + ; + private String value; + + JustifyContent(String value) { + this.value = value; + } + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/gcg/word/Paragraph.java b/src/main/java/gcg/word/Paragraph.java new file mode 100644 index 0000000..7afcd8c --- /dev/null +++ b/src/main/java/gcg/word/Paragraph.java @@ -0,0 +1,32 @@ +package gcg.word; + +import gcg.word.util.Rsid; + +public class Paragraph { + private Rsid rsid; + + private gcg.word.properties.Paragraph pPr; + private Row r; + + public Paragraph(Rsid rsid, String fontName, int fontSize, boolean bold, JustifyContent justify, String text) { + this.rsid = rsid; + + pPr = new gcg.word.properties.Paragraph( + new Spacing(0, fontSize * 10, "auto"),//FIXME + justify, + new gcg.word.properties.Row(fontName, fontSize, bold)); + r = new Row(rsid.rsidRPr(), new gcg.word.properties.Row(fontName, fontSize, bold), text); + } + + public Row getRow() { + return r; + } + + @Override + public String toString() { + return "" + + pPr + + r + + ""; + } +} diff --git a/src/main/java/gcg/word/Row.java b/src/main/java/gcg/word/Row.java new file mode 100644 index 0000000..194b57d --- /dev/null +++ b/src/main/java/gcg/word/Row.java @@ -0,0 +1,21 @@ +package gcg.word; + +public class Row { + private String rsidRPr; + private gcg.word.properties.Row rPr; + private Text t; + + public Row(String rsidRPr, gcg.word.properties.Row rPr, String text) { + this.rsidRPr = rsidRPr; + this.rPr = rPr; + this.t = new Text(text); + } + + @Override + public String toString() { + return "" + + rPr + + t + + ""; + } +} diff --git a/src/main/java/gcg/word/Size.java b/src/main/java/gcg/word/Size.java new file mode 100644 index 0000000..e308851 --- /dev/null +++ b/src/main/java/gcg/word/Size.java @@ -0,0 +1,14 @@ +package gcg.word; + +public class Size { + protected int value; + + public Size(int value) { + this.value = value; + } + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/gcg/word/SizeCS.java b/src/main/java/gcg/word/SizeCS.java new file mode 100644 index 0000000..bba8641 --- /dev/null +++ b/src/main/java/gcg/word/SizeCS.java @@ -0,0 +1,13 @@ +package gcg.word; + +public class SizeCS extends Size { + + public SizeCS(int value) { + super(value); + } + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/gcg/word/Spacing.java b/src/main/java/gcg/word/Spacing.java new file mode 100644 index 0000000..0f68ae2 --- /dev/null +++ b/src/main/java/gcg/word/Spacing.java @@ -0,0 +1,22 @@ +package gcg.word; + +import java.util.Optional; + +public class Spacing { + private int after; + private int line; + private String line_rule; + + public Spacing(int after, int line, String line_rule) { + this.after = after; + this.line = line; + this.line_rule = line_rule; + } + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/gcg/word/Text.java b/src/main/java/gcg/word/Text.java new file mode 100644 index 0000000..6cf9903 --- /dev/null +++ b/src/main/java/gcg/word/Text.java @@ -0,0 +1,14 @@ +package gcg.word; + +public class Text { + private String value; + + public Text(String value) { + this.value = value; + } + + @Override + public String toString() { + return "" + value + ""; + } +} diff --git a/src/main/java/gcg/word/font/Row.java b/src/main/java/gcg/word/font/Row.java new file mode 100644 index 0000000..7670125 --- /dev/null +++ b/src/main/java/gcg/word/font/Row.java @@ -0,0 +1,16 @@ +package gcg.word.font; + +public class Row { + private String ascii; + private String h_ansi;//h-ansi + + public Row(String ascii) { + this.ascii = ascii; + this.h_ansi = ascii;//FIXME??? + } + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/gcg/word/properties/Paragraph.java b/src/main/java/gcg/word/properties/Paragraph.java new file mode 100644 index 0000000..f6d41c8 --- /dev/null +++ b/src/main/java/gcg/word/properties/Paragraph.java @@ -0,0 +1,25 @@ +package gcg.word.properties; + +import gcg.word.JustifyContent; +import gcg.word.Spacing; + +public class Paragraph { + private Spacing spacing; + private JustifyContent jc; + private Row rPr; + + public Paragraph(Spacing spacing, JustifyContent jc, Row rPr) { + this.spacing = spacing; + this.jc = jc; + this.rPr = rPr; + } + + @Override + public String toString() { + return "" + + spacing + + jc + + rPr + + ""; + } +} diff --git a/src/main/java/gcg/word/properties/Row.java b/src/main/java/gcg/word/properties/Row.java new file mode 100644 index 0000000..2c523c9 --- /dev/null +++ b/src/main/java/gcg/word/properties/Row.java @@ -0,0 +1,32 @@ +package gcg.word.properties; + +import gcg.word.Font; +import gcg.word.Size; +import gcg.word.SizeCS; + +public class Row { + private gcg.word.font.Row rFonts; + private Font font; + private boolean bold; + private Size sz; + private SizeCS sz_cs; + + public Row(String fontName, int size, boolean bold) { + rFonts = new gcg.word.font.Row(fontName); + font = new Font(fontName); + this.bold = bold; + sz = new Size(size); + sz_cs = new SizeCS(size); + } + + @Override + public String toString() { + return "" + + rFonts + + font + + (bold ? "" : "") + + sz + + sz_cs + + ""; + } +} diff --git a/src/main/java/gcg/word/properties/Table.java b/src/main/java/gcg/word/properties/Table.java new file mode 100644 index 0000000..76dfe7f --- /dev/null +++ b/src/main/java/gcg/word/properties/Table.java @@ -0,0 +1,38 @@ +package gcg.word.properties; + +import gcg.word.table.TableLook; +import gcg.word.table.border.Border; +import gcg.word.table.border.Type; +import gcg.word.table.tblW; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class Table { + private tblW width = new tblW(); + private TableLook tblLook = new TableLook("04A0"); + private List tblBorders = new ArrayList<>(); + + public Table() {//TODO + tblBorders.add(new Border(Type.TOP)); + tblBorders.add(new Border(Type.LEFT)); + tblBorders.add(new Border(Type.BOTTOM)); + tblBorders.add(new Border(Type.RIGHT)); + tblBorders.add(new Border(Type.INSIDE_H)); + tblBorders.add(new Border(Type.INSIDE_V)); + } + + @Override + public String toString() { + return "" + + width + + "" + + tblBorders.stream() + .map(Border::toString) + .collect(Collectors.joining()) + + "" + + tblLook + + ""; + } +} diff --git a/src/main/java/gcg/word/properties/TableColumn.java b/src/main/java/gcg/word/properties/TableColumn.java new file mode 100644 index 0000000..420f38a --- /dev/null +++ b/src/main/java/gcg/word/properties/TableColumn.java @@ -0,0 +1,23 @@ +package gcg.word.properties; + +import gcg.word.table.TableColumnWidth; + +public class TableColumn { + private TableColumnWidth tcW; + + public TableColumn(int width) { + tcW = new TableColumnWidth(width, "dxa"); + } + + public int getWidth() { + return tcW.getWidth(); + } + + @Override + public String toString() { + return "" + + tcW + + "" +//TODO: create class + ""; + } +} diff --git a/src/main/java/gcg/word/table/TableColumn.java b/src/main/java/gcg/word/table/TableColumn.java new file mode 100644 index 0000000..28e42c5 --- /dev/null +++ b/src/main/java/gcg/word/table/TableColumn.java @@ -0,0 +1,29 @@ +package gcg.word.table; + +import gcg.word.Paragraph; + +public class TableColumn { + private gcg.word.properties.TableColumn tcPr; + private Paragraph p; + + public TableColumn(Paragraph p, int width) { + this.tcPr = new gcg.word.properties.TableColumn(width); + this.p = p; + } + + public Paragraph getParagraph() { + return p; + } + + public int getWidth() { + return tcPr.getWidth(); + } + + @Override + public String toString() { + return "" + + tcPr + + p + + ""; + } +} diff --git a/src/main/java/gcg/word/table/TableColumnWidth.java b/src/main/java/gcg/word/table/TableColumnWidth.java new file mode 100644 index 0000000..97c90f9 --- /dev/null +++ b/src/main/java/gcg/word/table/TableColumnWidth.java @@ -0,0 +1,20 @@ +package gcg.word.table; + +public class TableColumnWidth { + private int width; + private String type; + + public TableColumnWidth(int width, String type) { + this.width = width; + this.type = type; + } + + public int getWidth() { + return width; + } + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/gcg/word/table/TableLook.java b/src/main/java/gcg/word/table/TableLook.java new file mode 100644 index 0000000..1cb95f2 --- /dev/null +++ b/src/main/java/gcg/word/table/TableLook.java @@ -0,0 +1,14 @@ +package gcg.word.table; + +public class TableLook { + private String value; + + public TableLook(String value) { + this.value = value; + } + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/gcg/word/table/TableRow.java b/src/main/java/gcg/word/table/TableRow.java new file mode 100644 index 0000000..e54e159 --- /dev/null +++ b/src/main/java/gcg/word/table/TableRow.java @@ -0,0 +1,29 @@ +package gcg.word.table; + +import gcg.word.util.Rsid; + +import java.util.List; +import java.util.stream.Collectors; + +public class TableRow { + private Rsid rsid; + private List tc; + + public TableRow(Rsid rsid, List tc) { + this.rsid = rsid; + this.tc = tc; + } + + public List getColumns() { + return tc; + } + + @Override + public String toString() { + return "" + + tc.stream() + .map(TableColumn::toString) + .collect(Collectors.joining()) + + ""; + } +} diff --git a/src/main/java/gcg/word/table/border/Border.java b/src/main/java/gcg/word/table/border/Border.java new file mode 100644 index 0000000..14d88a9 --- /dev/null +++ b/src/main/java/gcg/word/table/border/Border.java @@ -0,0 +1,25 @@ +package gcg.word.table.border; + +public class Border {//FIXME + private Type type; + public String val = "single"; + public int sz = 4; + public int bdrwidth = 10; + public int space = 0; + public String color = "auto"; + + public Border(Type type) { + this.type = type; + } + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/gcg/word/table/border/Type.java b/src/main/java/gcg/word/table/border/Type.java new file mode 100644 index 0000000..8626def --- /dev/null +++ b/src/main/java/gcg/word/table/border/Type.java @@ -0,0 +1,21 @@ +package gcg.word.table.border; + +public enum Type { + TOP("top"), + LEFT("left"), + BOTTOM("bottom"), + RIGHT("right"), + INSIDE_H("insideH"), + INSIDE_V("insideV") + ; + + private String type; + Type(String type) { + this.type = type; + } + + @Override + public String toString() { + return type; + } +} diff --git a/src/main/java/gcg/word/table/grid/GridColumn.java b/src/main/java/gcg/word/table/grid/GridColumn.java new file mode 100644 index 0000000..24b8dda --- /dev/null +++ b/src/main/java/gcg/word/table/grid/GridColumn.java @@ -0,0 +1,14 @@ +package gcg.word.table.grid; + +public class GridColumn { + private int width; + + public GridColumn(int width) { + this.width = width; + } + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/gcg/word/table/grid/TableGrid.java b/src/main/java/gcg/word/table/grid/TableGrid.java new file mode 100644 index 0000000..f798476 --- /dev/null +++ b/src/main/java/gcg/word/table/grid/TableGrid.java @@ -0,0 +1,25 @@ +package gcg.word.table.grid; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class TableGrid { + private List columns; + + public TableGrid(List width) { + columns = new ArrayList<>(); + for(Integer w : width) { + columns.add(new GridColumn(w.intValue())); + } + } + + @Override + public String toString() { + return "" + + columns.stream() + .map(GridColumn::toString) + .collect(Collectors.joining()) + + ""; + } +} diff --git a/src/main/java/gcg/word/table/tblW.java b/src/main/java/gcg/word/table/tblW.java new file mode 100644 index 0000000..6f47eb0 --- /dev/null +++ b/src/main/java/gcg/word/table/tblW.java @@ -0,0 +1,11 @@ +package gcg.word.table; + +public class tblW { + private int w = 0; + private String type = "auto"; + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/gcg/word/util/Rsid.java b/src/main/java/gcg/word/util/Rsid.java new file mode 100644 index 0000000..5ed9a25 --- /dev/null +++ b/src/main/java/gcg/word/util/Rsid.java @@ -0,0 +1,37 @@ +package gcg.word.util; + +public class Rsid { + private String R; + private String RPr; + private String RDefault; + private String P; + private String Tr; + + public Rsid(String R, String RPr, String RDefault, String P, String Tr) { + this.R = R; + this.RPr = RPr; + this.RDefault = RDefault; + this.P = P; + this.Tr = Tr; + } + + public String rsidR() { + return R; + } + + public String rsidRPr() { + return RPr; + } + + public String rsidRDefault() { + return RDefault; + } + + public String rsidP() { + return P; + } + + public String rsidTr() { + return Tr; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d936425..c570cd4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -19,7 +19,7 @@ micronaut: executors: io: type: fixed - nThreads: 75 + nThreads: 16 # scheduled: # type: scheduled # core-pool-size: 30 @@ -46,4 +46,5 @@ jpa: enable_lazy_load_no_trans: true hbm2ddl: auto: none - show_sql: true \ No newline at end of file + show_sql: true +#env PGPASSWORD="dent" pg_dump -h localhost -p 5432 -U dent -v -b -Fp dent > dent_full.sql \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 1b4dc7f..ad37a45 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -1,6 +1,7 @@ + false @@ -9,7 +10,7 @@ - dent + ${APP_NAME} diff --git a/src/main/resources/views/calendar.hbs b/src/main/resources/views/calendar.hbs index 51cf975..822c46c 100644 --- a/src/main/resources/views/calendar.hbs +++ b/src/main/resources/views/calendar.hbs @@ -5,34 +5,31 @@ - - + + - +