<?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 $repo;
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->repo = $this->em->getRepository(MedComCorrespondence::class);
$this->repo->setEm($this->em);
$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 ."*.xml" );
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, $deleted = false) {
$this->type = $type;
$this->auth($request);
$currentPage = ($request->get("page") != null && is_nan($request->get("page")) == false ? $request->get("page") : 1);
$c = 10;
$search = ($request->get("search") != null ? $request->get("search") : "");
$ctotal = $this->repo->fetechCorrespondencesTotal($this->type, $journal, $search, $deleted);
$pagination = array("c" => $c,
"ctotal" => $ctotal,
"pages" => ceil(($ctotal / $c)),
"page" => $currentPage,
"skip" => ($currentPage - 1)*$c
);
$corr = $this->repo->fetechCorrespondences($this->type, $journal,$pagination['c'], $pagination['skip'], $search, $deleted);
$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,
'deleted' => $deleted,
'medcomSpecialtyCodes' => $this->getMedComSpecialtyCodes(),
'MedComHelper' => new \App\Service\MedcomTwig(),
'pagination' => $pagination,
"search" => $search
));
}
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 trashcan(Request $request) {
return $this->getData(3, $request, false, true);
}
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());
//get files
$id = $request->get("id");
return $this->render('medcom/_journalize.twig', array(
'thisID' => $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");
$_cor = $this->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');
$_cor = $this->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();
$heading = $request->get("subject");
$dialogueAttachmentDetailObj->setAttachmentHeading($heading);
$this->em->persist($dialogueAttachmentDetailObj);
$this->em->flush();
$ccID = $dialogueAttachmentDetailObj->getId();
$cor->journalize($ccID);
$cor->setPatient($this->patientObj);
$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 saveJournalizeFiles(Request $request) {
$this->auth($request);
$id = $request->get('id');
$_msg = $this->repo->fetechMessage($id);
$filename = $request->get('postMailAttachmentName');
if($id != null && $id != 0 && count($_msg) != 0 && $filename != null && $filename != "") {
$msg = $_msg[0];
$msg->setFilename($filename);
$this->em->persist($msg);
$this->em->flush();
return new Response(json_encode('success:'.$id), Response::HTTP_OK,['content-type' => "text/json"]);
}
return new Response(json_encode('error:true'), Response::HTTP_OK,['content-type' => "text/json"]);
}
public function saveFile($type, $medcom,$obj,$cbj,$name,$ean = null,$parentID = null,$files = null) {
$medcom = ($medcom != null ? $medcom : $this->repo->getMedcomList($cbj->getMedComUser()));
$ean = ($ean != null ? $ean : $medcom->getEAN());
if($type == "xdis91") {
$parentID = ($parentID != null ? $parentID : $this->repo->lastMessageID);
$files = ($files != null ? $files : $this->repo->fetechMessageParent($parentID));
$_xml = $this->getXmlDis91($obj, $cbj, $medcom, $files);
}
elseif($type == "xbin01")
$_xml = $this->getXmlbin01($obj,$medcom);
$xml = $this->getVansXml($_xml, $type, $ean, $this->repo);
$myfile = fopen("Medcom/Out/".$name.".xml", "w") or die("Unable to open file!");
fwrite($myfile, $xml->asXML());
fclose($myfile);
}
public function send(Request $request) {
$this->auth($request);
$type = ($request->get("submit") == "send" ? 2 : 1);
$type = ($request->get("submit") == "inbox" ? 3 : $type);
$cor;
$medcom;
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 = $this->repo->insert($request->get("medcom_user"), $request->get("subject"), $this->user, $this->patientObj, $request->get("priority"), $request->get("message"), $type,false);
$i = 1;
$medcom = $this->repo->getMedcomList($cor->getMedComUser());
$id = $this->repo->lastMessageID;
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 = $this->repo->insertFileOnly($filesize,$request->get("medcom_user"), $this->user, $this->patientObj,$type,$filename,$ext,$base,$cor,$request->get("priority"));
$obj->setParentID($id);
$this->em->persist($obj);
$this->em->flush();
if($request->get("submit") != 2) {
$this->saveFile("xbin01", $medcom, $obj, $cor, $id."_file".$i);
$i++;
}
}
} else {
$cor = $this->repo->insert($request->get("medcom_user"), $request->get("subject"), $this->user, $this->patientObj, $request->get("priority"), $request->get("message"), $type);
$id = $this->repo->lastMessageID;
}
if($request->get("submit") != 2) {
$medcom = $this->repo->getMedcomList($cor->getMedComUser());
$ean = $medcom->getEAN();
$_obj = $this->repo->fetechMessage($id);
$this->saveFile("xdis91", $medcom, $_obj[0], $cor, $id,$ean,$id);
}
return new Response(json_encode('success:'.$id), Response::HTTP_OK,['content-type' => "text/json"]);
}
public function sendDraft(Request $request) {
$this->auth($request);
$id = $request->get("objID");
$_msg = $this->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 = $this->repo->getMedcomList($cor->getMedComUser());
$this->saveFile("xdis91", $medcom, $msg, $cor, $id);
$i = 1;
$files = $this->repo->fetechFiles($cor);
foreach($files as $file) {
$this->saveFile("xbin01", $medcom, $file, $cor, $id."_file".$i);
$i++;
}
return new Response(json_encode('success'), Response::HTTP_OK,['content-type' => "text/json"]);
} else {
return new Response(json_encode('error'), Response::HTTP_OK,['content-type' => "text/json"]);
}
return $this->redirectToRoute("medcom_index");
}
public function edi(Request $request) {
}
private function getVansXml($xml, $code, $ean,$repo) {
$baseData = base64_encode(str_replace("<Break/> ", "<Break/>", $xml->asXml()));
$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:XDIS91');
$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->repo->fetechMessage($id);
if(count($_obj) != 0) {
$obj = $_obj[0];
$cor = $obj->getCorrospondence();
$medcom = $this->repo->getMedcomList($cor->getMedComUser());
$ean = $medcom->getEAN();
$orgVersionCode = (strtolower($obj->getType()) == "bilag" ? "XB0131X" : "XD9134L");
$files = $this->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);
$vans_exist = $this->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) {
$files = scandir('Medcom/In');
foreach($files as $file) {
$ext = pathinfo('Medcom/In/'.$file, PATHINFO_EXTENSION);
if(is_dir('Medcom/In/'.$file) == false && $ext == "xml") {
//libxml_use_internal_errors(true);
$fileData = file_get_contents('Medcom/In/'.$file);
//$xml_ = simplexml_load_file('Medcom/In/'.$file);
$xml_ = simplexml_load_string($fileData);
//$errors = libxml_get_errors();
if($xml_ != false) {
$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->repo->fetechMessage($id);
if(count($_obj) != 0) {
$obj = $_obj[0];
$cor = $obj->getCorrospondence();
$medcom = $this->repo->getMedcomList($cor->getMedComUser());
$files = $this->repo->fetechMessageParent($id);
$last9 = $this->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->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"));
$medcom = $this->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->repo->fetechMessage($id);
if(count($_obj) != 0) {
$obj = $_obj[0];
$cor = $obj->getCorrospondence();
$medcom = $this->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->repo->fetechMessage($id);
if(count($_obj) != 0) {
$obj = $_obj[0];
$cor = $obj->getCorrospondence();
$medcom = $this->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) {
if($this->em == null)
$this->auth($request);
$repo = $this->repo;
if (file_exists('import.xml') || $vansXml != null) {
//libxml_use_internal_errors(true);
$xml_ = ($vansXml != null ? simplexml_load_string($vansXml, 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_PARSEHUGE) : simplexml_load_file('import.xml'));
$xml = ($xml_->Emessage != null && $xml_->Emessage != "" ? $xml_->Emessage : $xml_);
//$errors = libxml_get_errors();
$id = 0; $_xml; $moveFoward = true;
$mServ = new \App\Service\MedcomXml($this->em, $xml, $this->repo);
$vars = $mServ->getVariables();
$this->patientObj = $this->em->getRepository(Patient::class)->findOneBy(array('cpr' => $vars["cpr"]));
if($this->patientObj == null) {
//handle check here
//$rootdir = $this->get('kernel')->getRootDir();
//$patientServ = new \App\Service\CreatePatient($this->em, $request,$rootdir);
//$patientServ->createPatient($vars["cpr"]);
}
$_xml = $vars["xml"];
if(isset($xml->ClinicalEmail) && $xml->ClinicalEmail !== null && $xml->ClinicalEmail !== "") {
$m_id = 0;
$cor;
$vars = $mServ->handleErrors("xdis91");
$msg_exist = $this->repo->fetechMessageUUID($vars["letterID"]);
if(count($msg_exist) == 0) {
if($_obj = $this->repo->fetechCorrespondenceUUID($vars["id"]) && count($_obj) != 0) {
$cor = $_obj[0];
$m = MedComMessages::withInsert($vars["xdis91"]["message"],"",null,$cor,3,'Korrespondancebrev',$vars["xdis91"]["prio"]);
$m->setMedicalSpecialityCode($MedicalSpecialityCode);
$m->setPatientString($_xml->Patient->AsXML());
$m->setDeleted(($vars["error"]["error"] ? true : false)); $m->setUUID($vars["letterID"]); $m->setEUUID($vars["envID"]); $this->em->persist($m); $this->em->flush();
$m_id=$m->getId();
$cor->setDeleted(($vars["error"]["error"] ? true : false)); $cor->setStatus(3); $cor->setUpdatedAt(new \DateTime()); $this->em->persist($cor); $this->em->flush();
} else {
$cor = $this->repo->insertUUID($vars["sender"], $vars["xdis91"]["subject"], null, $this->patientObj, $vars["xdis91"]["prio"], $vars["xdis91"]["message"], 3, $vars["id"], $vars["letterID"], $vars["envID"], $vars["xdis91"]["MedicalSpecialityCode"]);
$cor->setDeleted(($vars["error"]["error"] ? true : false)); $cor->setUpdatedAt(new \DateTime()); $this->em->persist($cor); $this->em->flush();
$m_id=$this->repo->lastMessageID;
$msg = $this->repo->fetechMessage($m_id);
$msg[0]->setPatientString($_xml->Patient->AsXML());
$this->em->persist($msg[0]);
$this->em->flush();
}
$mServ->xdisReference(function ($ext, $filesize, $objID, $_extFile) use (&$cor, &$m_id, &$vars) {
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();
}
}
else {
$obj = $this->repo->insertFileOnly($filesize,$vars["sender"],null,$this->patientObj,3,"bilag.".date_timestamp_get(date_create()),$ext,null,$cor,false,$objID);
}
$obj->setPatientString($_xml->Patient->AsXML());
$obj->setParentID($m_id);
$obj->setCor($cor);
$obj->setDeleted(($vars["error"]["error"] ? true : false));
$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() != $vars["envID"])) {
$msg = null;
$msg = $this->repo->fetechMessageUUID($vars["letterID"]);
$msg[0]->setReceipt(true);
$this->em->persist($msg[0]);
$this->em->flush();
$_id = $msg[0]->getID();
if($vars["error"]["error"]) {
if($vansXml != null) {
$_xdisXml = $this->getXmlctl02($msg[0],$cor,null,$vars["sender"],$vars["VersionCode"],$vars["error"]["refuseCode"],$vars["error"]["refuseText"]);
return $this->getVansXml($_xdisXml, "xctl02", $vars["sender"], $this->repo);
}
return $this->xml02($request,$_id,$vars["error"]["refuseText"],$vars["error"]["refuseCode"],$vars["error"]["_ean"],$vars["VersionCode"].'');
} else {
if($vansXml != null) {
$_xdisXml = $this->getXmlctl03($msg[0],$cor,null,$vars["sender"]);
return $this->getVansXml($_xdisXml, "xctl03", $vars["sender"], $this->repo);
}
return $this->xml03($request,$_id,$vars["sender"]);
}
} else {
return null;
}
}
elseif(isset($xml->BinaryLetter) && $xml->BinaryLetter !== null && $xml->BinaryLetter !== "") {
$vars = $mServ->handleErrors("xbin01");
$obj = null;
$cor = null;
$_id = null;
$msg = null;
$mServ->xbinloop(function ($extFile, $xbin,$i) use (&$cor, &$obj, &$vars, &$_id, &$_xml, &$msg) {
if($extFile != null) {
$cor = $extFile->getCorrospondence();
$cor->setUpdatedAt(new \DateTime()); $this->em->persist($cor); $this->em->flush();
$obj = $this->repo->insertFileOnly($xbin["filesize"],$vars["sender"],null,$this->patientObj,3,"bilag.".date_timestamp_get(date_create())."_".$i,$xbin["ext"],$xbin["baseData"],$cor,false,$xbin["objID"]);
$extFile->setDeleted(true);
$this->em->persist($extFile);
$this->em->flush();
$msg = $extFile;
} else {
$cor = ($cor != null ? $cor : $this->repo->insertUUID($vars["sender"], "Bilag uden meddelelse", null, $this->patientObj, false, "bilag uden meddelelse", 3, $vars["id"], $vars["letterID"], $vars["envID"]));
$cor->setDeleted(($vars["error"]["error"] ? true : false)); $cor->setUpdatedAt(new \DateTime()); $this->em->persist($cor); $this->em->flush();
$obj = $this->repo->insertFileOnly($xbin["filesize"],$vars["sender"],null,$this->patientObj,3,"bilag.".date_timestamp_get(date_create())."_".$i,$xbin["ext"],$xbin["baseData"],$cor,false,$xbin["objID"]);
$m_id=$this->repo->lastMessageID;
$_message = $this->repo->fetechMessage($m_id);
$_message[0]->setPatientString($_xml->Patient->asXML());
$this->em->persist($_message[0]);
$this->em->flush();
$obj->setParentID($m_id);
$msg = $_message[0];
}
$obj->setPatientString($_xml->Patient->asXML());
$obj->setDeleted(($vars["error"]["error"] ? true : false));
$_id = $obj->getId();
$this->em->persist($obj);
$this->em->flush();
});
if($vansXml != null) {
//$msg = $this->repo->fetechMessageUUID($vars["letterID"]);
$_xdisXml = ($vars["error"]["error"] ? $this->getXmlctl02($msg,$cor,null,$vars["sender"],$vars["VersionCode"],$vars["error"]["refuseCode"],$vars["error"]["refuseText"]) : $this->getXmlctl03($msg,$cor,null,$vars["sender"]));
return $this->getVansXml($_xdisXml, ($vars["error"]["error"] ? "xctl02" : "xctl03"), $vars["sender"], $this->repo);
} else {
if($vars["error"]["error"]) {
return $this->xml02($request,$_id,$vars["error"]["refuseText"],$vars["error"]["refuseCode"],$vars["sender"]);
} else {
return $this->xml03($request,$_id,$vars["sender"]);
}
}
}
if($vars["is_reciept"]) {
$_obj = $this->repo->fetechMessageUUID($vars["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 != "")
|| ($_xml->OriginalEmessage->RefuseText != null && $_xml->OriginalEmessage->RefuseText != "")) {
if($_xml->OriginalEmessage->OriginalLetter->RefuseText != null && $_xml->OriginalEmessage->OriginalLetter->RefuseText != "") {
$rT = $_xml->OriginalEmessage->OriginalLetter->RefuseText;
$rC = $_xml->OriginalEmessage->OriginalLetter->RefuseCode;
}
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);
$cbj = $this->em->getRepository(MedComCorrespondence::class)->find($request->get("objID"));
$obj = $this->repo->reply($this->user, $request->get("message"), $request->get("priority"), $cbj,2);
if($cbj->getPatient() == null) {
$str = $this->repo->getPatientData($cbj);
if($str != null) {
$obj->setPatientString($str);
$this->em->persist($obj);
$this->em->flush();
}
}
$this->saveFile("xdis91", null, $obj, $cbj, $this->repo->lastMessageID);
return new Response(json_encode('success'), Response::HTTP_OK,['content-type' => "text/json"]);
}
public function delete(Request $request) {
$this->auth($request);
$cbj = $this->em->getRepository(MedComCorrespondence::class)->find($request->get("objID"));
$this->repo->delete($cbj);
return new Response(json_encode('success'), Response::HTTP_OK,['content-type' => "text/json"]);
}
public function deleteMessage(Request $request) {
$this->auth($request);
$cbj = $this->em->getRepository(MedComMessages::class)->find($request->get("objID"));
$this->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);
$cbj = $this->em->getRepository(MedComMessages::class)->find($request->get("objID"));
//resend
//new ids
return new Response(json_encode('success'), Response::HTTP_OK,['content-type' => "text/json"]);
}
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;
}
private function getPatientData($parent, $patientObj, $address = true) {
$patient = $parent->addChild("Patient");
if($patientObj == null) {
$patientObj = new Patient();
$str = $this->repo->getPatientData($cbj);
if($str != null) {
$xml = simplexml_load_string($str);
$patientObj->setCpr($str->CivilRegistrationNumber);
$$patientObj->setFirstName($str->PersonGivenName);
$$patientObj->setLastName($str->PersonSurnameName);
$patientObj->setCity($str->DistrictName);
$patientObj->setPostNumber($str->PostCodeIdentifier);
$patientObj->setAddressLine1($str->StreetName);
}
}
$patient->addChild("CivilRegistrationNumber", $patientObj->getCpr());
$patient->addChild("PersonSurnameName", $patientObj->getLastName());
$patient->addChild("PersonGivenName", $patientObj->getFirstName());
if($address) {
$patient->addChild("StreetName", $patientObj->getAddressLine1());
$patient->addChild("DistrictName", $patientObj->getCity());
$patient->addChild("PostCodeIdentifier", $patientObj->getPostNumber());
$patient->addChild("EpisodeOfCareStatusCode", "inaktiv");
}
}
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());
$this->getPatientData($cEmail, $cor->getPatient());
$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());
$cor = $obj->getCorrospondence();
$this->getPatientData($cEmail, $cor->getPatient(), false);
$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;
}
}