First working version of drugs formatting.
This commit is contained in:
parent
bcbed5bca3
commit
21e7d44187
45
Tests/Medication/ImporterTest.cs
Executable file
45
Tests/Medication/ImporterTest.cs
Executable file
@ -0,0 +1,45 @@
|
||||
/* ImporterTest.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests.Medication
|
||||
{
|
||||
[TestFixture]
|
||||
class ImporterTest
|
||||
{
|
||||
[Test]
|
||||
public void ImportDrugsTwoColumns()
|
||||
{
|
||||
string s =
|
||||
"Aktuelle Medikation:\r" +
|
||||
"Advagraf 1 mg 2-0-0 CellCept 500 mg 1-0-1\r" +
|
||||
"CellCept 250 mg 1-0-1 Decortin 10 mg 1-0-0\r" +
|
||||
"Beloc-Zok mite 1-0-1 Ramipril 5 mg 0-0-1 (neu)\r" +
|
||||
"Pantozol 40 mg 0-0-1 Decostriol 0,5 µg 2-0-0\r" +
|
||||
"Euthyrox 200 µg 1-1-1 (gesteigert) Ossofortin forte 1-0-1\r" +
|
||||
"Vfend 200 mg 2-0-2 CPS-Pulver 0-1-0\r" +
|
||||
"Cyklokapron 500 mg 1-1-1 Tamsulosin 0,4 mg 1-0-0 ";
|
||||
zaaReloaded2.Medication.Importer i = new zaaReloaded2.Medication.Importer(s);
|
||||
Assert.AreEqual(14, i.Prescriptions.Count);
|
||||
}
|
||||
}
|
||||
}
|
@ -83,6 +83,7 @@
|
||||
<Compile Include="Controller\Comments\CommentPoolTest.cs" />
|
||||
<Compile Include="Controller\Comments\ItemCommentTest.cs" />
|
||||
<Compile Include="Controller\Elements\CloneTest.cs" />
|
||||
<Compile Include="Medication\ImporterTest.cs" />
|
||||
<Compile Include="Medication\PrescriptionTest.cs" />
|
||||
<Compile Include="SerializationTest.cs" />
|
||||
<Compile Include="Controller\SettingsRepositoryTest.cs" />
|
||||
|
BIN
gimp/m.xcf
Normal file
BIN
gimp/m.xcf
Normal file
Binary file not shown.
@ -138,6 +138,31 @@ namespace zaaReloaded2
|
||||
Globals.ThisAddIn.Application.Selection);
|
||||
}
|
||||
|
||||
public static void FormatDrugs()
|
||||
{
|
||||
// If no "real" selection exists, attempt to auto-detect the drugs section.
|
||||
// (NB Technically, there is never _no_ selection in a document.)
|
||||
Word.Window activeWindow = Globals.ThisAddIn.Application.ActiveWindow;
|
||||
Word.Selection sel = activeWindow.Selection;
|
||||
if (!(sel.Paragraphs.Count > 1
|
||||
|| (sel.Text.Length > 1 && sel.Text.EndsWith("\r"))))
|
||||
{
|
||||
if (!Medication.Importer.AutoDetect(activeWindow.Document))
|
||||
{
|
||||
NotificationAction a = new NotificationAction();
|
||||
a.Caption = "Formatieren nicht möglich";
|
||||
a.Message = "Das Dokument scheint keine Medikationsliste zu enthalten.";
|
||||
a.OkButtonLabel = "Schließen";
|
||||
a.Invoke();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Medication.Importer importer = new Medication.Importer(activeWindow.Selection.Text);
|
||||
Medication.Formatter formatter = new Medication.Formatter(importer.Prescriptions);
|
||||
formatter.FormatOneColumn(activeWindow.Document);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
Binary file not shown.
@ -142,13 +142,7 @@ namespace zaaReloaded2.Formatter
|
||||
// Create undo record and styles prior to iterating over the elements
|
||||
// because a column switching element might trigger output to the
|
||||
// document.
|
||||
bool hasAddin = Globals.ThisAddIn != null;
|
||||
if (hasAddin)
|
||||
{
|
||||
Globals.ThisAddIn.Application.UndoRecord.StartCustomRecord(
|
||||
String.Format("Laborformatierung ({0})", Properties.Settings.Default.AddinName)
|
||||
);
|
||||
}
|
||||
Helpers.StartUndo("Laborformatierung");
|
||||
CreateStyles();
|
||||
|
||||
int current = 0;
|
||||
@ -177,10 +171,7 @@ namespace zaaReloaded2.Formatter
|
||||
}
|
||||
|
||||
_secondaryBuffer.Flush();
|
||||
if (hasAddin)
|
||||
{
|
||||
Globals.ThisAddIn.Application.UndoRecord.EndCustomRecord();
|
||||
}
|
||||
Helpers.EndUndo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -40,5 +40,30 @@ namespace zaaReloaded2
|
||||
new string[] { "\r\n", "\n\r", "\r", "\n" },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts a custom undo record.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public static void StartUndo(string message)
|
||||
{
|
||||
if (Globals.ThisAddIn != null)
|
||||
{
|
||||
Globals.ThisAddIn.Application.UndoRecord.StartCustomRecord(
|
||||
String.Format("{0} ({1})", message, Properties.Settings.Default.AddinName)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ends an undo record.
|
||||
/// </summary>
|
||||
public static void EndUndo()
|
||||
{
|
||||
if (Globals.ThisAddIn != null)
|
||||
{
|
||||
Globals.ThisAddIn.Application.UndoRecord.EndCustomRecord();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
zaaReloaded2/Icons/m.png
Normal file
BIN
zaaReloaded2/Icons/m.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 778 B |
83
zaaReloaded2/Medication/Formatter.cs
Executable file
83
zaaReloaded2/Medication/Formatter.cs
Executable file
@ -0,0 +1,83 @@
|
||||
using Microsoft.Office.Interop.Word;
|
||||
/* Formatter.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace zaaReloaded2.Medication
|
||||
{
|
||||
/// <summary>
|
||||
/// Formats prescriptions
|
||||
/// </summary>
|
||||
public class Formatter
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public IList<Prescription> Prescriptions { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public Formatter() { }
|
||||
|
||||
public Formatter(IList<Prescription> prescriptions)
|
||||
: this()
|
||||
{
|
||||
Prescriptions = prescriptions;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Writes a block of prescriptions with one column to a
|
||||
/// Word document.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
public void FormatOneColumn(Document document)
|
||||
{
|
||||
if (document == null)
|
||||
{
|
||||
throw new ArgumentNullException(
|
||||
"Cannot format prescriptions because no document was given.");
|
||||
}
|
||||
|
||||
Helpers.StartUndo("Medikation formatieren");
|
||||
foreach (Prescription p in Prescriptions)
|
||||
{
|
||||
document.ActiveWindow.Selection.TypeText(p.ToString() + "\r");
|
||||
}
|
||||
Helpers.EndUndo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a table containing all prescriptions and copies it to
|
||||
/// the clipboard.
|
||||
/// </summary>
|
||||
public void CreatePrescriptionsTable()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ namespace zaaReloaded2.Medication
|
||||
/// The detected block is selected.
|
||||
/// </summary>
|
||||
/// <returns>True if a block was detected, false if not.</returns>
|
||||
public bool AutoDetect(Document document)
|
||||
public static bool AutoDetect(Document document)
|
||||
{
|
||||
Paragraph start = null;
|
||||
Paragraph end = null;
|
||||
@ -47,20 +47,20 @@ namespace zaaReloaded2.Medication
|
||||
string line = document.Paragraphs[i].Range.Text;
|
||||
if (Prescription.IsPrescriptionLine(line))
|
||||
{
|
||||
start = document.Paragraphs[i];
|
||||
end = document.Paragraphs[i];
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
|
||||
if (start != null)
|
||||
if (end != null)
|
||||
{
|
||||
end = start;
|
||||
while (i > 1)
|
||||
start = end;
|
||||
while (i > 2)
|
||||
{
|
||||
if (!Prescription.IsPrescriptionLine(document.Paragraphs[i - 1].Range.Text))
|
||||
{
|
||||
end = document.Paragraphs[i];
|
||||
start = document.Paragraphs[i];
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
@ -102,7 +102,7 @@ namespace zaaReloaded2.Medication
|
||||
{
|
||||
if (Prescription.IsPrescriptionLine(line))
|
||||
{
|
||||
Prescriptions.Add(Prescription.FromLine(line));
|
||||
Prescriptions.AddRange(Prescription.ManyFromLine(line));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,9 @@ namespace zaaReloaded2
|
||||
case "zrlDemo":
|
||||
Commands.LoadDemo();
|
||||
break;
|
||||
case "zrlFormatDrugs":
|
||||
Commands.FormatDrugs();
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException("No operation defined for " + control.Id);
|
||||
}
|
||||
@ -150,6 +153,11 @@ namespace zaaReloaded2
|
||||
return Commands.CanFormat();
|
||||
}
|
||||
|
||||
public bool CanFormatDrugs(Office.IRibbonControl control)
|
||||
{
|
||||
return Commands.CanFormat();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
@ -23,8 +23,8 @@
|
||||
<ribbon>
|
||||
<tabs>
|
||||
<tab id="zaaReloaded2" label="zaaReloaded2">
|
||||
<group id="zrlFormatGroup" label="Formatieren">
|
||||
<button id="zrlFormat" label="Formatieren" image="f.png" onAction="Ribbon_Click" size="large"
|
||||
<group id="zrlGroupLab" label="Laborwerte">
|
||||
<button id="zrlFormatLab" label="Formatieren" image="f.png" onAction="Ribbon_Click" size="large"
|
||||
supertip="Formatiert den ausgewählten Bereich mit dem zuletzt verwendeten Stil."
|
||||
getEnabled="CanFormat" />
|
||||
<button id="zrlSettings" label="Stilauswahl" image="fff.png" onAction="Ribbon_Click" size="large"
|
||||
@ -32,6 +32,11 @@
|
||||
<button id="zrlDaniel" label="Daniels Spezial" image="dk.png" onAction="Ribbon_Click" size="large"
|
||||
getVisible="Daniel_GetVisible"/>
|
||||
</group>
|
||||
<group id="zrlGroupDrugs" label="Medikamente">
|
||||
<button id="zrlFormatDrugs" label="Formatieren" image="m.png" onAction="Ribbon_Click" size="large"
|
||||
supertip="Formatiert die Medikationsliste"
|
||||
getEnabled="CanFormatDrugs" />
|
||||
</group>
|
||||
<group id="zrlInfoGroup" label="Info">
|
||||
<button id="zrlDemo" label="Demo" image="d.png" onAction="Ribbon_Click" size="large"
|
||||
screentip="Demo-Dokument öffnen"
|
||||
|
@ -222,6 +222,7 @@
|
||||
<Compile Include="Formatter\DanielsStyle.cs" />
|
||||
<Compile Include="Formatter\DocumentWriter.cs" />
|
||||
<Compile Include="Formatter\NoLaboratoryDataException.cs" />
|
||||
<Compile Include="Medication\Formatter.cs" />
|
||||
<Compile Include="Medication\Importer.cs" />
|
||||
<Compile Include="Medication\Prescription.cs" />
|
||||
<Compile Include="Preferences.cs" />
|
||||
@ -449,6 +450,9 @@
|
||||
<ItemGroup>
|
||||
<Resource Include="Icons\gear.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Icons\m.png" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
Loading…
Reference in New Issue
Block a user