121 lines
3.9 KiB
C#
121 lines
3.9 KiB
C#
using BS.Shared.DataContracts;
|
|
using BS.Shared.Models;
|
|
using Dakota.Models.Infos;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Dakota.Logic
|
|
{
|
|
public class DakotaManager
|
|
{
|
|
public int Month { get; set; }
|
|
public int Version { get; set; }
|
|
|
|
public DakotaInfoCreator DakotaInfoCreator { get; set; }
|
|
public bool IsSammelrechnung { get; set; }
|
|
|
|
public Dictionary<string, DakotaFile> DakotaFileDict { get; set; }
|
|
|
|
public Dictionary<string, InfoDateiNutzdaten> DakotaInfoNutzDict { get; set; }
|
|
public Dictionary<string, InfoDateiAuftrags> DakotaInfoAufDict { get; set; }
|
|
|
|
public DakotaManager() : this(DateTime.Now.Month, DateTime.Now)
|
|
{
|
|
|
|
}
|
|
public DakotaManager(int month, DateTime dateTime, bool isSammelrechnung = false)
|
|
{
|
|
Month = month;
|
|
Version = GetVersion(dateTime);
|
|
|
|
DakotaFileDict = new Dictionary<string, DakotaFile>();
|
|
|
|
DakotaInfoNutzDict = new Dictionary<string, InfoDateiNutzdaten>();
|
|
DakotaInfoAufDict = new Dictionary<string, InfoDateiAuftrags>();
|
|
|
|
DakotaInfoCreator = new DakotaInfoCreator(isSammelrechnung);
|
|
IsSammelrechnung = isSammelrechnung;
|
|
}
|
|
|
|
public void Add(ServiceInvoiceDC serviceInvoice, OrganisationDC organisation, CustomerDC customer, AddressInformation address, int datenaustauschreferenz, int transfernummer)
|
|
{
|
|
var ik_datenannahmestelle = organisation.IKDatenannahmestelle;
|
|
var success = DakotaInfoNutzDict.TryGetValue(ik_datenannahmestelle, out InfoDateiNutzdaten nutzdaten);
|
|
|
|
if (!success)
|
|
{
|
|
var verfahrensstufe = organisation.Verfahrensstufe;
|
|
|
|
// Verfahrenkennung
|
|
// Erste Stelle:
|
|
// "E" - Echtdaten
|
|
// "T" - Testdaten
|
|
// Annahme: "E" auch für Erprobungsverfahrenstufe
|
|
// Zusatz: "T" bei Erprobungsverfahrenstufe
|
|
|
|
var isTest = verfahrensstufe == BS.Shared.GkvVerfahrensstufe.Test || verfahrensstufe == BS.Shared.GkvVerfahrensstufe.Erprobung;
|
|
var verfahrenkennung = isTest ? "TSOL0" : "ESOL0";
|
|
var logischer_dateiname = DakotaConfig.GetLogischerDateiname(Month).Trim();
|
|
|
|
var info_nutz_add = DakotaInfoCreator.GetEmptyInfoNutzdatendatei(DakotaConfig.IKAbsender, organisation.IKDatenannahmestelle, (int)verfahrensstufe, logischer_dateiname, datenaustauschreferenz);
|
|
var info_auf_add = DakotaInfoCreator.GetEmptyInfoAuftragsdatei(organisation.IKDatenannahmestelle, logischer_dateiname, verfahrenkennung, transfernummer);
|
|
|
|
DakotaInfoNutzDict.Add(ik_datenannahmestelle, info_nutz_add);
|
|
DakotaInfoAufDict.Add(ik_datenannahmestelle, info_auf_add);
|
|
|
|
nutzdaten = info_nutz_add;
|
|
}
|
|
|
|
foreach (var peroid in serviceInvoice.ServiceInvoicePeriods)
|
|
{
|
|
foreach (var invoice in peroid.InvoiceItems)
|
|
{
|
|
var info_nutz_item = new InfoParameterInvoiceItem(serviceInvoice, invoice, organisation, customer, address);
|
|
|
|
DakotaInfoCreator.AddInfoParameter(nutzdaten, info_nutz_item, Version);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Apply()
|
|
{
|
|
foreach (var ik_datenannahmestelle in DakotaInfoNutzDict.Keys)
|
|
{
|
|
var file = new DakotaFile(DateTime.Now);
|
|
|
|
var info_nutz = DakotaInfoNutzDict[ik_datenannahmestelle];
|
|
var info_auf = DakotaInfoAufDict[ik_datenannahmestelle];
|
|
|
|
file.Nutzdatendatei.Apply(info_nutz, DakotaInfoCreator.IsSammelrechnung);
|
|
file.Auftragsdatei.Apply(info_auf);
|
|
|
|
DakotaFileDict.Add(ik_datenannahmestelle, file);
|
|
}
|
|
}
|
|
|
|
private int GetVersion(DateTime create4month)
|
|
{
|
|
if (create4month < new DateTime(2023, 7, 1))
|
|
throw new NotImplementedException("Keine Unterstützung von Version 17 oder niedriger");
|
|
|
|
if (create4month < new DateTime(2024, 1, 1))
|
|
return 18;
|
|
|
|
if (create4month < new DateTime(2024, 7, 1))
|
|
return 19;
|
|
|
|
if (create4month < new DateTime(2026, 1, 1))
|
|
return 20;
|
|
|
|
if (create4month < new DateTime(2027, 1, 1))
|
|
return 21;
|
|
|
|
throw new NotImplementedException("Keine Unterstützung von Version 22 oder aufwärts");
|
|
}
|
|
}
|
|
}
|