Skip to content

Commit

Permalink
Allow empty values in info fiels when printing prescription. Add test…
Browse files Browse the repository at this point in the history
…s for 10 drugs.
  • Loading branch information
ngiger committed Jul 30, 2014
1 parent 64ed9e7 commit 87103b3
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 55 deletions.
77 changes: 48 additions & 29 deletions doc/resources/javascript/prescription.js
@@ -1,7 +1,8 @@
function print_composite_init(comment_id) {
var field_id = 'undefined';
try {
for (index = 0; index < 99; ++index) {
var field_id = 'prescription_comment_' + index;
field_id = 'prescription_comment_' + index;
var saved_value = sessionStorage.getItem(field_id, '');
var x=document.getElementById(field_id);
var header=document.getElementById('prescription_header_' + index);
Expand All @@ -25,7 +26,7 @@ function print_composite_init(comment_id) {
}
}
js_restore_prescription_patient_info();
var field_id = 'prescription_sex';
field_id = 'prescription_sex';
var saved_value = sessionStorage.getItem(field_id, '');
// console.log ('PrescriptionForm.onload ' + field_id + ':' + document.getElementById(field_id) + ': saved_value ' + saved_value);
if (saved_value == '1') {
Expand All @@ -35,7 +36,7 @@ function print_composite_init(comment_id) {
}
}
catch(err) {
console.log('print_composite_init: catched error: ' + err);
console.log('print_composite_init: catched error: ' + err + ' for ' + field_id);
}
}

Expand All @@ -47,53 +48,71 @@ function getToday() {
return year + month + day;
}

function getValueOfDomElement(element_id) {
console.log('getValueOfDomElement of ' + element_id);
var inhalt = '';
try {
var element = document.getElementById(element_id);
if (element == undefined || element == null) {
return '';
}
inhalt = element.value;
if (inhalt == undefined || inhalt == null) {
inhalt = element.innerHTML;
if (inhalt == undefined || inhalt == null) {
return '';
}
}
} catch(err) {
console.log('getValueOfDomElement: catched error: ' + err);
}
console.log('getValueOfDomElement of ' + element_id + ' returns ' + inhalt);
return inhalt;
}
function create_prescription_from_dom() {
var prescription = new Prescription(guid());
prescription.doctor_glin = 'doctor-ean13'
prescription.doctor_zsr = 'ZSR?'
prescription.patient_id = 'PatID?'
prescription.date_issued = getToday()
prescription.patient_family_name = document.getElementById('prescription_family_name').value
prescription.patient_first_name = document.getElementById('prescription_first_name').value
prescription.patient_zip_code = 'PLZ?'
prescription.patient_birthday = document.getElementById('prescription_birth_day').value
prescription.patient_insurance_glin = 'Vers.Nummer'
prescription.doctor_zsr = getValueOfDomElement('prescription_zsr')
prescription.doctor_glin = 'doctor-ean13' // TODO: Add more info via SOAP from ZSR
prescription.patient_id = getValueOfDomElement('prescription_patient_id')
prescription.patient_family_name = getValueOfDomElement('prescription_family_name')
prescription.patient_first_name = getValueOfDomElement('prescription_first_name')
prescription.patient_zip_code = getValueOfDomElement('prescription_patient_plz')
prescription.patient_birthday = getValueOfDomElement('prescription_birth_day')
prescription.patient_insurance_glin = getValueOfDomElement('prescription_patient_insurance_glin')

for (index = 0; index < 99; ++index) {
var id = document.getElementById('prescription_comment_' + index);
if (id == null) { break; }
var comment_id = 'prescription_comment_' + index;
var ean13_id = 'prescription_ean13_' + index;
var comment = document.getElementById(comment_id);
if (comment != null) {
var prescription_dom = document.getElementById(ean13_id);
if (prescription_dom != null) {
var ean13 = prescription_dom.innerHTML; // value is undefined
// console.log('create_prescription_from_dom add ' + index + ' ean13 ' + ean13);
var item = new PrescriptionItem(ean13)
item.extended_posology = comment.innerHTML;
prescription.add_item(item);
}
}
if (comment == undefined || comment == null) { break; }
var comment = getValueOfDomElement(comment_id)
var ean13 = getValueOfDomElement('prescription_ean13_' + index);
var item = new PrescriptionItem(ean13)
item.extended_posology = comment;
prescription.add_item(item);
}
return prescription;
}

function add_prescription_qr_code(text_id, element_id) {
// console.log('add_prescription_qr_code for element '+element_id + ' from text_id ' + text_id);
try {
var qrcode = new QRCode(element_id);

function makeCode () {
var inhalt = create_prescription_from_dom().qr_string();
var inhalt = create_prescription_from_dom().qr_string();
document.getElementById(text_id).innerHTML = inhalt;
qrcode.makeCode(inhalt);
var qrcode = new QRCode(element_id, {
text: inhalt,
correctLevel : QRCode.CorrectLevel.H
});

// qrcode.makeCode(inhalt);
}

makeCode();
}
catch(err) {
console.log('prescription_form_init: catched error: ' + err);
console.log('add_prescription_qr_code: catched error: ' + err);
document.getElementById(element_id).innerHTML = 'Error generating QRCode: ' + err;
}
}

Expand Down
2 changes: 1 addition & 1 deletion doc/resources/javascript/qrcode.js
Expand Up @@ -219,7 +219,7 @@ var QRCode;
return Drawing;
})();

var useSVG = document.documentElement.tagName.toLowerCase() === "svg";
var useSVG = (typeof document === 'undefined') ? false : document.documentElement.tagName.toLowerCase() === "svg";

// Drawing in DOM by using Table tag
var Drawing = useSVG ? svgDrawer : !_isSupportCanvas() ? (function () {
Expand Down
111 changes: 91 additions & 20 deletions spec/rezept_and_instantsearch_spec.rb
Expand Up @@ -35,29 +35,28 @@ def add_one_drug_to_rezept(name)
end

before :all do
@idx = 0
$prescription_test_id = 1
waitForOddbToBeReady(@browser, OddbUrl)
login
end

before :each do
@timestamp = Time.now.strftime('%Y%m%d%H%M%S')
# puts "before #{$prescription_test_id} with #{@browser.windows.size} windows"
while @browser.windows.size > 1
@browser.windows.first.use
@browser.windows.last.close if @browser.windows.last
end
@browser.goto OddbUrl
if @browser.link(:text=>'Plus').exists?
puts "Going from instant to plus"
@browser.link(:text=>'Plus').click
@browser.link(:text=>'Plus').click
end
end

after :each do
@idx += 1
createScreenshot(@browser, '_'+@idx.to_s) if @browser
# sleep
@browser.goto OddbUrl
end

after :all do
@browser.close if @browser
createScreenshot(@browser, '_'+$prescription_test_id.to_s) if @browser
$prescription_test_id += 1
end

def genComment(unique)
Expand Down Expand Up @@ -86,9 +85,10 @@ def setGeneralInfo(nrMedis=0)
def checkGeneralInfo(nrMedis=0)
if @browser.url.index('/print/rezept/')
inhalt = @browser.text
inhalt.should_not match /Error generating QRCode/i
[FirstName, FamilyName, Birthday, " m\n"].each {
|what|
unless inhalt.index(what)
if inhalt.index(what).class == NilClass
puts "Could not find #{what} in #{inhalt}"
# require 'pry'; binding.pry
end
Expand Down Expand Up @@ -117,30 +117,64 @@ def checkGeneralInfo(nrMedis=0)
end
end

it "should be possible to print a presciption" do
@browser.goto(OddbUrl + '/de/gcc/rezept/ean/7680516820922,7680390530474')
setGeneralInfo(2)
def showElapsedTime(startTime, comment = caller[0])
duration = (Time.now - startTime).to_i
puts "#{comment} took #{duration} seconds"
end

def waitForPrintInfo(maxSeconds = 120)
startTime = Time.now
while @browser.text.size < 100
# puts "Slept already for #{(Time.now - startTime).to_i} seconds. size is #{@browser.text.size}"
sleep(1)
break if Time.now - startTime > maxSeconds
end
# puts "waitForPrintInfo finished after #{(Time.now - startTime).to_i} seconds. size is #{@browser.text.size}"
sleep(1)
end

it "should print the fachinfo when opening the fachinfo from a prescription" do
@browser.select_list(:name, "search_type").select("Markenname")
@browser.text_field(:name, "search_query").set(Four_Medis.first)
@browser.button(:name, "search").click
@browser.link(:href, /rezept/).click
setGeneralInfo(1)
@browser.element(:text, 'FI').click
oldWindowsSize = @browser.windows.size
@browser.link(:text, /FI/).click
@browser.windows.size.should == oldWindowsSize + 1 # must open a new window
@browser.windows.last.use
oldWindowsSize = @browser.windows.size
@browser.link(:text, /Drucken/i).click
@browser.windows.size.should == oldWindowsSize + 1 # must open a new window
@browser.windows.last.use
@browser.url.should_not match /^rezept/i
@browser.text.should match /^Ausdruck[^\n]+\nFachinformation/
end

it 'should not throw a an error with a problematic combination of drugs' do
@browser.goto(OddbUrl + '/de/gcc/rezept/ean/7680516801112,7680576730063?')
oldWindowsSize = @browser.windows.size
@browser.button(:name, "print").click
@browser.windows.size.should == oldWindowsSize + 1 # must open a new window
@browser.windows.last.use
waitForPrintInfo
inhalt = @browser.text
checkGeneralInfo(2)
inhalt.should_not match /Error generating QRCode/i
inhalt.should_not match /Bemerkungen/
inhalt.should match(/Ausdruck/i)
['Ausdruck',
'Stempel, Unterschrift',
'Merfen', 'Nolvadex',
'7680516820922', '7680390530474',
'Merfen', 'Aspirin',
'7680516801112', '7680576730063?',
/ m$/, # männlich
].each do
|name|
inhalt.should match(name)
end
inhalt.should match /Bemerkungen/
end

it "should not contain remarks or interaction header only when present" do
# goto Asprin, Inderal, Marcouma
it "should contain remarks or interaction header only when present" do
@browser.goto(OddbUrl + '/de/gcc/rezept/ean/')
add_one_drug_to_rezept('Aspirin')
add_one_drug_to_rezept('Inderal')
Expand All @@ -152,6 +186,7 @@ def checkGeneralInfo(nrMedis=0)
@browser.button(:name, "print").click
@browser.windows.size.should == oldWindowsSize + 1 # must open a new window
@browser.windows.last.use
waitForPrintInfo
inhalt = @browser.text
checkGeneralInfo(2)
inhalt.scan(/\nBemerkungen\n/).size.should == 2
Expand All @@ -177,6 +212,7 @@ def checkGeneralInfo(nrMedis=0)
@browser.url.should_not match /^rezept/i
@browser.text.should match /^Ausdruck[^\n]+\nFachinformation/
end

it "should enable to go back after printing a prescription" do
@browser.goto OddbUrl
@browser.select_list(:name, "search_type").select("Markenname")
Expand All @@ -191,6 +227,7 @@ def checkGeneralInfo(nrMedis=0)
end

it "should not loose existing comment after adding a new prescription" do
@browser.goto OddbUrl
@browser.select_list(:name, "search_type").select("Markenname")
@browser.text_field(:name, "search_query").set(Four_Medis.first)
@browser.button(:name, "search").click
Expand All @@ -200,7 +237,9 @@ def checkGeneralInfo(nrMedis=0)
add_one_drug_to_rezept(Four_Medis[1])
checkGeneralInfo(1)
end

it "should show the interaction between different drugs" do
@browser.goto OddbUrl
@browser.select_list(:name, "search_type").select("Markenname")
@browser.text_field(:name, "search_query").set(Four_Medis.first)
@browser.button(:name, "search").click
Expand Down Expand Up @@ -305,4 +344,36 @@ def checkGeneralInfo(nrMedis=0)
inhalt.should match(/Zusammensetzung/i)
inhalt.should match(/Filmtabletten/i)
end

# this tests takes (at the moment) over 2,5 minutes
it "should be possible to print a presciption with 10 drugs" do
startTime = Time.now
nrDrugs = 10
@browser.goto(OddbUrl + '/de/gcc/rezept/ean/')
add_one_drug_to_rezept('Aspirin')
add_one_drug_to_rezept('Inderal')
add_one_drug_to_rezept('Marcoumar')
add_one_drug_to_rezept('Ponstan')
add_one_drug_to_rezept('Merfen')
add_one_drug_to_rezept('Actem')
add_one_drug_to_rezept('Dostinex')
add_one_drug_to_rezept('Yondelis')
add_one_drug_to_rezept('Bactrim')
add_one_drug_to_rezept('Badesalz')

# add two remarks
setGeneralInfo(nrDrugs)
showElapsedTime(startTime, "Generating a prescription with #{nrDrugs}")
startTime = Time.now
oldWindowsSize = @browser.windows.size
@browser.button(:name, "print").click
@browser.windows.size.should == oldWindowsSize + 1 # must open a new window
@browser.windows.last.use
waitForPrintInfo
showElapsedTime(startTime, "Printing a prescription with #{nrDrugs} drugs")
inhalt = @browser.text.clone
checkGeneralInfo(nrDrugs)
inhalt.scan(/\nBemerkungen\n/).size.should == nrDrugs
inhalt.scan(/\nInteraktionen\n/).size.should == nrDrugs
end
end
7 changes: 4 additions & 3 deletions test/test_view/drugs/javascript.js
Expand Up @@ -21,7 +21,7 @@ function create_qrcode_example() {
}

function create_example_prescription(){
var prescription = prescription( '4dd33f59-1fbb-4fc9-96f1-488e7175d761');
var prescription = new Prescription( '4dd33f59-1fbb-4fc9-96f1-488e7175d761');
prescription.SW_ORIGIN_ID = 'TriaMed'
prescription.SW_VERSION_ID = '3.9.3.0'
prescription.doctor_glin = '7601000092786'
Expand All @@ -35,6 +35,7 @@ function create_example_prescription(){
prescription.patient_insurance_glin = '7601003000382'
return prescription
}
// console.log(create_qrcode_example().qr_string());
console.log('No tests run until DOH added');

console.log(create_qrcode_example().qr_string());
// TODO: add test for the following problematic string
// http://2dmedication.org/|1.0|62a5b6cb-43cd-84bc-a72e-98392d55ca41|ywesee GmBh|1.0|doctor-ean13|||2051|||||;7680516801112|||1||0.00-0.00-0.00-0.00|||0|7680576730063|||1||0.00-0.00-0.00-0.00|||0;14436
7 changes: 5 additions & 2 deletions test/test_view/drugs/javascript.rb
Expand Up @@ -16,10 +16,13 @@ def test_simple_logging
def test_prescription
javascripts = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..','doc', 'resources', 'javascript'))
base = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..','doc', 'resources'))
outfile = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'log', 'javascript_test.js'));
ENV['NODE_PATH']=javascripts # "#{dojo}:#{javascripts}"
expected = 'http://2dmedication.org/|1.0|4dd33f59-1fbb-4fc9-96f1-488e7175d761|TriaMed|3.9.3.0|7601000092786|K2345.33||20131104|Beispiel|Susanne|3073|19460801|7601003000382;|2014236||1||0.00-0.00-0.00-0.00|||1|||SPEZIALVERBAND|1|20131214|0.00-0.00-0.00-0.00||40|0|7680456740106|||1||1.00-1.00-1.00-0.00|zu Beginn der Mahlzeiten mit mindestens einem halben Glas Wasser einzunehmen||0;27834'
expected = 'No tests run until DOH added'
assert_equal(expected, `nodejs #{__FILE__.sub('.rb','.js')}`.chomp);
cmd = "cat #{javascripts}/qrcode.js #{}/#{javascripts}/prescription.js #{__FILE__.sub('.rb','.js')} | tee #{outfile} | nodejs"
result = `#{cmd}`.chomp
puts "Failed running #{cmd}" unless expected == result
assert_equal(expected, `#{cmd}`.chomp);
end
end

0 comments on commit 87103b3

Please sign in to comment.