<?php
namespace App\Controller;
#use Symfony\Component\HTTPFoundation\Response;
#use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use phpseclib\Net\SFTP;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\MedComCorrespondence;
use App\Entity\MedComMessages;
use App\Entity\Patient;
use App\Entity\Dialogue;
use App\Entity\User;
use App\Entity\JoMasterInformation;
use App\Entity\JoPostMail;
use App\Entity\JoPostMailAttachment;
use App\Entity\PredefinedAttachmentType;
use App\Entity\PredefinedCaseCard;
use App\Entity\DialogueCaseCard;
use App\Entity\DialogueCaseCardMeasure;
use App\Entity\DialogueAttachmentDetails;
use App\Entity\CasecardMeasure;
use App\Entity\DialogueAttachments;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
class MedComController extends AbstractController {
private $EANS = "";
private $medcomID = "";
private $medcomIDCode = "";
private $orgName = "";
private $departmentName = "";
private $unitName = "";
private $districtName = "";
private $postalCode = "";
private $address = "";
private $city = "";
private $Info;
private $em;
private $user;
private $userRoleType;
private $session;
private $dialogueControllerObj;
private $selectedPatient;
private $selectedDialogue;
private $patientObj;
private $dialogueObj;
private $cprNo;
private $areaNames;
private $getFullDate;
private $bdateYear;
private $dateDiff;
private $ean = array();
function __construct() {
}
private function auth($request) {
$twig = $this->container->get('twig');
$globals = $twig->getGlobals();
$this->EANS = $globals["medcom"]["ean"];
$this->medcomID = $globals["medcom"]["medcomID"];
$this->medcomIDCode = $globals["medcom"]["medcomIDCode"];
$this->orgName = $globals["medcom"]["orgName"];
$this->departmentName = $globals["medcom"]["departmentName"];
$this->unitName = $globals["medcom"]["unitName"];
$this->districtName = $globals["medcom"]["districtName"];
$this->postalCode = $globals["medcom"]["postalCode"];
$this->address = $globals["medcom"]["address"];
$this->city = $globals["medcom"]["city"];
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$this->Info = array("EAN" => $this->EANS, "orgName" => $this->orgName, "departmentName" => $this->departmentName, "unitName" => $this->unitName, "District" => $this->districtName, "postal" => $this->postalCode, "address" => $this->address, "city" => $this->city);
$this->em = $this->getDoctrine()->getManager();
$this->_receiveVans($request);
$this->user = $this->get('security.token_storage')->getToken()->getUser();
$this->userRoleType = $this->user->hasRole('ROLE_CSV') ? 1 : ($this->user->hasRole('ROLE_DTS') ? 2 : 0);
$this->session = $request->getSession();
$this->dialogueControllerObj = new DialogueController();
$this->selectedPatient = $this->session->get("selectedPatient", null);
$this->selectedDialogue = $this->session->get("selectedDialogue", null);
if($this->selectedDialogue != null)
$this->dialogueObj = $this->em->getRepository(Dialogue::class)->find($this->selectedDialogue);
if($this->selectedPatient != null)
$this->patientObj = $this->em->getRepository(Patient::class)->find($this->selectedPatient);
$this->areaNames = $this->em->getRepository(JoMasterInformation::class)->getAreaNames();
if($this->selectedPatient != null)
$this->cprNo = $this->patientObj->getCpr();
if($this->selectedPatient != null)
$this->getFullDate = $this->dialogueControllerObj->getBirthDate($this->cprNo);
if($this->selectedPatient != null)
$this->bdateYear = date_format($this->getFullDate, "d.m.Y");
$this->dateDiff = $this->dialogueControllerObj->getUserAge($this->bdateYear);
}
public function getMedComNewFiles(Request $request) {
$directory = getcwd()."/Medcom/In/";
// Initialize filecount variavle
$filecount = 0;
$files2 = glob( $directory ."*" );
if( $files2 ) {
$filecount = count($files2);
}
return new Response(json_encode($filecount), Response::HTTP_OK,['content-type' => "text/json"]);
}
private function getMedComSpecialtyCodes() {
$array = array();
$array["Ikkeklassificeret"] = "Ikke klassificeret";
$array["ikkeklassificeret"] = "Ikke klassificeret";
$array["blandet"] = "Blandet medicin";
$array["intern_medicin_sygehus"] = "Intern medicin";
$array["geriatri"] = "Geriatri";
$array["hepatologi"] = "Hepatologi";
$array["haematologi"] = "Hæmatologi";
$array["Infektionsmedicin"] = "Infektionsmedicin";
$array["kardiologi"] = "Kardiologi";
$array["med_allergologi"] = "Med. allergologi";
$array["med_endokrinologi"] = "Med. endokrinologi";
$array["med_gastroenterologi"] = "Med. gastroenterologi";
$array["med_lungesygdomme"] = "Med. lungesygdomme";
$array["nefrologi"] = "Nefrologi";
$array["reumatologi"] = "Reumatologi";
$array["palliativ"] = "Palliativ medicin";
$array["akut"] = "Akut medicin";
$array["dermato_venerologi_sygehus"] = "Dermato-venerologi";
$array["neurologi"] = "Neurologi";
$array["onkologi"] = "Onkologi";
$array["kirurgi_sygehus"] = "Kirurgi";
$array["karkirurgi"] = "Karkirurgi";
$array["kir_gastroenterologi"] = "Kir. gastroenterologi";
$array["plastikkirurgi"] = "Plastikkirurgi";
$array["thoraxkirurgi"] = "Thoraxkirurgi";
$array["urologi"] = "Urologi";
$array["gynaekologi_obstetrik_sygehus"] = "Gynækologi og obstetrik";
$array["sexologi"] = "Sexologi";
$array["neurokirurgi"] = "Neurokirurgi";
$array["ortopaedisk_kirurgi_sygehus"] = "Ortopædisk kirurgi";
$array["oftalmologi"] = "Oftalmologi";
$array["oto_rhino_laryngologi"] = "Oto-, rhino-, laryngologi";
$array["hospitalsodontologi"] = "Hospitalsodontologi";
$array["psykiatri_sygehus"] = "Psykiatri";
$array["boerne_ungdomspsykiatri"] = "Børne- og ungdomspsykiatri";
$array["klin_biokemi"] = "Klin. biokemi";
$array["klin_fys_nuklearmedicin"] = "Klin fys og nuklearmedicin";
$array["klin_immunologi"] = "Klin. immunologi";
$array["klin_mikrobiologi"] = "Klin. mikrobiologi";
$array["klin_neurofysiologi"] = "Klin. neurofysiologi";
$array["patologisk_anatomi"] = "Patologisk anatomi";
$array["diagnostisk_radiologi"] = "Diagnostisk radiologi";
$array["klin_farmakologi"] = "Klin. farmakologi";
$array["klin_genetik"] = "Klin. genetik";
$array["paediatri_sygehus"] = "Pædiatri";
$array["anaestesiologi_sygehus"] = "Anæstesiologi";
$array["arbejdsmedicin"] = "Arbejdsmedicin";
$array["almen_medicin"] = "Almen medicin";
$array["samfundsmedicin"] = "Samfundsmedicin";
$array["retsmedicin"] = "Retsmedicin";
$array["fysioterapi_sygehus"] = "Fysio- og ergoterapi";
$array["anaestesiologi_praksis"] = "Anæstesiologi";
$array["roentgen_kbh"] = "Røntgen (København)";
$array["dermato_venerologi_praksis"] = "Dermatologi-venerologi";
$array["roentgen"] = "Røntgen";
$array["reumatologi_fysiurgi"] = "Reumatologi (Fysiurgi)";
$array["gynaekologi_obstetrik_praksis"] = "Gynækologi/obstetrik";
$array["intern_medicin_praksis"] = "Intern Medicin";
$array["kirurgi_praksis"] = "Kirurgi";
$array["klinisk_kemi"] = "Klinisk kemi";
$array["neurokirurgi_praksis"] = "Neurokirurgi";
$array["neuromedicin"] = "Neuromedicin";
$array["oejenlaege"] = "Øjenlæge";
$array["ortopaedisk_kirurgi_praksis"] = "Ortopædisk Kirurgi";
$array["oere_naese_halslaege"] = "Øre, Næse halslæge";
$array["patologi"] = "Patologi";
$array["plastkirurgi"] = "Plastkirurgi";
$array["psykiatri_praksis"] = "Psykiatri";
$array["paediatri"] = "Pædiatri";
$array["boernepsykiatri"] = "Børnepsykiatri";
$array["tropemedicin"] = "Tropemedicin";
$array["med_laboratorier_kpll"] = "KPLL";
$array["med_laboratorier"] = "Med. laboratorier";
$array["omegnslaboratorier"] = "Omegnslaboratorier";
$array["med_laboratorier_ssi"] = "SSI";
$array["tandplejere"] = "Tandplejere";
$array["tandlaege"] = "Tandlæge";
$array["fysioterapi"] = "Fysioterapi";
$array["briller"] = "Briller";
$array["kiropraktor"] = "Kiropraktor";
$array["fodterapi"] = "Fodterapi";
$array["fodbehandlking"] = "Fodbehandling";
$array["ridefysioterapi"] = "Ridefysioterapi";
$array["teddy"] = "Teddy Øfeldt";
$array["fodterapi_radioaktiv"] = "Fodterapi - følger radioaktiv bestråling";
$array["fodterapi_leddegigt"] = "Fodterapi - svær leddegigt";
$array["fysioterapi_vederlagsfri"] = "Vederlagsfri fysioterapi";
$array["psykolog"] = "Psykolog";
$array["kiropraktor_64"] = "Kiropraktik - ordning 64";
$array["ridefysioterapi_vederlagsfri"] = "Vederlagsfri ridefysioterapi";
$array["almenlaege_laegevagt"] = "Almenlæge og lægevagt";
$array["vagtlaege"] = "Almenlæge og lægevagt";
$array["almenlaege_vagtkoersel"] = "Almen lægers vagtkørsel";
$array["almenlaege_vagtlaegehjaelp"] = "Vagtlægehjælp, region hovedstaden";
$array["vagtlaegehjaelp_kbh"] = "Vagtlægehjælp, region hovedstaden";
$array["vagtlaegehjaelp"] = "Vagtlægehjælp";
return $array;
}
private function getData($type, $request, $journal = false) {
$this->type = $type;
$this->auth($request);
//$medcomList = $this->getMedComData();
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$medcom = $repo->getMedcomList("5790001365165");
$_medcom = $repo->getMedcomListentity("Mohsen Dasdar");
$corr = $repo->fetechCorrespondences($this->type, $journal);
$templateName = "index.html.twig";
return $this->render('medcom/'.$templateName, array(
'journal' => $journal,
'patientObj' => $this->patientObj,
'dialogueObj' => $this->dialogueObj,
'areaNames' => $this->areaNames,
'dateDiff' => $this->dateDiff,
'type' => $this->type,
'cor' => $corr,
'info' => $this->Info,
'medcomSpecialtyCodes' => $this->getMedComSpecialtyCodes(),
));
}
public function uploadList(Request $request) {
set_time_limit(0);
$this->auth($request);
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$file = fopen("medcom.csv","r");
$_lineCount = 0;
$keys = array();
$medcomList = array();
while(($line = fgets($file)) !== false)
{
$t = explode(";",$line);
$medcomrow = array();
for($i=0;$i<count($t);$i++) {
if($_lineCount != 0) {
$key = count($keys)-1<$i ? $i : $keys[$i];
//$medcomList[($_lineCount-1)][$key] = $t[$i];
$medcomrow[$key] = utf8_encode($t[$i]);
} else {
$keys[$i] = $t[$i];
}
}
if($_lineCount != 0 && ($_lineCount > 75000 && $_lineCount < 80000)) {
$obj = $medcomrow;
$ean = $obj["EanLocationCode"];
if($ean != null || $ean != "") {
$repo->insertList(null, $obj["EntityName"], $obj["PostalAddress"], $obj["P_Postnummer"], $obj["PostalDistrictName"], $obj["PostalDistrictName"], $obj["SorId"], $ean);
}
}
$_lineCount++;
}
fclose($file);
return $this->redirectToRoute("medcom_index");
//
/*set_time_limit(0);
$this->auth($request);
$medcomList = $this->getMedComData();
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
foreach($medcomList as $obj) {
$ean = ($obj["EanLocationCode"] != null || $obj["EanLocationCode"] != "" ? $obj["EanLocationCode"] : (isset($this->ean[$obj["ParentSorId"]]) ? $this->ean[$obj["ParentSorId"]] : ""));
$repo->insertList($obj["ParentSorEntityName"], $obj["EntityName"], $obj["PostalAddress"], $obj["PostalPostCodeId"], $obj["PostalDistrictName"], $obj["PostalDistrictName"], $obj["SorId"], $ean);
}
return $this->redirectToRoute("medcom_index");*/
}
public function journal(Request $request) {
return $this->getData(3, $request, true);
}
public function index(Request $request) {
return $this->getData(3, $request);
}
public function outbox(Request $request) {
return $this->getData(2, $request);
}
public function drafts(Request $request) {
return $this->getData(1, $request);
}
public function journalize(Request $request) {
$this->auth($request);
$searchFilter = "ROLE_DTS";
if ($this->user->hasRole('ROLE_CSV')) {
$searchFilter = "ROLE_CSV";
}
$predefinedCaseCardAll = $this->em->getRepository(PredefinedCaseCard::class)->findBy(array('userType' => $searchFilter, 'isForIndividual' => 1));
$joGroupObj = NULL;
if($this->dialogueObj != null) {
if(($this->dialogueObj->getDialogueType() == 3 || $this->dialogueObj->getDialogueType() == 4) && $searchFilter == "ROLE_DTS" ) {
$joGroupObj = $this->em->getRepository(JoGroup::class)->findOneBy(array('Dialogue' => $this->dialogueObj));
$predefinedCaseCardAll = $this->em->getRepository(PredefinedCaseCard::class)->fetchGroupPredefinedCaseCardListByType($searchFilter, $joGroupObj->getJoMasterInformation()->getInfoType(), $joGroupObj->getJoMasterInformation()->getKkorg());
} else if(($this->dialogueObj->getDialogueType() == 4) && $searchFilter == "ROLE_CSV" ) {
$joGroupObj = $this->em->getRepository(JoGroup::class)->findOneBy(array('Dialogue' => $this->dialogueObj));
$predefinedCaseCardAll = $this->em->getRepository(PredefinedCaseCard::class)->findBy(array('userType' => $searchFilter, 'isForGroup' => 1));
}
}
$dialogueCaseCardAll = $this->em->getRepository(DialogueCaseCard::class)->findBy(array('dialogue' => $this->dialogueObj));
$userCreatedCaseCardsId = $userCreatedDialogueCaseCard = array();
foreach ($dialogueCaseCardAll as $dialogueCaseCard) {
if (!$dialogueCaseCard->getIsClosed()) {
$userCreatedCaseCardsId[] = $dialogueCaseCard->getPCaseCardId()->getId();
$userCreatedDialogueCaseCard[$dialogueCaseCard->getPCaseCardId()->getId()] = $dialogueCaseCard;
}
}
$dialogueCaseCardMeasureAll = $this->em->getRepository(DialogueCaseCardMeasure::class)->fetchMeasureTilDateMedcom('F',new \DateTime());
return $this->render('medcom/_journalize.twig', array(
'thisID' => $request->get("id"),
"userCreatedDialogueCaseCard" => $userCreatedDialogueCaseCard,
'predefinedCaseCardAll' => $predefinedCaseCardAll,
'dialogueCaseCardMeasureAll' => $dialogueCaseCardMeasureAll,
'userCreatedCaseCardsId' => $userCreatedCaseCardsId,
'patientObj' => $this->patientObj,
'dialogueObj' => $this->dialogueObj,
'areaNames' => $this->areaNames,
'dateDiff' => $this->dateDiff,
'info' => $this->Info
));
}
public function journalized(Request $request) {
$this->auth($request);
$id = $request->get("id");
$repo = $this->em->getRepository(MedComCorrespondence::class);
$_cor = $repo->fetechCorrespondenceJournal($id);
if($id != null && $id != 0 && count($_cor) != 0) {
$cor = $_cor[0];
return $this->render('medcom/_journalized.twig', array(
'journal' => true,
'patientObj' => $this->patientObj,
'dialogueObj' => $this->dialogueObj,
'areaNames' => $this->areaNames,
'dateDiff' => $this->dateDiff,
'type' => "3",
'thisID' => $request->get("id"),
'cor' => $_cor,
'info' => $this->Info,
'medcomSpecialtyCodes' => $this->getMedComSpecialtyCodes(),
));
}
}
public function saveJournalize(Request $request) {
$this->auth($request);
$id = $request->get('id');
$repo = $this->em->getRepository(MedComCorrespondence::class);
$_cor = $repo->fetechCorrespondence($id);
if($id != null && $id != 0 && count($_cor) != 0) {
$cor = $_cor[0];
$dialogueCaseCard = $request->get('dialogueCaseCard');
$predefinedCaseCardId = $request->get('predefinedCaseCardId');
$dialogueCaseCardMeasureId = $request->get('dialogueCaseCardMeasureId');
$measureId = $request->get('measureId');
$dialogueCaseCardObj = $this->em->getRepository(DialogueCaseCard::class)->find($dialogueCaseCard);
$predefinedCaseCardObj = $this->em->getRepository(PredefinedCaseCard::class)->find($predefinedCaseCardId);
$predefinedAttachmentTypeObj = $this->em->getRepository(PredefinedAttachmentType::class)->findOneBy(array('attachmentType' => 'medcom')); //Medcom
$dialogueAttachmentDetailObj = new DialogueAttachmentDetails();
$dialogueAttachmentDetailObj->setPCaseCardId($predefinedCaseCardObj);
$dialogueAttachmentDetailObj->setPatient($this->patientObj);
$dialogueAttachmentDetailObj->setDialogue($this->dialogueObj);
if($dialogueCaseCardObj){
$dialogueAttachmentDetailObj->setDialogueCaseCard($dialogueCaseCardObj);
}
$dialogueCaseCardMeasureObj = $this->em->getRepository(DialogueCaseCardMeasure::class)->find($dialogueCaseCardMeasureId);
$dialogueAttachmentDetailObj->setDialogueCaseCardMeasureId($dialogueCaseCardMeasureObj);
$caseCardMeasureObj = $this->em->getRepository(CasecardMeasure::class)->find($measureId);
$dialogueAttachmentDetailObj->setMeasureId($caseCardMeasureObj);
$dialogueAttachmentDetailObj->setUser($this->user);
$dialogueAttachmentDetailObj->setPAtttachmentType($predefinedAttachmentTypeObj);
if($this->dialogueObj->getDialogueType() == 1 || $this->dialogueObj->getDialogueType() == 2){
$dialogueAttachmentDetailObj->setAttachmentDate(new \DateTime());
}else{
$dialogueAttachmentDetailObj->setAttachmentDate($cor->getUpdatedAt());
}
$dialogueAttachmentDetailObj->setIsDraft(false);
$dialogueAttachmentDetailObj->setVisibleStatus(0);
$dialogueAttachmentDetailObj->setActivityType(11);
$heading = $cor->getSubject();
$dialogueAttachmentDetailObj->setAttachmentHeading($heading);
$this->em->persist($dialogueAttachmentDetailObj);
$this->em->flush();
$ccID = $dialogueAttachmentDetailObj->getId();
$cor->journalize($ccID);
$this->em->persist($cor);
$this->em->flush();
return new Response(json_encode('success:'.$ccID), Response::HTTP_OK,['content-type' => "text/json"]);
}
return new Response(json_encode('error:true'), Response::HTTP_OK,['content-type' => "text/json"]);
}
public function send(Request $request) {
$this->auth($request);
$type = ($request->get("submit") == "send" ? 2 : 1);
$type = ($request->get("submit") == "inbox" ? 3 : $type);
//$obj = $this->em->getRepository(MedComCorrespondence::class);
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
//$this->getMedComData();
//$medcom = $this->getMedComData($request->get("medcom_user"));
$cor;
if($request->files->get("new_medcom_file") != null) {
//$ean = ($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : (isset($this->ean[$medcom["ParentSorId"]]) ? $this->ean[$medcom["ParentSorId"]] : ""));
$cor = $repo->insert($request->get("medcom_user"), $request->get("subject"), $this->user, $this->patientObj, $request->get("priority"), $request->get("message"), $type,false);
$i = 1;
foreach($request->files->get("new_medcom_file") as $f) {
$file = file_get_contents($f);
$ext = pathinfo($f->getClientOriginalName(), PATHINFO_EXTENSION);
$filename = pathinfo($f->getClientOriginalName(), PATHINFO_FILENAME);
$base = base64_encode($file);
$filesize = filesize($f);
$obj = $repo->insertFileOnly($filesize,$request->get("medcom_user"), $this->user, $this->patientObj,$type,$filename,$ext,$base,$cor,$request->get("priority"));
$obj->setParentID($repo->lastMessageID);
$this->em->persist($obj);
$this->em->flush();
if($request->get("submit") != 2) {
$medcom = $repo->getMedcomList($cor->getMedComUser());
$ean = $medcom->getEAN();
$_xml = $this->getXmlbin01($obj,$medcom);
$xml = $this->getVansXml($_xml, "xbin01", $ean, $repo);
$myfile = fopen("Medcom/Out/".$repo->lastMessageID."_file".$i.".xml", "w") or die("Unable to open file!");
fwrite($myfile, $xml->asXML());
fclose($myfile);
$i++;
}
}
} else {
$cor = $repo->insert($request->get("medcom_user"), $request->get("subject"), $this->user, $this->patientObj, $request->get("priority"), $request->get("message"), $type);
}
if($request->get("submit") != 2) {
$medcom = $repo->getMedcomList($cor->getMedComUser());
$ean = $medcom->getEAN();
$_obj = $repo->fetechMessage($repo->lastMessageID);
$obj = $_obj[0];
$files = $repo->fetechMessageParent($repo->lastMessageID);
$_xml = $this->getXmlDis91($obj, $cor, $medcom, $files);
$xml = $this->getVansXml($_xml, "xdis91", $ean, $repo);
$myfile = fopen("Medcom/Out/".$repo->lastMessageID.".xml", "w") or die("Unable to open file!");
fwrite($myfile, $xml->asXML());
fclose($myfile);
}
return new Response(json_encode('success:'.$repo->lastMessageID), Response::HTTP_OK,['content-type' => "text/json"]);
}
public function sendDraft(Request $request) {
$this->auth($request);
//$obj = $this->em->getRepository(MedComCorrespondence::class);
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$id = $request->get("objID");
$_msg = $repo->fetechMessage($id);
if($_msg != null) {
$msg = $_msg[0];
$cor = $msg->getCorrospondence();
$msg->sendDraft();
$this->em->persist($msg);
$this->em->flush();
$cor->sendDraft();
$this->em->persist($cor);
$this->em->flush();
$medcom = $repo->getMedcomList($cor->getMedComUser());
$ean = $medcom->getEAN();
$files = $repo->fetechMessageParent($id);
$_xml = $this->getXmlDis91($msg, $cor, $medcom, $files);
$xml = $this->getVansXml($_xml, "xdis91", $ean, $repo);
$myfile = fopen("Medcom/Out/".$id.".xml", "w") or die("Unable to open file!");
fwrite($myfile, $xml->asXML());
fclose($myfile);
$i = 1;
foreach($files as $file) {
$_xml = $this->getXmlbin01($file,$medcom);
$xml = $this->getVansXml($_xml, "xbin01", $ean, $repo);
$_myfile = fopen("Medcom/Out/".$id."_file".$i.".xml", "w") or die("Unable to open file!");
fwrite($_myfile, $xml->asXML());
fclose($_myfile);
$i++;
}
} else {
return $this->redirectToRoute("medcom_drafts");
}
return $this->redirectToRoute("medcom_index");
}
public function edi(Request $request) {
}
private function getVansXml($xml, $code, $ean,$repo) {
$baseData = base64_encode($xml);
$size = (int) (strlen(rtrim($baseData, '=')) * 3 / 4);
$env = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><VANSEnvelope />');
$env->addAttribute("xmlns", "urn:oio:medcom:vans-envelope:1.0.4");
$esend = $env->addChild('SenderID', $this->EANS);
$esend->addAttribute("EndPointType", "EAN");
$erec = $env->addChild('ReceiverID', $ean);
$erec->addAttribute("EndPointType", "EAN");
$env->addChild('EnvelopeIdentifier', $repo->create_guid());
$env->addChild('SentDateTime', date("Y-m-d")."T".date("H:i:s"));
$message = $env->addChild("Message");
$meta = $message->addChild('MetaInformation');
$meta->addChild('Identifier', $repo->create_guid());
$doc = $meta->addChild('Document');
$doc->addChild('Format', "XML");
if($code == "xdis91") {
$doc->addChild('Name','MCM:XDIS19');
$doc->addChild('Version', "XD9134L");
}
elseif($code == "xctl02") {
$doc->addChild('Name','MCM:XCTL02');
$doc->addChild('Version', "XC0230Q");
}
elseif($code == "xctl03") {
$doc->addChild('Name','MCM:XCTL03');
$doc->addChild('Version', "XC0330Q");
}
elseif($code == "xbin01") {
$doc->addChild('Name','MCM:XBIN01');
$doc->addChild('Version', "XB0131X");
}
$doc->addChild('SizeInBytes', $size);
$data = $message->addChild('Data', $baseData);
return $env;
}
public function vans(Request $request, $code, $_id = null, $_refuseCode = null, $_refuseText = null, $_ean = null) {
$this->auth($request);
$id = ($_id != null ? $_id : $request->get("id"));
$refuseText = ($_refuseText != null ? $_refuseText : $request->get("RefuseText"));
$refuseCode = ($_refuseCode != null ? $_refuseCode : $request->get("RefuseCode"));
if($id != null) {
//$obj = $this->em->getRepository(MedComMessages::class)->findOneBy(array('id' => intval($id))); $repo = $this->em->getRepository(MedComCorrespondence::class);
//$obj = $this->em->getRepository(MedComMessages::class)->createQueryBuilder("m")->where("m.id LIKE :id")->setParameter("id",$id)->getQuery()->getResult();
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$_obj = $repo->fetechMessage($id);
if(count($_obj) != 0) {
$obj = $_obj[0];
$cor = $obj->getCorrospondence();
/*$this->getMedComData();
$medcom = null;
if($cor != null)
$medcom = $this->getMedComData($cor->getMedComUser());
$ean = ($_ean != null ? $_ean : ($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : $this->ean[$medcom["ParentSorId"]]));
$ean = ($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : $this->ean[$medcom["ParentSorId"]]);
*/
$medcom = $repo->getMedcomList($cor->getMedComUser());
$ean = $medcom->getEAN();
$orgVersionCode = (strtolower($obj->getType()) == "bilag" ? "XB0131X" : "XD9134L");
$files = $repo->fetechMessageParent($id);
if($code == "xdis91")
$_xml = $this->getXmlDis91($obj, $cor, $medcom, $files);
elseif($code == "xctl02")
$_xml = $this->getXmlctl02($obj, $cor, $medcom, $ean,$orgVersionCode, $refuseCode, $refuseText);
elseif($code == "xctl03")
$_xml = $this->getXmlctl03($obj, $cor, $medcom, $ean);
elseif($code == "xbin01")
$_xml = $this->getXmlbin01($obj, $medcom);
else
return new Response("ERROR");
$xml = $_xml->asXML();
$env = $this->getVansXml($xml, $code, $ean, $repo);
/*$baseData = base64_encode($xml);
$size = (int) (strlen(rtrim($baseData, '=')) * 3 / 4); $env = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><VANSEnvelope />');
$env->addAttribute("xmlns", "urn:oio:medcom:vans-envelope:1.0.4");
//$env->addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
//$env->addAttribute("xmlns:schemaLocation", "urn:oio:medcom:vans-envelope:1.0.4 http://svn.medcom.dk/svn/drafts/VANSEnvelope/VANSEnvelope_1.0.4.xsd");
$esend = $env->addChild('SenderID', $this->EANS);
$esend->addAttribute("EndPointType", "EAN");
$erec = $env->addChild('ReceiverID', $ean);
$erec->addAttribute("EndPointType", "EAN");
$env->addChild('EnvelopeIdentifier', $repo->create_guid());
$env->addChild('SentDateTime', date("Y-m-d")."T".date("H:i:s"));
$message = $env->addChild("Message");
$meta = $message->addChild('MetaInformation');
$meta->addChild('Identifier', $repo->create_guid());
$doc = $meta->addChild('Document');
$doc->addChild('Format', "XML");
if($code == "xdis91") {
$doc->addChild('Name','MCM:XDIS19');
$doc->addChild('Version', "XD9134L");
}
elseif($code == "xctl02") {
$doc->addChild('Name','MCM:XCTL02');
$doc->addChild('Version', "XC0230Q");
}
elseif($code == "xctl03") {
$doc->addChild('Name','MCM:XCTL03');
$doc->addChild('Version', "XC0330Q");
}
elseif($code == "xbin01") {
$doc->addChild('Name','MCM:XBIN01');
$doc->addChild('Version', "XB0131X");
}
$doc->addChild('SizeInBytes', $size);
$data = $message->addChild('Data', $baseData);*/
$vans_exist = $repo->fetechMessageParentVans($obj->getId(),$code);
if(true) {
$vans = MedComMessages::withInsert($code,$ean,null,$cor,4,'Vans'.$code,false);
$vans->setFileData($env->asXML());
$vans->setParentID($obj->getId());
$this->em->persist($vans);
$this->em->flush();
if(count($vans_exist) != 0) {
$vans_exist[0]->setType("VansExpired");
$this->em->persist($vans_exist[0]);
$this->em->flush();
}
}
$res = new Response($env->asXML(), Response::HTTP_OK,['content-type' => "text/xml"]);
$res->setCharset('ISO-8859-1');
return $res;
}
return new Response("ERROR");
}
return new Response("ERROR");
}
public function _receiveVans(Request $request) {
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$files = scandir('Medcom/In');
foreach($files as $file) {
if(is_dir('Medcom/In/'.$file) == false) {
$xml_ = simplexml_load_file('Medcom/In/'.$file);
$xml = ($xml_->VANSEnvelope != null && $xml_->VANSEnvelope != "" ? $xml_->VANSEnvelope : $xml_);
$ean = $xml->SenderID;
$EnvelopeIdentifier = $xml->EnvelopeIdentifier;
$code = $xml->Message->MetaInformation->Document->Version;
$id = 0;
$_xml;
$messageBase = $xml->Message->Data;
$message = base64_decode($messageBase);
$check_size_in_bytes = (int) (strlen(rtrim($message, '=')) * 3 / 4);
//var_dump($check_size_in_bytes);
//exit;
$vans = MedComMessages::withInsert($code,$ean,null,null,4,'Vans',false);
$vans->setFileData($xml->asXML());
$this->em->persist($vans);
$this->em->flush();
$var = $this->receiveXml($request, $message);
if($var != null) {
$myfile = fopen("Medcom/Out/".$EnvelopeIdentifier.".kvittering.xml", "w") or die("Unable to open file!");
fwrite($myfile, $var->asXML());
fclose($myfile);
}
unlink('Medcom/In/'.$file);
}
}
}
public function receiveVans(Request $request) {
exit;
}
public function xml(Request $request) {
$this->auth($request);
$id = $request->get("id");
if($id != null) {
//$obj = $this->em->getRepository(MedComMessages::class)->findOneBy(array('id' => intval($id))); $repo = $this->em->getRepository(MedComCorrespondence::class);
//$obj = $this->em->getRepository(MedComMessages::class)->createQueryBuilder("m")->where("m.id LIKE :id")->setParameter("id",$id)->getQuery()->getResult();
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$_obj = $repo->fetechMessage($id);
if(count($_obj) != 0) {
$obj = $_obj[0];
$cor = $obj->getCorrospondence();
//$this->getMedComData();
//$medcom = $this->getMedComData($cor->getMedComUser());
$medcom = $repo->getMedcomList($cor->getMedComUser());
$files = $repo->fetechMessageParent($id);
$last9 = $repo->fetechMessageLast9($id,$cor);
$emssage = $this->getXmlDis91($obj, $cor, $medcom,$files,$last9);
$res = new Response($emssage->asXML(), Response::HTTP_OK,['content-type' => "text/xml"]);
$res->setCharset('ISO-8859-1');
return $res;
}
return new Response("ERROR");
}
return new Response("ERROR");
}
public function xml02(Request $request, $_id = null, $_refuseText = null, $_refuseCode = null, $_ean = null, $_orgVersionCode = null) {
$this->auth($request);
$id = ($_id != null ? $_id : $request->get("id"));
$refuseText = ($_refuseText != null ? $_refuseText : $request->get("RefuseText"));
$refuseCode = ($_refuseCode != null ? $_refuseCode : $request->get("RefuseCode"));
if($id != null) {
//$obj = $this->em->getRepository(MedComMessages::class)->findOneBy(array('id' => intval($id))); $repo = $this->em->getRepository(MedComCorrespondence::class);
//$obj = $this->em->getRepository(MedComMessages::class)->createQueryBuilder("m")->where("m.id LIKE :id")->setParameter("id",$id)->getQuery()->getResult();
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$_obj = $repo->fetechMessage($id);
if($_obj != null && count($_obj) != 0) {
$obj = $_obj[0];
$cor = $obj->getCorrospondence();
$orgVersionCode = ($_orgVersionCode != null ? $_orgVersionCode : (strtolower($obj->getType()) == "bilag" ? "XB0131X" : "XD9134L"));
//$this->getMedComData();
/*$medcom = null;
/*if($cor != null)
$medcom = $this->getMedComData($cor->getMedComUser());
$ean = ($_ean != null ? $_ean : ($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : $this->ean[$medcom["ParentSorId"]]));
*/
$medcom = $repo->getMedcomList($cor->getMedComUser());
$ean = $medcom->getEAN();
$emssage = $this->getXmlctl02($obj,$cor,$medcom,$ean,$orgVersionCode,$refuseCode,$refuseText);
$res = new Response($emssage->asXML(), Response::HTTP_OK,['content-type' => "text/xml"]);
$res->setCharset('ISO-8859-1');
return $res;
}
return new Response("ERROR");
}
return new Response("ERROR");
}
public function xml03(Request $request, $_id = null, $_ean = null) {
$this->auth($request);
$id = ($_id != null ? $_id : $request->get("id"));
if($id != null) {
//$obj = $this->em->getRepository(MedComMessages::class)->findOneBy(array('id' => intval($id))); $repo = $this->em->getRepository(MedComCorrespondence::class);
//$obj = $this->em->getRepository(MedComMessages::class)->createQueryBuilder("m")->where("m.id LIKE :id")->setParameter("id",$id)->getQuery()->getResult();
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$_obj = $repo->fetechMessage($id);
if(count($_obj) != 0) {
$obj = $_obj[0];
$cor = $obj->getCorrospondence();
//$this->getMedComData();
/*$medcom = null;
if($cor != null)
$medcom = $this->getMedComData($cor->getMedComUser());
$ean = ($_ean != null ? $_ean : ($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : $this->ean[$medcom["ParentSorId"]]));
*/
$medcom = $repo->getMedcomList($cor->getMedComUser());
$ean = $medcom->getEAN();
$emssage = $this->getXmlctl03($obj,$cor,$medcom,$ean);
$res = new Response($emssage->asXML(), Response::HTTP_OK,['content-type' => "text/xml"]);
$res->setCharset('ISO-8859-1');
return $res;
}
return new Response("ERROR");
}
return new Response("ERROR");
}
public function xml04(Request $request) {
$this->auth($request);
$id = $request->get("id");
if($id != null) {
//$obj = $this->em->getRepository(MedComMessages::class)->findOneBy(array('id' => intval($id))); $repo = $this->em->getRepository(MedComCorrespondence::class);
//$obj = $this->em->getRepository(MedComMessages::class)->createQueryBuilder("m")->where("m.id LIKE :id")->setParameter("id",$id)->getQuery()->getResult();
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$_obj = $repo->fetechMessage($id);
if(count($_obj) != 0) {
$obj = $_obj[0];
$cor = $obj->getCorrospondence();
//$this->getMedComData();
//$medcom = $this->getMedComData($cor->getMedComUser());
$medcom = $repo->getMedcomList($cor->getMedComUser());
$emssage = $this->getXmlbin01($obj,$medcom);
$res = new Response($emssage->asXML(), Response::HTTP_OK,['content-type' => "text/xml"]);
$res->setCharset('ISO-8859-1');
return $res;
}
return new Response("ERROR");
}
return new Response("ERROR");
}
public function receiveXml(Request $request, $vansXml = null) {
$this->em = $this->getDoctrine()->getManager();
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
if (file_exists('import.xml') || $vansXml != null) {
$xml_ = ($vansXml != null ? simplexml_load_string($vansXml) : simplexml_load_file('import.xml'));
$xml = ($xml_->Emessage != null && $xml_->Emessage != "" ? $xml_->Emessage : $xml_);
$id = 0;
$_xml;
$moveFoward = true;
if(isset($xml->ClinicalEmail) && $xml->ClinicalEmail !== null && $xml->ClinicalEmail !== "") {
$moveFoward = false;
$_xml = $xml->ClinicalEmail;
$id = $xml->Letter->EpisodeOfCareIdentifier;
if($id === "" && $id === "")
$id = str_replace("-","",$repo->create_guid());;
$_obj = $repo->fetechCorrespondenceUUID($id);
$_message = "";
$subject = $_xml->AdditionalInformation->Subject;
$cpr = $_xml->Patient->CivilRegistrationNumber;
$sender = $_xml->Sender->EANIdentifier;
$receiver = $_xml->Receiver->EANIdentifier;
$_MedicalSpecialityCode = $_xml->Sender->MedicalSpecialityCode;
$MedicalSpecialityCode = ($_MedicalSpecialityCode !== null && $_MedicalSpecialityCode !== "" ? $_MedicalSpecialityCode : null);
$envID = $xml->Envelope->Identifier;
$letterID = $_xml->Letter->Identifier;
$VersionCode = $_xml->Letter->VersionCode;
$TypeCode = $_xml->Letter->TypeCode;
$_prio = $_xml->AdditionalInformation->Priority;
$prio = ($_prio == "høj_prioritet" ? true : false);
foreach($xml->ClinicalEmail->ClinicalInformation->Text01 as $_txt) {
$_message .= strip_tags($_txt->asXml(), "<Break>");
}
$message = str_replace("<Break/>", "\r\n", $_message);
$message = str_replace("<Break />", "\r\n", $message);
$message = str_replace("<break/>", "\r\n", $message);
$message = str_replace("<break />", "\r\n", $message);
$_error = false;
$_id = $letterID;
$_refuseCode = "ikke_specificeret";
$_refuseText;
$_ean = null;
$medcom;
//if(!isset($receiver) || $receiver == null || $receiver == "" && $receiver == $this->EANS) { $_refuseCode = "problem_med_modtagerID"; $_refuseText = "Denne meddelelse er sendt til forkert modtager"; $_error = true; }
if(!isset($subject) || $subject == null || $subject == "") { $subject = "ikke_specificeret"; $_refuseText = "Emnetekst mangler"; $_error = true; }
if(!isset($cpr) || $cpr == null || $cpr == "") { $_refuseText = "cpr mangler"; $_error = true; }
if(!isset($sender) || $sender == null || $sender == "") { $sender = "ikke_specificeret"; $_refuseText = "EANIdentifier for sender mangler"; $_error = true; } else {
$medcom = $repo->getMedcomList($sender);
$_ean=$sender;
if($medcom == null) {
$sender = "ikke_specificeret"; $_refuseText = "EANIdentifier for sender er ikke i Sor Liste"; $_error = true;
}
/*$medcom = $this->getMedComData($sender);
if(!isset($medcom["SorId"]) || $medcom["SorId"] == null || $medcom["SorId"] == "") { $sender = "ikke_specificeret"; $_refuseText = "EANIdentifier for sender er ikke i Sor Liste"; $_error = true; } else {
$medcom_user = $medcom["SorId"];
}*/
}
if(!isset($letterID) || $letterID == null || $letterID == "") { $_refuseText = "Brev id mangler for sender mangler"; $_error = true; }
if(!isset($_prio) || $_prio == null || $_prio == "") { $_refuseText = "Prioritet mangler"; $_error = true; }
if(!isset($VersionCode) || $VersionCode == null || $VersionCode == "" || $VersionCode != "XD9134L") { $_refuseCode = "problem_med_version"; $_refuseText = "Ugyldig VersionCode ".$VersionCode." understoettes ikke"; $_error = true; }
if(!isset($TypeCode) || $TypeCode == null || $TypeCode == "" || $TypeCode != "XDIS91") { $_refuseText = "Ugyldig TypeCode ".$TypeCode." understoettes ikke"; $_error = true; }
$msg_exist = $repo->fetechMessageUUID($letterID);
$m_id = 0;
$cor;
if(count($_obj) != 0) {
$cor = $_obj[0];
$m = MedComMessages::withInsert($message,"",null,$cor,3,'Korrespondancebrev',$prio);
$m->setMedicalSpecialityCode($MedicalSpecialityCode);
$m->setDeleted(($_error ? true : false)); $m->setUUID($letterID); $m->setEUUID($envID); $this->em->persist($m); $this->em->flush();
$m_id=$m->getId();
$cor->setDeleted(($_error ? true : false)); $cor->setStatus(3); $this->em->persist($cor); $this->em->flush();
} else {
$this->patientObj = $this->em->getRepository(Patient::class)->findOneBy(array('cpr' => $cpr));
$cor = $repo->insertUUID($sender, $subject, null, $this->patientObj, $prio, $message, 3, $id, $letterID, $envID, $MedicalSpecialityCode);
$cor->setDeleted(($_error ? true : false)); $this->em->persist($cor); $this->em->flush();
$m_id=$repo->lastMessageID;
}
foreach($_xml->Reference as $ref) {
if(isset($ref->RefDescription) && $ref->RefDescription == "BIN") {
$this->patientObj = $this->em->getRepository(Patient::class)->findOneBy(array('cpr' => $cpr));
$VersionCode = $ref->Letter->VersionCode;
$ext = $ref->BIN->ObjectExtensionCode;
$filesize = $ref->BIN->OriginalObjectSize;
$date = date_create();
$_objID = $ref->BIN->ObjectIdentifier;
$objID = $repo->guid_line($_objID);
$_extFile = $repo->fetechMessageFileGUID($objID,"true");
if(count($_extFile) != 0) {
$obj = $_extFile[0];
$old_cor = $obj->getCorrospondence();
if($old_cor != null && count($old_cor) != 0) {
$old_cor->setDeleted(true);
$this->em->persist($old_cor);
$this->em->flush();
}
$obj->setCor($cor);
$obj->setParentID($m_id);
}
else {
$obj = $repo->insertFileOnly($filesize,$sender,null,$this->patientObj,3,"bilag.".date_timestamp_get($date),$ext,null,$cor,false,$objID);
$obj->setParentID($m_id);
}
//$obj = $repo->insertFileOnly($filesize,$_xml->Sender->Identifier, null, $this->patientObj, 3, "bilag.".$ext,$ext,$_xml->BinaryObject->Object_Base64Encoded);
$obj->setDeleted(($_error ? true : false));
$_id = $obj->getId();
$this->em->persist($obj);
$this->em->flush();
}
}
if(count($msg_exist) == null || count($msg_exist) == 0 || $msg_exist[0]->getReceipt() != true || ($msg_exist !== null && $msg_exist[0]->getEUUID() != $envID)) {
$msg = null;
if($_error) {
$msg = $repo->fetechMessageUUID($letterID);
$msg[0]->setReceipt(true);
$this->em->persist($msg[0]);
$this->em->flush();
$_id = $msg[0]->getID();
//send it
if($vansXml != null) {
$_xdisXml = $this->getXmlctl02($msg[0],$cor,null,$sender,$VersionCode,$_refuseCode,$_refuseText);
return $this->getVansXml($_xdisXml, "xctl02", $sender, $repo);
//return $this->vans($request,"xctl02",$_id,$_refuseText,$_refuseCode,$_ean);
}
return $this->xml02($request,$_id,$_refuseText,$_refuseCode,$_ean,$VersionCode.'');
} else {
$msg = $repo->fetechMessageUUID($letterID);
$msg[0]->setReceipt(true);
$this->em->persist($msg[0]);
$this->em->flush();
$_id = $msg[0]->getID();
//send it
if($vansXml != null) {
$_xdisXml = $this->getXmlctl03($msg[0],$cor,null,$sender);
return $this->getVansXml($_xdisXml, "xctl03", $sender, $repo);
//return $this->vans($request,"xctl03",$_id,"","",$sender);
}
return $this->xml03($request,$_id,$sender);
}
//set msg reciept to true here
} else {
//return new Response("ingen kvittering");
return null;
}
}
elseif(isset($xml->BinaryLetter) && $xml->BinaryLetter !== null && $xml->BinaryLetter !== "") {
$moveFoward = false;
$_error = false;
$_refuseCode = "ikke_specificeret";
$_refuseText;
$_xml = $xml->BinaryLetter;
$id = $xml->Envelope->Identifier;
//$_obj = $repo->fetechCorrespondenceUUID($id);
//$cor = null;
//if(count($_obj) != 0) {
// $cor = $_obj[0];
//}
$cpr = $_xml->Patient->CivilRegistrationNumber;
$VersionCode = $_xml->Letter->VersionCode;
$sender = $_xml->Sender->EANIdentifier;
$envID = $xml->Envelope->Identifier;
$letterID = $_xml->Letter->Identifier;
$id = $xml->Letter->EpisodeOfCareIdentifier;
if($id === "" && $id === "")
$id = str_replace("-","",$repo->create_guid());;
if(!isset($cpr) || $cpr == null || $cpr == "") { $_refuseText = "cpr mangler"; $_error = true; }
if(!isset($VersionCode) || $VersionCode == null || $VersionCode == "" || $VersionCode != "XB0131X") { $_refuseCode = "problem_med_version"; $_refuseText = "Ugyldig VersionCode"; $_error = true; }
$this->patientObj = $this->em->getRepository(Patient::class)->findOneBy(array('cpr' => $cpr));
$ext = $_xml->BinaryObject->ObjectExtensionCode;
$filesize = $_xml->BinaryObject->OriginalObjectSize;
$baseData = $_xml->BinaryObject->Object_Base64Encoded;
$check_size_in_bytes = (int) (strlen(rtrim($baseData, '=')) * 3 / 4);
if(!isset($filesize) || $filesize == null || $filesize == "" || $filesize != $check_size_in_bytes) { $_refuseCode = "ikke_specificeret"; $_refuseText = "File stoerrelse stemmer ikke overens"; $_error = true; }
$date = date_create();
$objID = $_xml->BinaryObject->ObjectIdentifier;
$_extFile = $repo->fetechMessageFileGUID($objID);
$obj = null;
//check if filesize is what it says it is
$cor;
if(count($_extFile) != null) {
$extFile = $_extFile[0];
$cor = $extFile->getCorrospondence();
$obj = $repo->insertFileOnly($filesize,$sender,null,$this->patientObj,3,"bilag.".date_timestamp_get($date),$ext,$baseData,$cor,false,$objID);
$extFile->setDeleted(true);
$this->em->persist($extFile);
$this->em->flush();
} else {
$cor = $repo->insertUUID($sender, "Bilag uden meddelelse", null, $this->patientObj, false, "bilag uden meddelelse", 3, $id, $letterID, $envID);
$cor->setDeleted(($_error ? true : false)); $this->em->persist($cor); $this->em->flush();
$obj = $repo->insertFileOnly($filesize,$sender, null, $this->patientObj, 3, "bilag.".date_timestamp_get($date),$ext,$baseData,$cor,false,$objID);
$m_id=$repo->lastMessageID;
$obj->setParentID($m_id);
}
$obj->setDeleted(($_error ? true : false));
$_id = $obj->getId();
$this->em->persist($obj);
$this->em->flush();
if($_error) {
//send it
if($vansXml != null) {
$msg = $repo->fetechMessageUUID($letterID);
$_xdisXml = $this->getXmlctl02($msg[0],$cor,null,$sender,$VersionCode,$_refuseCode,$_refuseText);
return $this->getVansXml($_xdisXml, "xctl02", $sender, $repo);
} else {
if($cor != null)
return $this->xml02($request,$_id,$_refuseText,$_refuseCode);
return $this->xml02($request,$_id,$_refuseText,$_refuseCode,$sender->asXML());
}
} else {
//send it
if($vansXml != null) {
$msg = $repo->fetechMessageUUID($letterID);
$_xdisXml = $this->getXmlctl03($msg[0],$cor,null,$sender);
return $this->getVansXml($_xdisXml, "xctl03", $sender, $repo);
} else {
if($cor != null)
return $this->xml03($request,$_id);
return $this->xml03($request,$_id,$sender->asXML());
}
}
$moveFoward = false;
}
else if(isset($xml->NegativeReceipt) && $xml->NegativeReceipt !== null && $xml->NegativeReceipt !== "") {
$_xml = $xml->NegativeReceipt;
$id = $_xml->OriginalEmessage->OriginalLetter->OriginalLetterIdentifier;
}
else if(isset($xml->PositiveReceipt) && $xml->PositiveReceipt != null && $xml->PositiveReceipt !== "") {
$_xml = $xml->PositiveReceipt;
$id = $_xml->OriginalEmessage->OriginalLetter->OriginalLetterIdentifier;
}
else if(isset($xml->NegativeVansReceipt) && $xml->NegativeVansReceipt !== null && $xml->NegativeVansReceipt !== "") {
$_xml = $xml->NegativeVansReceipt;
$id = $_xml->OriginalEmessage->OriginalLetter->OriginalLetterIdentifier;
}
if($moveFoward) {
$_obj = $repo->fetechMessageUUID($id);
$code = $_xml->Letter->VersionCode;
$ean = $_xml->Sender->EANIdentifier;
if(count($_obj) != 0) {
$obj = $_obj[0];
$cor = $obj->getCorrospondence();
$delivered = true;
//$obj->setError(null);
//$obj->setErrorType(null);
if($_xml->OriginalEmessage->OriginalLetter->RefuseText != null && $_xml->OriginalEmessage->OriginalLetter->RefuseText != "") {
$rT = $_xml->OriginalEmessage->OriginalLetter->RefuseText;
$rC = $_xml->OriginalEmessage->OriginalLetter->RefuseCode;
$obj->setError($rC . ' - ' .str_replace("<Break/>","<br />",$rT));
$obj->setErrorType($code);
$delivered = false;
$cor->setStatus(3);
$this->em->persist($cor);
$this->em->flush();
}
if($_xml->OriginalEmessage->RefuseText != null && $_xml->OriginalEmessage->RefuseText != "") {
$rT = $_xml->OriginalEmessage->RefuseText;
$rC = $_xml->OriginalEmessage->RefuseCode;
$obj->setError('Afvist af VANS: '.$rC . ' - ' .str_replace("<Break/>","<br />",$rT));
$obj->setErrorType($code);
$delivered = false;
$cor->setStatus(3);
$this->em->persist($cor);
$this->em->flush();
}
$obj->setRecieptDate();
$obj->setDelivered($delivered);
$reciept = MedComMessages::withInsert($code,$ean,null,$cor,4,'Kvittering',false);
$reciept->setFileData($xml->asXML());
$this->em->persist($obj);
$this->em->flush();
$reciept->setParentID($obj->getId());
$this->em->persist($reciept);
$this->em->flush();
//return new Response('success', Response::HTTP_OK,['content-type' => "text/json"]);
return true;
}
$reciept = MedComMessages::withInsert($code,$ean,null,null,4,'Kvittering',false);
$reciept->setFileData($xml->asXML());
$this->em->persist($reciept);
$this->em->flush();
//return new Response('failure', Response::HTTP_OK,['content-type' => "text/json"]);
return false;
}
}
}
public function reply(Request $request) {
$this->auth($request);
$type = $request->get("type");//( == "send" ? 2 : 1);
//$obj = $this->em->getRepository(MedComCorrespondence::class);
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$cbj = $this->em->getRepository(MedComCorrespondence::class)->find($request->get("objID"));
$obj = $repo->reply($this->user, $request->get("message"), $request->get("priority"), $cbj,2);
return new Response(json_encode('success'), Response::HTTP_OK,['content-type' => "text/json"]);
//return $this->redirectToRoute(($request->get("submit") == "2" ? "medcom_outbox" : "medcom_index"));
}
public function delete(Request $request) {
$this->auth($request);
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$cbj = $this->em->getRepository(MedComCorrespondence::class)->find($request->get("objID"));
$repo->delete($cbj);
return new Response(json_encode('success'), Response::HTTP_OK,['content-type' => "text/json"]);
}
public function deleteMessage(Request $request) {
$this->auth($request);
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$cbj = $this->em->getRepository(MedComMessages::class)->find($request->get("objID"));
$repo->delete($cbj);
return new Response(json_encode('success'), Response::HTTP_OK,['content-type' => "text/json"]);
}
public function medcom_receivers(Request $request) {
$this->em = $this->getDoctrine()->getManager();
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$s = $request->get("search");
$_data = $repo->getMedcomListSearch($s);
$data = [];
foreach($_data as $_obj) {
$obj = $_obj[0];
$data[] = ["full" => $_obj["full"],"id" => $obj->getId(), "EAN" => $obj->getEAN(), "UUID" => $obj->getSorId(), "entity" => $obj->getEntityName(), "parent" => $obj->getParent(), "type" => $obj->getEntityTypeName(), "address" => $obj->getPostalAddress(), "district" => $obj->getPostalDistrictName(), "postal" => $obj->getPostalPostCodeId()];
}
return new Response(json_encode($data), Response::HTTP_OK,['content-type' => "text/json"]);
}
public function resendMessage(Request $request) {
$this->auth($request);
$repo = $this->em->getRepository(MedComCorrespondence::class);
$repo->setEm($this->em);
$cbj = $this->em->getRepository(MedComMessages::class)->find($request->get("objID"));
//resend
//new ids
return $this->redirectToRoute("medcom_index");
$referer = $request->headers->get('referer');
$baseUrl = $request->getBaseUrl();
$lastPath = substr($referer, strpos($referer, $baseUrl) + strlen($baseUrl));
return $this->get('router')->getMatcher()->match($lastPath);
}
private function getXmlAddDatetimeChild($parent,$name) {
$child = $parent->addChild($name);
$child->addChild('Date', date("Y-m-d"));//datetime now
$child->addChild('Time', date("H:i"));//datetime now
}
private function getXmlStart($xmlns, $euuid) {
$emssage = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><Emessage />');
$emssage->addAttribute("xmlns", $xmlns);
$env = $emssage->addChild('Envelope');
$this->getXmlAddDatetimeChild($env,"Sent");
$env->addChild('Identifier', $euuid);
$env->addChild('AcknowledgementCode', "minuspositivkvitt");
return $emssage;
}
/*
$receiver->addChild("EANIdentifier",($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : $this->ean[$medcom["ParentSorId"]]));
$receiver->addChild("Identifier",$medcom["SorId"]);
$receiver->addChild("IdentifierCode","sygehusafdelingsnummer");
$receiver->addChild("OrganisationName",$medcom['EntityName']);
$receiver->addChild("DepartmentName",$medcom['EntityTypeName']);
$receiver->addChild("StreetName",$medcom['PostalAddress']);
$receiver->addChild("DistrictName",$medcom['PostalDistrictName']);
$receiver->addChild("PostCodeIdentifier",$medcom['PostalPostCodeId']);
*/
private function getXmlDis91($obj, $cor, $medcom,$files = null, $last9 = null) {
$emssage = $this->getXmlStart("http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2006/07/01/", $obj->getEUUID());
$cEmail = $emssage->addChild('ClinicalEmail');
$letter = $cEmail->addChild("Letter");
$letter->addChild('Identifier', $obj->getUUID());
$letter->addChild('VersionCode', "XD9134L");
$letter->addChild('StatisticalCode', "XDIS91");
$auth = $letter->addChild('Authorisation');
$auth->addChild('Date', date("Y-m-d")."");//datetime now
$auth->addChild('Time', date("H:i")."");//datetime now
$letter->addChild('TypeCode', "XDIS91");
$letter->addChild('StatusCode', "nytbrev");
$letter->addChild('EpisodeOfCareIdentifier', $cor->getUUID());
$sender = $cEmail->addChild("Sender");
$sender->addChild("EANIdentifier",$this->EANS);
$sender->addChild("Identifier", $this->medcomID);
$sender->addChild("IdentifierCode",$this->medcomIDCode);
$sender->addChild("OrganisationName",$this->orgName);
$sender->addChild("DepartmentName",$this->departmentName);
$sender->addChild("UnitName",$this->unitName);
$sender->addChild("DistrictName",$this->districtName);
$sender->addChild("PostCodeIdentifier",$this->postalCode);
$sender->addChild("MedicalSpecialityCode","ikkeklassificeret");
$receiver = $cEmail->addChild("Receiver");
$receiver->addChild("EANIdentifier",$medcom->getEAN());
$receiver->addChild("Identifier",$medcom->getSorId());
$receiver->addChild("IdentifierCode","sygehusafdelingsnummer");
$receiver->addChild("OrganisationName",$medcom->getEntityName());
$receiver->addChild("DepartmentName",$medcom->getEntityTypeName());
$receiver->addChild("StreetName",$medcom->getPostalAddress());
$receiver->addChild("DistrictName",$medcom->getPostalDistrictName());
$receiver->addChild("PostCodeIdentifier",$medcom->getPostalPostCodeId());
$patient = $cEmail->addChild("Patient");
$patient->addChild("CivilRegistrationNumber", $this->patientObj->getCpr());
$patient->addChild("PersonSurnameName", $this->patientObj->getLastName());
$patient->addChild("PersonGivenName", $this->patientObj->getFirstName());
$patient->addChild("StreetName", $this->patientObj->getAddressLine1());
$patient->addChild("DistrictName", $this->patientObj->getCity());
$patient->addChild("PostCodeIdentifier", $this->patientObj->getPostNumber());
$patient->addChild("EpisodeOfCareStatusCode", "inaktiv");
$addInfo = $cEmail->addChild("AdditionalInformation");
$addInfo->addChild("Priority", ($obj->isHighPrio() ? "høj_prioritet" : "rutine"));//rutine
$addInfo->addChild("Subject", $cor->getSubject());
$cInfo1 = $cEmail->addChild("ClinicalInformation");
$length = strlen($obj->getMessageBreakXML());
$cInfo1->addChild("Text01",$obj->getMessageBreakXML());
if($last9 != null && false) {
foreach($last9 as $_txt) {
$length += strlen(utf8_decode($_txt["message"]));
if($length <= 25000)
$cEmail->addChild("ClinicalInformation")->addChild("Text01",utf8_decode($_txt["message"]));
}
}
//GET ALL FILES RELATED TO THIS
if($files != null && count($files) != 0) {
foreach($files as $file) {
$ref = $cEmail->addChild("Reference");
$ref->addChild("RefDescription","BIN");
$bin = $ref->addChild("BIN");
$bin->addChild('ObjectIdentifier', str_replace('-','',$file->getGUID()));
$object_type_code = ($file->getFileType() == "jpg" || $file->getFileType() == "jpeg" || $file->getFileType() == "gif" || $file->getFileType() == "png" || $file->getFileType() == "bmp" || $file->getFileType() == "pcx" || $file->getFileType() == "tiff" ? "billede" : "");
$object_type_code = ($file->getFileType() == "pdf" ? "vektor_grafik" : $object_type_code);
$object_type_code = ($file->getFileType() == "zip" ? "proprietaert_indhold" : $object_type_code);
$object_type_code = ($file->getFileType() == "txt" || $file->getFileType() == "rtf" || $file->getFileType() == "doc" || $file->getFileType() == "xls" || $file->getFileType() == "wpd" ? "tekstfil" : $object_type_code);
$bin->addChild('ObjectCode', $object_type_code);
$bin->addChild('ObjectExtensionCode', ($file->getFileType() == "jpg" ? "jpeg" : $file->getFileType()));
$bin->addChild('OriginalObjectSize', $file->getFileSize());
}
} else {
$ref = $cEmail->addChild("Reference");
$ref->addChild("RefDescription","Der Findes yderliger oplysninger i SUP");
$ref->addChild("SUP", "true");
}
return $emssage;
}
private function getXmlctl02($obj,$cor,$medcom,$ean,$orgVersionCode,$refuseCode,$refuseText) {
$emssage = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><Emessage />');
$emssage->addAttribute("xmlns", "http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2005/08/07/");
$env = $emssage->addChild('Envelope');
$envSent = $env->addChild('Sent');
$envSent->addChild('Date', date("Y-m-d"));//datetime now
$envSent->addChild('Time', date("H:i"));//datetime now
$env->addChild('Identifier', uniqid());
$env->addChild('AcknowledgementCode', "minuspositivkvitt");
$msg = $emssage->addChild('NegativeReceipt');
$letter = $msg->addChild("Letter");
$letter->addChild('Identifier', uniqid());
$letter->addChild('VersionCode', "XC0230Q");
$letter->addChild('StatisticalCode', "XCTL02");
$sender = $msg->addChild("Sender");
$sender->addChild("EANIdentifier",$this->EANS);
$receiver = $msg->addChild("Receiver");
$receiver->addChild("EANIdentifier",$ean);
$orgmsg = $msg->addChild("OriginalEmessage");
$orgmsg->addChild("OriginalEnvelopeIdentifier", $obj->getEUUID());
$orgSender = $orgmsg->addChild("OriginalSender");
$orgSender->addChild("EANIdentifier",$ean);
$orgReceiver = $orgmsg->addChild("OriginalReceiver");
$orgReceiver->addChild("EANIdentifier",$this->EANS);
$orgletter = $orgmsg->addChild("OriginalLetter");
$orgletter->addChild("OriginalLetterIdentifier",$obj->getUUID());
$orgletter->addChild("OriginalVersionCode",$orgVersionCode);
if($refuseText !== null && $refuseCode !== "")
$orgletter->addChild("RefuseCode",$refuseCode);
if($refuseText !== null && $refuseText !== "")
$orgletter->addChild("RefuseText",$refuseText);
return $emssage;
}
private function getXmlctl03($obj,$cor,$medcom,$ean) {
$emssage = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><Emessage />');
$emssage->addAttribute("xmlns", "http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2005/08/07/");
$env = $emssage->addChild('Envelope');
$envSent = $env->addChild('Sent');
$envSent->addChild('Date', date("Y-m-d"));//datetime now
$envSent->addChild('Time', date("H:i"));//datetime now
$env->addChild('Identifier', uniqid());
$env->addChild('AcknowledgementCode', "minuspositivkvitt");
$msg = $emssage->addChild('PositiveReceipt');
$letter = $msg->addChild("Letter");
$letter->addChild('Identifier', uniqid());
$letter->addChild('VersionCode', "XC0330Q");
$letter->addChild('StatisticalCode', "XCTL03");
$sender = $msg->addChild("Sender");
$sender->addChild("EANIdentifier",$this->EANS);
$receiver = $msg->addChild("Receiver");
$receiver->addChild("EANIdentifier", $ean);
$orgmsg = $msg->addChild("OriginalEmessage");
$orgmsg->addChild("OriginalEnvelopeIdentifier", $obj->getEUUID());
$orgSender = $orgmsg->addChild("OriginalSender");
$orgSender->addChild("EANIdentifier",$ean);
$orgReceiver = $orgmsg->addChild("OriginalReceiver");
$orgReceiver->addChild("EANIdentifier",$this->EANS);
$orgletter = $orgmsg->addChild("OriginalLetter");
$orgletter->addChild("OriginalLetterIdentifier",$obj->getUUID());
if(strtolower($obj->getType()) == "bilag"){
$orgletter->addChild("OriginalVersionCode","XB0131X");
} else {
$orgletter->addChild("OriginalVersionCode","XD9134L");
}
return $emssage;
}
private function getXmlbin01($obj,$medcom) {
$emssage = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><Emessage />');
$emssage->addAttribute("xmlns", "http://rep.oio.dk/medcom.dk/xml/schemas/2012/03/28/");
$env = $emssage->addChild('Envelope');
$envSent = $env->addChild('Sent');
$envSent->addChild('Date', date("Y-m-d"));//datetime now
$envSent->addChild('Time', date("H:i"));//datetime now
$env->addChild('Identifier', $obj->getEUUID());
$env->addChild('AcknowledgementCode', "minuspositivkvitt");
$cEmail = $emssage->addChild('BinaryLetter');
$letter = $cEmail->addChild("Letter");
$letter->addChild('Identifier', $obj->getUUID());
$letter->addChild('VersionCode', "XB0131X");
$letter->addChild('StatisticalCode', "XBIN01");
$auth = $letter->addChild('Authorisation');
$auth->addChild('Date', date("Y-m-d")."");//datetime now
$auth->addChild('Time', date("H:i")."");//datetime now
$letter->addChild('TypeCode', "XBIN01");
$letter->addChild('StatusCode', "nytbrev");
$sender = $cEmail->addChild("Sender");
$sender->addChild("EANIdentifier",$this->EANS);
$sender->addChild("Identifier", $this->medcomID);
$sender->addChild("IdentifierCode",$this->medcomIDCode);
$sender->addChild("OrganisationName",$this->orgName);
$sender->addChild("DepartmentName",$this->departmentName);
$sender->addChild("UnitName",$this->unitName);
$sender->addChild("DistrictName",$this->districtName);
$sender->addChild("PostCodeIdentifier",$this->postalCode);
$sender->addChild("MedicalSpecialityCode","ikkeklassificeret");
$receiver = $cEmail->addChild("Receiver");
$receiver->addChild("EANIdentifier",$medcom->getEAN());
$receiver->addChild("Identifier",$medcom->getSorId());
$receiver->addChild("IdentifierCode","sygehusafdelingsnummer");
$receiver->addChild("OrganisationName",$medcom->getEntityName());
$receiver->addChild("DepartmentName",$medcom->getEntityTypeName());
$receiver->addChild("StreetName",$medcom->getPostalAddress());
$receiver->addChild("DistrictName",$medcom->getPostalDistrictName());
$receiver->addChild("PostCodeIdentifier",$medcom->getPostalPostCodeId());
$patient = $cEmail->addChild("Patient");
$patient->addChild("CivilRegistrationNumber", $this->patientObj->getCpr());
$patient->addChild("PersonSurnameName", $this->patientObj->getLastName());
$patient->addChild("PersonGivenName", $this->patientObj->getFirstName());
$msg = $cEmail->addChild('BinaryObject');
$msg->addChild('ObjectIdentifier', $obj->getGUID());
$object_type_code = ($obj->getFileType() == "jpg" || $obj->getFileType() == "jpeg" || $obj->getFileType() == "gif" || $obj->getFileType() == "png" || $obj->getFileType() == "bmp" || $obj->getFileType() == "pcx" || $obj->getFileType() == "tiff" ? "billede" : "");
$object_type_code = ($obj->getFileType() == "pdf" ? "vektor_grafik" : $object_type_code);
$object_type_code = ($obj->getFileType() == "zip" ? "proprietaert_indhold" : $object_type_code);
$object_type_code = ($obj->getFileType() == "txt" || $obj->getFileType() == "rtf" || $obj->getFileType() == "doc" || $obj->getFileType() == "xls" || $obj->getFileType() == "wpd" ? "tekstfil" : $object_type_code);
$msg->addChild('ObjectCode', $object_type_code);
$msg->addChild('ObjectExtensionCode', ($obj->getFileType() == "jpg" ? "jpeg" : $obj->getFileType()));
$msg->addChild('OriginalObjectSize', $obj->getFileSize());
$msg->addChild('Object_Base64Encoded', $obj->getFileData());
return $emssage;
}
}