Skip to content

Commit

Permalink
Merge pull request #58 from b123400/prescription
Browse files Browse the repository at this point in the history
Rezepte implementieren (Part 1)
  • Loading branch information
zdavatz committed Apr 12, 2024
2 parents 53f12a7 + e4e0809 commit 7fcc144
Show file tree
Hide file tree
Showing 15 changed files with 1,075 additions and 61 deletions.
3 changes: 3 additions & 0 deletions .jshintrc
@@ -0,0 +1,3 @@
{
"esversion":6
}
547 changes: 547 additions & 0 deletions app/assets/javascripts/amiko.prescriptions.js

Large diffs are not rendered by default.

79 changes: 71 additions & 8 deletions app/assets/javascripts/amiko.searchdb.coffee
Expand Up @@ -5,6 +5,7 @@ $ ->
SearchState =
Compendium: 1
Interactions: 2
Prescriptions: 3

SearchType =
Title: 1
Expand Down Expand Up @@ -89,8 +90,11 @@ $ ->
else if search_state == SearchState.Interactions
$('#interactions-button').toggleClass 'nav-button-active'
$('#fulltext-button').disabled = 'disabled'
else if search_state == SearchState.Prescriptions
$('#prescriptions-button').toggleClass 'nav-button-active'
$('#fulltext-button').disabled = 'disabled'
else
search_state = 1 # default search state is 'compendium'
search_state = SearchState.Compendium # default search state is 'compendium'
$('#compendium-button').toggleClass 'nav-button-active'
localStorage.setItem 'search-state', search_state

Expand Down Expand Up @@ -143,6 +147,44 @@ $ ->

typeaheadCtrl = $('#input-form .twitter-typeahead')

packInfoDataForPrescriptionBasket = (data, packinfo) ->
JSON.stringify({
eancode: data.eancode,
package: packinfo.title,
title: data.title
author: data.author,
regnrs: data.regnrs,
atccode: data.atccode
})

atcCodeElement = (data)->
if !data.atccode
return ""
atcCodeStr = ""
atcTitleStr = ""
mCode = data.atccode.split(';')
if mCode.length > 1
atcCodeStr = mCode[0]
atcTitleStr = mCode[1]

atcCodeStr = atcCodeStr.split(',').map((code)-> "<a class='atc-code' href='/?atc_query=#{code}'>#{code}</a>")

if data.atcclass
mClass = data.atcclass.split(';')
if mClass.length == 1
atcCodeStr = "<p>" + atcCodeStr + " - " + atcTitleStr + "</p><p>" + mClass[0] + "</p>"
else if mClass.length == 2 # *** Ver.<1.2.4
atcCodeStr = "<p>" + atcCodeStr + " - " + atcTitleStr + "</p><p>" + mClass[1] + "</p>"
else if mClass.length == 3 # *** Ver. 1.2.4 and above
atcClassL4AndL5 = mClass[2].split('#')
atcClassStr = ""
if atcClassL4AndL5.length
atcClassStr = atcClassL4AndL5[atcClassL4AndL5.length - 1];
atcCodeStr = "<p>" + atcCodeStr + " - " + atcTitleStr + "</p><p>" + atcClassStr + "</p><p>" + mClass[1] + "</p>"
else
atcCodeStr = "<p>" + atcCodeStr + " - " + atcTitleStr + "</p><p>k.A.</p>";
return atcCodeStr

typeaheadCtrl.typeahead
menu: $('#special-dropdown')
hint: false
Expand All @@ -156,28 +198,33 @@ $ ->
source: articles.ttAdapter()
templates:
suggestion: (data) ->
console.log 'data', data
if search_type == SearchType.Title
packsStr = (packinfo)->
"<p class='article-packinfo' style='color:#{packinfo.color};' data-prescription='#{packInfoDataForPrescriptionBasket(data, packinfo)}'>
#{packinfo.title}
</p>"
"<div style='display:table;vertical-align:middle;'>\
<p style='color:var(--text-color-light);font-size:1.0em;'><b>#{data.title}</b></p>\
<span style='font-size:0.85em;'>#{data.packinfo}</span></div>"
<span style='font-size:0.85em;'>#{data.packinfos.map(packsStr).join('')}</span></div>"
else if search_type == SearchType.Owner
"<div style='display:table;vertical-align:middle;'>\
"<div style='display:table;vertical-align:middle;' class='typeahead-suggestion-wrapper'>\
<p style='color:var(--text-color-light);font-size:1.0em;'><b>#{data.title}</b></p>\
<span style='color:#8888cc;font-size:1.0em;'><p>#{data.author}</p></span></div>"
else if search_type == SearchType.Atc
"<div style='display:table;vertical-align:middle;'>\
"<div style='display:table;vertical-align:middle;' class='typeahead-suggestion-wrapper'>\
<p style='color:var(--text-color-light);font-size:1.0em;'><b>#{data.title}</b></p>\
<span style='color:gray;font-size:0.85em;'>#{data.atccode}</span></div>"
<span style='color:gray;font-size:0.85em;'>#{atcCodeElement(data)}</span></div>"
else if search_type == SearchType.Regnr
"<div style='display:table;vertical-align:middle;'>\
"<div style='display:table;vertical-align:middle;' class='typeahead-suggestion-wrapper'>\
<p style='color:var(--text-color-light);font-size:1.0em;'><b>#{data.title}</b></p>\
<span style='color:#8888cc;font-size:1.0em;'><p>#{data.regnrs}</p></span></div>"
else if search_type == SearchType.Therapie
"<div style='display:table;vertical-align:middle;'>\
"<div style='display:table;vertical-align:middle;' class='typeahead-suggestion-wrapper'>\
<p style='color:var(--text-color-light);font-size:1.0em;'><b>#{data.title}</b></p>\
<span style='color:gray;font-size:0.85em;'>#{data.therapy}</span></div>"
else if search_type == SearchType.FullText
"<div style='display:table;vertical-align:middle;'>\
"<div style='display:table;vertical-align:middle;' class='typeahead-suggestion-wrapper'>\
<p style='color:var(--text-color-light);font-size:1.0em;'><b>#{data.title}</b></p>"

typeaheadCtrl.on 'typeahead:asyncrequest', (event, selection) ->
Expand All @@ -191,6 +238,11 @@ $ ->
$('.atc-code').on 'click', (e)->
e.stopPropagation()

$('p.article-packinfo').on 'click', (e) ->
if !document.URL.endsWith('/prescriptions')
$('button.state-button.--prescription').addClass('shake')
setTimeout((()-> $('button.state-button.--prescription').removeClass('shake')), 1000)

typeaheadCtrl.on 'typeahead:change', (event, selection) ->
typed_input = $('.twitter-typeahead').typeahead('val')

Expand All @@ -201,6 +253,9 @@ $ ->

# Retrieves the fachinfo, the URL should be of the form /fi/gtin/
typeaheadCtrl.on 'typeahead:selected', (event, selection) ->
if window.event.target.classList.contains('article-packinfo')
# Clicking on packinfo triggers prescription basket
return
if search_state == SearchState.Compendium
if search_type == SearchType.FullText
# FULL TEXT search
Expand Down Expand Up @@ -308,6 +363,14 @@ $ ->
.fail (jqHXR, textStatus) ->
alert('ajax error')

$('#prescriptions-button').on 'click', ->
$(this).toggleClass 'nav-button-active'
# disable full text search button
disableButton SearchType.FullText
# set search state
setSearchUIState(SearchState.Prescriptions)
window.location.assign '/prescriptions'

# Detect click on search buttons
setSearchType = (type) ->
disableButton(search_type)
Expand Down
16 changes: 16 additions & 0 deletions app/controllers/MainController.java
Expand Up @@ -99,10 +99,19 @@ Boolean getShowInteractions() {
}
}

Boolean getShowPrescriptions() {
try {
return configuration.getBoolean("feature.prescriptions");
} catch (com.typesafe.config.ConfigException.Missing e_) {
return false;
}
}

ViewContext getViewContext(Http.Request request) {
String host = request.host();
ViewContext ctx = new ViewContext();
ctx.showInteraction = getShowInteractions();
ctx.showPrescriptions = getShowPrescriptions();
if (host.contains("zurrose")) {
ctx.logo = "ZURROSE";
ctx.googleAnalyticsId = "UA-20151536-22";
Expand All @@ -126,6 +135,13 @@ public Result index(Http.Request request, String atc_query) {
return ok(index.render("", "", "", "", "", vc, messages));
}

public Result prescription(Http.Request request, String lang, String key) {
ViewContext vc = getViewContext(request);
Messages messages = messagesApi.preferred(request);
String html = prescriptions.render("the name").toString();
return ok(index.render(html, "titles", "", "", "", vc, messages));
}

/**
* These is the list of functions which are called from javascripts/coffeescripts
* @return
Expand Down
64 changes: 18 additions & 46 deletions app/models/Article.java
@@ -1,5 +1,6 @@
package models;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
Expand Down Expand Up @@ -32,9 +33,10 @@ public class Article {
public String keyword = "";
public String author = "";
public String atccode = "";
public String atcclass = "";
public String regnrs = "";
public String therapy = "";
public String packinfo = "";
public ArrayList<PackInfo> packinfos = new ArrayList();
public String eancode = "";
public String titles = "";
public String sections = "";
Expand All @@ -58,9 +60,10 @@ public Article(long _id, String _hash, String _title, String _keyword, String _a
this.hash = _hash;
this.title = _title;
this.keyword = _keyword;;
this.packinfo = packinfoStr();
this.packinfos = makePackInfos();
this.author = _author;
this.atccode = atccodeStr();
this.atccode = _atccode;
this.atcclass = _atcclass;
this.regnrs = _regnrs;
this.therapy = therapyStr();
this.eancode = eancodeStr();
Expand All @@ -74,59 +77,28 @@ public Article(String _title, String _titles) {
this._titles = _titles;
}

public String packinfoStr() {
String pack_info_str = "";
public ArrayList<PackInfo> makePackInfos() {
Pattern p_red = Pattern.compile(".*O]");
Pattern p_green = Pattern.compile(".*G]");
Scanner pack_str_scanner = new Scanner(_packinfo);
ArrayList<PackInfo> result = new ArrayList<PackInfo>();
while (pack_str_scanner.hasNextLine()) {
String pack_str_line = pack_str_scanner.nextLine();
Matcher m_red = p_red.matcher(pack_str_line);
Matcher m_green = p_green.matcher(pack_str_line);
if (m_red.find())
pack_info_str += "<p style='color:red;'>" + pack_str_line + "</p>";
else if (m_green.find())
pack_info_str += "<p style='color:green;'>" + pack_str_line + "</p>";
else
pack_info_str += "<p style='color:gray;'>" + pack_str_line + "</p>";
}
pack_str_scanner.close();
return pack_info_str;
}

public String atccodeStr() {
String atc_code_str = "";
String atc_title_str = "";

if (_atccode != null) {
String[] m_code = _atccode.split(";");
if (m_code.length > 1) {
atc_code_str = m_code[0];
atc_title_str = m_code[1];
String color = "";
if (m_red.find()) {
color = "red";
} else if (m_green.find()) {
color = "green";
}
atc_code_str = String.join(",",
Stream.of(atc_code_str.split(","))
.map(code -> "<a class='atc-code' href='/?atc_query=" + code + "'>" + code + "</a>")
.collect(Collectors.toList()));
if (_atcclass != null) {
String[] m_class = _atcclass.split(";");
String atc_class_str;
if (m_class.length == 1) {
atc_code_str = "<p>" + atc_code_str + " - " + atc_title_str + "</p><p>" + m_class[0] + "</p>";
} else if (m_class.length == 2) { // *** Ver.<1.2.4
atc_code_str = "<p>" + atc_code_str + " - " + atc_title_str + "</p><p>" + m_class[1] + "</p>";
} else if (m_class.length == 3) { // *** Ver. 1.2.4 and above
atc_class_str = "";
String[] atc_class_l4_and_l5 = m_class[2].split("#");
if (atc_class_l4_and_l5.length > 0)
atc_class_str = atc_class_l4_and_l5[atc_class_l4_and_l5.length - 1];
atc_code_str = "<p>" + atc_code_str + " - " + atc_title_str + "</p><p>" + atc_class_str + "</p><p>" + m_class[1] + "</p>";
}
} else {
atc_code_str = "<p>" + atc_code_str + " - " + atc_title_str + "</p><p>k.A.</p>";
else {
color = "gray";
}
result.add(new PackInfo(color, pack_str_line));
}
return atc_code_str;
pack_str_scanner.close();
return result;
}

public String therapyStr() {
Expand Down
19 changes: 19 additions & 0 deletions app/models/PackInfo.java
@@ -0,0 +1,19 @@
package models;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PackInfo {
public String color;
public String title;

public PackInfo(String color, String title) {
this.color = color;
this.title = title;
}
}
1 change: 1 addition & 0 deletions app/models/ViewContext.java
Expand Up @@ -22,5 +22,6 @@
public class ViewContext {
public String logo;
public boolean showInteraction;
public boolean showPrescriptions;
public String googleAnalyticsId;
}
11 changes: 11 additions & 0 deletions app/views/index.scala.html
Expand Up @@ -6,6 +6,7 @@
<script type="text/javascript" src="@routes.Assets.versioned("javascripts/amiko.searchdb.js")"></script>
<script type="text/javascript" src="@routes.Assets.versioned("javascripts/amiko.helpers.js")"></script>
<script type="text/javascript" src="@routes.Assets.versioned("javascripts/interaction_callbacks.js")"></script>
<script type="text/javascript" src="@routes.Assets.versioned("javascripts/amiko.prescriptions.js")"></script>
<script>setInitialLanguage("@messages("web_url")")</script>

<header>
Expand All @@ -29,6 +30,16 @@
</div>
</div>
}
@if(vc.showPrescriptions) {
<div class="nav-button" id="prescriptions-button">
<div class="center-image">
<button class="state-button --prescription">
<img border="0" alt="Prescriptions" src="@routes.Assets.versioned("images/prescription.png")" height="28"/>
</button>
<span style="display: block;">@messages("prescriptions")</span>
</div>
</div>
}
<!-- DOWNLOAD BUTTON -->
<div class="nav-button" id="download-button">
<div class="center-image">
Expand Down

0 comments on commit 7fcc144

Please sign in to comment.