src/Controller/MedComController.php line 289

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. #use Symfony\Component\HTTPFoundation\Response;
  4. #use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use phpseclib\Net\SFTP;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use App\Entity\MedComCorrespondence;
  10. use App\Entity\MedComMessages;
  11. use App\Entity\Patient;
  12. use App\Entity\Dialogue;
  13. use App\Entity\User;
  14. use App\Entity\JoMasterInformation;
  15. use App\Entity\JoPostMail;
  16. use App\Entity\JoPostMailAttachment;
  17. use App\Entity\PredefinedAttachmentType;
  18. use App\Entity\PredefinedCaseCard;
  19. use App\Entity\DialogueCaseCard;
  20. use App\Entity\DialogueCaseCardMeasure;
  21. use App\Entity\DialogueAttachmentDetails;
  22. use App\Entity\CasecardMeasure;
  23. use App\Entity\DialogueAttachments;
  24. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  25. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  26. class MedComController extends AbstractController {
  27.     private $EANS "";
  28.     private $medcomID "";
  29.     private $medcomIDCode "";
  30.     private $orgName "";
  31.     private $departmentName "";
  32.     private $unitName "";
  33.     private $districtName "";
  34.     private $postalCode "";
  35.     private $address "";
  36.     private $city "";
  37.     
  38.     private $Info;
  39.     private $em;
  40.     private $user;
  41.     private $userRoleType;
  42.     private $session;
  43.     private $dialogueControllerObj;
  44.     private $selectedPatient;
  45.     private $selectedDialogue;
  46.     private $patientObj;
  47.     private $dialogueObj;
  48.     private $cprNo;
  49.     private $areaNames;
  50.     private $getFullDate;
  51.     private $bdateYear;
  52.     private $dateDiff;
  53.     private $ean = array();
  54.     function __construct() {
  55.     }
  56.     private function auth($request) {
  57.         $twig $this->container->get('twig');
  58.         $globals $twig->getGlobals();
  59.         $this->EANS $globals["medcom"]["ean"];
  60.         $this->medcomID $globals["medcom"]["medcomID"];
  61.         $this->medcomIDCode $globals["medcom"]["medcomIDCode"];
  62.         $this->orgName $globals["medcom"]["orgName"];
  63.         $this->departmentName $globals["medcom"]["departmentName"];
  64.         $this->unitName $globals["medcom"]["unitName"];
  65.         $this->districtName $globals["medcom"]["districtName"];
  66.         $this->postalCode $globals["medcom"]["postalCode"];
  67.         $this->address $globals["medcom"]["address"];
  68.         $this->city $globals["medcom"]["city"];
  69.     
  70.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  71.         $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);
  72.         $this->em $this->getDoctrine()->getManager();
  73.         $this->_receiveVans($request);
  74.         $this->user $this->get('security.token_storage')->getToken()->getUser();
  75.         $this->userRoleType $this->user->hasRole('ROLE_CSV') ? : ($this->user->hasRole('ROLE_DTS') ? 0);
  76.         $this->session $request->getSession();
  77.         $this->dialogueControllerObj = new DialogueController();
  78.         $this->selectedPatient $this->session->get("selectedPatient"null);
  79.         $this->selectedDialogue $this->session->get("selectedDialogue"null);
  80.         if($this->selectedDialogue != null)
  81.             $this->dialogueObj $this->em->getRepository(Dialogue::class)->find($this->selectedDialogue);
  82.         if($this->selectedPatient != null)
  83.             $this->patientObj $this->em->getRepository(Patient::class)->find($this->selectedPatient);
  84.         $this->areaNames $this->em->getRepository(JoMasterInformation::class)->getAreaNames();
  85.         if($this->selectedPatient != null)
  86.             $this->cprNo $this->patientObj->getCpr();
  87.         if($this->selectedPatient != null)
  88.             $this->getFullDate $this->dialogueControllerObj->getBirthDate($this->cprNo);
  89.         if($this->selectedPatient != null)
  90.             $this->bdateYear date_format($this->getFullDate"d.m.Y");
  91.         $this->dateDiff $this->dialogueControllerObj->getUserAge($this->bdateYear);
  92.     }
  93.     public function getMedComNewFiles(Request $request) {
  94.         $directory getcwd()."/Medcom/In/";
  95.         
  96.         // Initialize filecount variavle
  97.         $filecount 0;
  98.         
  99.         $files2 glob$directory ."*" );
  100.         if( $files2 ) {
  101.             $filecount count($files2);
  102.         }
  103.         return new Response(json_encode($filecount), Response::HTTP_OK,['content-type' => "text/json"]);
  104.     }
  105.     
  106.     private function getMedComSpecialtyCodes() {
  107.         $array = array();
  108.         $array["Ikkeklassificeret"] = "Ikke klassificeret";
  109.         $array["ikkeklassificeret"] = "Ikke klassificeret";
  110.         $array["blandet"] = "Blandet medicin";
  111.         $array["intern_medicin_sygehus"] = "Intern medicin";
  112.         $array["geriatri"] = "Geriatri";
  113.         $array["hepatologi"] = "Hepatologi";
  114.         $array["haematologi"] = "Hæmatologi";
  115.         $array["Infektionsmedicin"] = "Infektionsmedicin";
  116.         $array["kardiologi"] = "Kardiologi";
  117.         $array["med_allergologi"] = "Med. allergologi";
  118.         $array["med_endokrinologi"] = "Med. endokrinologi";
  119.         $array["med_gastroenterologi"] = "Med. gastroenterologi";
  120.         $array["med_lungesygdomme"] = "Med. lungesygdomme";
  121.         $array["nefrologi"] = "Nefrologi";
  122.         $array["reumatologi"] = "Reumatologi";
  123.         $array["palliativ"] = "Palliativ medicin";
  124.         $array["akut"] = "Akut medicin";
  125.         $array["dermato_venerologi_sygehus"] = "Dermato-venerologi";
  126.         $array["neurologi"] = "Neurologi";
  127.         $array["onkologi"] = "Onkologi";
  128.         $array["kirurgi_sygehus"] = "Kirurgi";
  129.         $array["karkirurgi"] = "Karkirurgi";
  130.         $array["kir_gastroenterologi"] = "Kir. gastroenterologi";
  131.         $array["plastikkirurgi"] = "Plastikkirurgi";
  132.         $array["thoraxkirurgi"] = "Thoraxkirurgi";
  133.         $array["urologi"] = "Urologi";
  134.         $array["gynaekologi_obstetrik_sygehus"] = "Gynækologi og obstetrik";
  135.         $array["sexologi"] = "Sexologi";
  136.         $array["neurokirurgi"] = "Neurokirurgi";
  137.         $array["ortopaedisk_kirurgi_sygehus"] = "Ortopædisk kirurgi";
  138.         $array["oftalmologi"] = "Oftalmologi";
  139.         $array["oto_rhino_laryngologi"] = "Oto-, rhino-, laryngologi";
  140.         $array["hospitalsodontologi"] = "Hospitalsodontologi";
  141.         $array["psykiatri_sygehus"] = "Psykiatri";
  142.         $array["boerne_ungdomspsykiatri"] = "Børne- og ungdomspsykiatri";
  143.         $array["klin_biokemi"] = "Klin. biokemi";
  144.         $array["klin_fys_nuklearmedicin"] = "Klin fys og nuklearmedicin";
  145.         $array["klin_immunologi"] = "Klin. immunologi";
  146.         $array["klin_mikrobiologi"] = "Klin. mikrobiologi";
  147.         $array["klin_neurofysiologi"] = "Klin. neurofysiologi";
  148.         $array["patologisk_anatomi"] = "Patologisk anatomi";
  149.         $array["diagnostisk_radiologi"] = "Diagnostisk radiologi";
  150.         $array["klin_farmakologi"] = "Klin. farmakologi";
  151.         $array["klin_genetik"] = "Klin. genetik";
  152.         $array["paediatri_sygehus"] = "Pædiatri";
  153.         $array["anaestesiologi_sygehus"] = "Anæstesiologi";
  154.         $array["arbejdsmedicin"] = "Arbejdsmedicin";
  155.         $array["almen_medicin"] = "Almen medicin";
  156.         $array["samfundsmedicin"] = "Samfundsmedicin";
  157.         $array["retsmedicin"] = "Retsmedicin";
  158.         $array["fysioterapi_sygehus"] = "Fysio- og ergoterapi";
  159.         $array["anaestesiologi_praksis"] = "Anæstesiologi";
  160.         $array["roentgen_kbh"] = "Røntgen (København)";
  161.         $array["dermato_venerologi_praksis"] = "Dermatologi-venerologi";
  162.         $array["roentgen"] = "Røntgen";
  163.         $array["reumatologi_fysiurgi"] = "Reumatologi (Fysiurgi)";
  164.         $array["gynaekologi_obstetrik_praksis"] = "Gynækologi/obstetrik";
  165.         $array["intern_medicin_praksis"] = "Intern Medicin";
  166.         $array["kirurgi_praksis"] = "Kirurgi";
  167.         $array["klinisk_kemi"] = "Klinisk kemi";
  168.         $array["neurokirurgi_praksis"] = "Neurokirurgi";
  169.         $array["neuromedicin"] = "Neuromedicin";
  170.         $array["oejenlaege"] = "Øjenlæge";
  171.         $array["ortopaedisk_kirurgi_praksis"] = "Ortopædisk Kirurgi";
  172.         $array["oere_naese_halslaege"] = "Øre, Næse halslæge";
  173.         $array["patologi"] = "Patologi";
  174.         $array["plastkirurgi"] = "Plastkirurgi";
  175.         $array["psykiatri_praksis"] = "Psykiatri";
  176.         $array["paediatri"] = "Pædiatri";
  177.         $array["boernepsykiatri"] = "Børnepsykiatri";
  178.         $array["tropemedicin"] = "Tropemedicin";
  179.         $array["med_laboratorier_kpll"] = "KPLL";
  180.         $array["med_laboratorier"] = "Med. laboratorier";
  181.         $array["omegnslaboratorier"] = "Omegnslaboratorier";
  182.         $array["med_laboratorier_ssi"] = "SSI";
  183.         $array["tandplejere"] = "Tandplejere";
  184.         $array["tandlaege"] = "Tandlæge";
  185.         $array["fysioterapi"] = "Fysioterapi";
  186.         $array["briller"] = "Briller";
  187.         $array["kiropraktor"] = "Kiropraktor";
  188.         $array["fodterapi"] = "Fodterapi";
  189.         $array["fodbehandlking"] = "Fodbehandling";
  190.         $array["ridefysioterapi"] = "Ridefysioterapi";
  191.         $array["teddy"] = "Teddy Øfeldt";
  192.         $array["fodterapi_radioaktiv"] = "Fodterapi - følger radioaktiv bestråling";
  193.         $array["fodterapi_leddegigt"] = "Fodterapi - svær leddegigt";
  194.         $array["fysioterapi_vederlagsfri"] = "Vederlagsfri fysioterapi";
  195.         $array["psykolog"] = "Psykolog";
  196.         $array["kiropraktor_64"] = "Kiropraktik - ordning 64";
  197.         $array["ridefysioterapi_vederlagsfri"] = "Vederlagsfri ridefysioterapi";
  198.         $array["almenlaege_laegevagt"] = "Almenlæge og lægevagt";
  199.         $array["vagtlaege"] = "Almenlæge og lægevagt";
  200.         $array["almenlaege_vagtkoersel"] = "Almen lægers vagtkørsel";
  201.         $array["almenlaege_vagtlaegehjaelp"] = "Vagtlægehjælp, region hovedstaden";
  202.         $array["vagtlaegehjaelp_kbh"] = "Vagtlægehjælp, region hovedstaden";
  203.         $array["vagtlaegehjaelp"] = "Vagtlægehjælp";
  204.         return $array;
  205.     }
  206.     private function getData($type$request$journal false) {
  207.         $this->type $type;
  208.         $this->auth($request);
  209.         //$medcomList = $this->getMedComData();
  210.         $repo $this->em->getRepository(MedComCorrespondence::class);
  211.         $repo->setEm($this->em);
  212.         $medcom $repo->getMedcomList("5790001365165");
  213.         $_medcom $repo->getMedcomListentity("Mohsen Dasdar");
  214.         $corr $repo->fetechCorrespondences($this->type$journal);
  215.         $templateName "index.html.twig";
  216.         return $this->render('medcom/'.$templateName, array(
  217.             'journal' => $journal,
  218.             'patientObj' => $this->patientObj,
  219.             'dialogueObj' => $this->dialogueObj,
  220.             'areaNames' => $this->areaNames,
  221.             'dateDiff' => $this->dateDiff,
  222.             'type' => $this->type,
  223.             'cor' => $corr,
  224.             'info' => $this->Info,
  225.             'medcomSpecialtyCodes' => $this->getMedComSpecialtyCodes(),
  226.         ));
  227.     }
  228.     public function uploadList(Request $request) {
  229.         set_time_limit(0);
  230.         $this->auth($request);
  231.         $repo $this->em->getRepository(MedComCorrespondence::class);
  232.         $repo->setEm($this->em);
  233.         $file fopen("medcom.csv","r");
  234.         $_lineCount 0;
  235.         $keys = array();
  236.         $medcomList = array();
  237.         while(($line fgets($file)) !== false)
  238.         {
  239.             
  240.             $t explode(";",$line);
  241.             $medcomrow = array();
  242.             for($i=0;$i<count($t);$i++) {
  243.                 if($_lineCount != 0) {
  244.                     $key count($keys)-1<$i $i $keys[$i];
  245.                     //$medcomList[($_lineCount-1)][$key] = $t[$i];
  246.                     $medcomrow[$key] = utf8_encode($t[$i]); 
  247.                 } else {
  248.                     $keys[$i] = $t[$i];
  249.                 }
  250.             }
  251.             if($_lineCount != && ($_lineCount 75000 && $_lineCount 80000)) {
  252.                 $obj $medcomrow;
  253.                 $ean $obj["EanLocationCode"];
  254.                 if($ean != null || $ean != "") {
  255.                     $repo->insertList(null$obj["EntityName"], $obj["PostalAddress"], $obj["P_Postnummer"], $obj["PostalDistrictName"], $obj["PostalDistrictName"], $obj["SorId"], $ean);
  256.                 }
  257.             }
  258.             $_lineCount++;
  259.         }
  260.         fclose($file);
  261.         return $this->redirectToRoute("medcom_index");
  262.         //
  263.         /*set_time_limit(0);
  264.         $this->auth($request);
  265.         $medcomList = $this->getMedComData();
  266.         $repo = $this->em->getRepository(MedComCorrespondence::class);
  267.         $repo->setEm($this->em);
  268.         foreach($medcomList as $obj) {
  269.             $ean = ($obj["EanLocationCode"] != null || $obj["EanLocationCode"] != "" ? $obj["EanLocationCode"] : (isset($this->ean[$obj["ParentSorId"]]) ? $this->ean[$obj["ParentSorId"]] : ""));
  270.             $repo->insertList($obj["ParentSorEntityName"], $obj["EntityName"], $obj["PostalAddress"], $obj["PostalPostCodeId"], $obj["PostalDistrictName"], $obj["PostalDistrictName"], $obj["SorId"], $ean);
  271.         }
  272.         return $this->redirectToRoute("medcom_index");*/
  273.     }
  274.     public function journal(Request $request) {
  275.         return $this->getData(3$requesttrue);
  276.     }
  277.     public function index(Request $request) {
  278.         return $this->getData(3$request);
  279.     }
  280.     public function outbox(Request $request) {
  281.         return $this->getData(2$request);
  282.     }
  283.     public function drafts(Request $request) {
  284.         return $this->getData(1$request);
  285.     }
  286.     public function journalize(Request $request) {
  287.         $this->auth($request);
  288.         $searchFilter "ROLE_DTS";
  289.         if ($this->user->hasRole('ROLE_CSV')) {
  290.             $searchFilter "ROLE_CSV";
  291.         }
  292.         $predefinedCaseCardAll $this->em->getRepository(PredefinedCaseCard::class)->findBy(array('userType' => $searchFilter'isForIndividual' => 1));
  293.         $joGroupObj NULL;
  294.         if($this->dialogueObj != null) {
  295.             if(($this->dialogueObj->getDialogueType() == || $this->dialogueObj->getDialogueType() == 4) && $searchFilter == "ROLE_DTS" ) {
  296.                 $joGroupObj $this->em->getRepository(JoGroup::class)->findOneBy(array('Dialogue' => $this->dialogueObj));
  297.                 
  298.                 $predefinedCaseCardAll $this->em->getRepository(PredefinedCaseCard::class)->fetchGroupPredefinedCaseCardListByType($searchFilter$joGroupObj->getJoMasterInformation()->getInfoType(), $joGroupObj->getJoMasterInformation()->getKkorg());
  299.             } else if(($this->dialogueObj->getDialogueType() == 4) && $searchFilter == "ROLE_CSV" ) {
  300.                 $joGroupObj $this->em->getRepository(JoGroup::class)->findOneBy(array('Dialogue' => $this->dialogueObj));
  301.                 $predefinedCaseCardAll $this->em->getRepository(PredefinedCaseCard::class)->findBy(array('userType' => $searchFilter'isForGroup' => 1));
  302.             }
  303.         }
  304.         $dialogueCaseCardAll $this->em->getRepository(DialogueCaseCard::class)->findBy(array('dialogue' => $this->dialogueObj));
  305.         $userCreatedCaseCardsId $userCreatedDialogueCaseCard = array();
  306.         foreach ($dialogueCaseCardAll as $dialogueCaseCard) {
  307.             if (!$dialogueCaseCard->getIsClosed()) {
  308.                 $userCreatedCaseCardsId[] = $dialogueCaseCard->getPCaseCardId()->getId();
  309.                 $userCreatedDialogueCaseCard[$dialogueCaseCard->getPCaseCardId()->getId()] = $dialogueCaseCard;
  310.             }
  311.         }
  312.         $dialogueCaseCardMeasureAll $this->em->getRepository(DialogueCaseCardMeasure::class)->fetchMeasureTilDateMedcom('F',new \DateTime());
  313.         return $this->render('medcom/_journalize.twig', array(
  314.             'thisID' => $request->get("id"),
  315.             "userCreatedDialogueCaseCard" => $userCreatedDialogueCaseCard,
  316.             'predefinedCaseCardAll' => $predefinedCaseCardAll,
  317.             'dialogueCaseCardMeasureAll' => $dialogueCaseCardMeasureAll,
  318.             'userCreatedCaseCardsId' => $userCreatedCaseCardsId,
  319.             'patientObj' => $this->patientObj,
  320.             'dialogueObj' => $this->dialogueObj,
  321.             'areaNames' => $this->areaNames,
  322.             'dateDiff' => $this->dateDiff,
  323.             'info' => $this->Info
  324.         ));
  325.     }
  326.     public function journalized(Request $request) {
  327.         $this->auth($request);
  328.         $id $request->get("id");
  329.         $repo $this->em->getRepository(MedComCorrespondence::class);
  330.         $_cor $repo->fetechCorrespondenceJournal($id);
  331.         if($id != null && $id != && count($_cor) != 0) {
  332.             $cor $_cor[0];
  333.             return $this->render('medcom/_journalized.twig', array(
  334.                 'journal' => true,
  335.                 'patientObj' => $this->patientObj,
  336.                 'dialogueObj' => $this->dialogueObj,
  337.                 'areaNames' => $this->areaNames,
  338.                 'dateDiff' => $this->dateDiff,
  339.                 'type' => "3",
  340.                 'thisID' => $request->get("id"),
  341.                 'cor' => $_cor,
  342.                 'info' => $this->Info,
  343.                 'medcomSpecialtyCodes' => $this->getMedComSpecialtyCodes(),
  344.             ));
  345.         }
  346.     }
  347.     public function saveJournalize(Request $request) {
  348.         $this->auth($request);
  349.         $id $request->get('id');
  350.         $repo $this->em->getRepository(MedComCorrespondence::class);
  351.         $_cor $repo->fetechCorrespondence($id);
  352.         if($id != null && $id != && count($_cor) != 0) {
  353.             $cor $_cor[0];
  354.             $dialogueCaseCard $request->get('dialogueCaseCard');
  355.             $predefinedCaseCardId $request->get('predefinedCaseCardId');
  356.             $dialogueCaseCardMeasureId $request->get('dialogueCaseCardMeasureId');
  357.             $measureId $request->get('measureId');
  358.             
  359.             $dialogueCaseCardObj $this->em->getRepository(DialogueCaseCard::class)->find($dialogueCaseCard);
  360.             $predefinedCaseCardObj $this->em->getRepository(PredefinedCaseCard::class)->find($predefinedCaseCardId);
  361.             $predefinedAttachmentTypeObj $this->em->getRepository(PredefinedAttachmentType::class)->findOneBy(array('attachmentType' => 'medcom')); //Medcom
  362.     
  363.     
  364.             $dialogueAttachmentDetailObj = new DialogueAttachmentDetails();
  365.             $dialogueAttachmentDetailObj->setPCaseCardId($predefinedCaseCardObj);
  366.             $dialogueAttachmentDetailObj->setPatient($this->patientObj);
  367.             $dialogueAttachmentDetailObj->setDialogue($this->dialogueObj);
  368.             if($dialogueCaseCardObj){
  369.                 $dialogueAttachmentDetailObj->setDialogueCaseCard($dialogueCaseCardObj);
  370.             }
  371.             
  372.             $dialogueCaseCardMeasureObj $this->em->getRepository(DialogueCaseCardMeasure::class)->find($dialogueCaseCardMeasureId);
  373.             $dialogueAttachmentDetailObj->setDialogueCaseCardMeasureId($dialogueCaseCardMeasureObj);
  374.             $caseCardMeasureObj $this->em->getRepository(CasecardMeasure::class)->find($measureId);
  375.             $dialogueAttachmentDetailObj->setMeasureId($caseCardMeasureObj);
  376.             
  377.             $dialogueAttachmentDetailObj->setUser($this->user);
  378.     
  379.             $dialogueAttachmentDetailObj->setPAtttachmentType($predefinedAttachmentTypeObj);
  380.             if($this->dialogueObj->getDialogueType() == || $this->dialogueObj->getDialogueType() == 2){
  381.                 $dialogueAttachmentDetailObj->setAttachmentDate(new \DateTime());
  382.             }else{
  383.                 $dialogueAttachmentDetailObj->setAttachmentDate($cor->getUpdatedAt());
  384.             }
  385.             $dialogueAttachmentDetailObj->setIsDraft(false);
  386.             $dialogueAttachmentDetailObj->setVisibleStatus(0);
  387.             $dialogueAttachmentDetailObj->setActivityType(11);
  388.             
  389.             $heading $cor->getSubject();
  390.             $dialogueAttachmentDetailObj->setAttachmentHeading($heading);
  391.             
  392.             $this->em->persist($dialogueAttachmentDetailObj);
  393.             $this->em->flush();
  394.             $ccID $dialogueAttachmentDetailObj->getId();
  395.             $cor->journalize($ccID);
  396.             $this->em->persist($cor);
  397.             $this->em->flush();
  398.             return new Response(json_encode('success:'.$ccID), Response::HTTP_OK,['content-type' => "text/json"]);
  399.         }
  400.         return new Response(json_encode('error:true'), Response::HTTP_OK,['content-type' => "text/json"]);
  401.     }
  402.     public function send(Request $request) {
  403.         $this->auth($request);
  404.         $type = ($request->get("submit") == "send" 1);
  405.         $type = ($request->get("submit") == "inbox" $type);
  406.         //$obj = $this->em->getRepository(MedComCorrespondence::class);
  407.         $repo $this->em->getRepository(MedComCorrespondence::class);
  408.         $repo->setEm($this->em);
  409.         //$this->getMedComData();
  410.         //$medcom = $this->getMedComData($request->get("medcom_user"));
  411.         $cor;
  412.         if($request->files->get("new_medcom_file") != null) {
  413.             //$ean = ($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : (isset($this->ean[$medcom["ParentSorId"]]) ? $this->ean[$medcom["ParentSorId"]] : ""));
  414.             $cor $repo->insert($request->get("medcom_user"), $request->get("subject"), $this->user$this->patientObj$request->get("priority"), $request->get("message"), $type,false);
  415.             $i 1;
  416.             foreach($request->files->get("new_medcom_file") as $f) {
  417.                 $file file_get_contents($f);
  418.                 $ext pathinfo($f->getClientOriginalName(), PATHINFO_EXTENSION);
  419.                 $filename pathinfo($f->getClientOriginalName(), PATHINFO_FILENAME);
  420.                 $base base64_encode($file);
  421.                 $filesize filesize($f);
  422.                 $obj $repo->insertFileOnly($filesize,$request->get("medcom_user"), $this->user$this->patientObj,$type,$filename,$ext,$base,$cor,$request->get("priority"));
  423.                 $obj->setParentID($repo->lastMessageID);
  424.                 $this->em->persist($obj);
  425.                 $this->em->flush();
  426.                 if($request->get("submit") != 2) {
  427.                     $medcom $repo->getMedcomList($cor->getMedComUser());
  428.                     $ean $medcom->getEAN();
  429.                     $_xml $this->getXmlbin01($obj,$medcom);
  430.                     $xml $this->getVansXml($_xml"xbin01"$ean$repo);
  431.                     $myfile fopen("Medcom/Out/".$repo->lastMessageID."_file".$i.".xml""w") or die("Unable to open file!");
  432.                     fwrite($myfile$xml->asXML());
  433.                     fclose($myfile);
  434.                     $i++;
  435.                 }
  436.             }
  437.         } else {
  438.             $cor $repo->insert($request->get("medcom_user"), $request->get("subject"), $this->user$this->patientObj$request->get("priority"), $request->get("message"), $type);
  439.         }
  440.         if($request->get("submit") != 2) {
  441.             $medcom $repo->getMedcomList($cor->getMedComUser());
  442.             $ean $medcom->getEAN();
  443.             $_obj $repo->fetechMessage($repo->lastMessageID);
  444.             $obj $_obj[0];
  445.             $files $repo->fetechMessageParent($repo->lastMessageID);
  446.             $_xml $this->getXmlDis91($obj$cor$medcom$files);
  447.             $xml $this->getVansXml($_xml"xdis91"$ean$repo);
  448.             $myfile fopen("Medcom/Out/".$repo->lastMessageID.".xml""w") or die("Unable to open file!");
  449.             fwrite($myfile$xml->asXML());
  450.             fclose($myfile);
  451.         }
  452.         return new Response(json_encode('success:'.$repo->lastMessageID), Response::HTTP_OK,['content-type' => "text/json"]);
  453.     }
  454.     public function sendDraft(Request $request) {
  455.         $this->auth($request);
  456.         
  457.         //$obj = $this->em->getRepository(MedComCorrespondence::class);
  458.         $repo $this->em->getRepository(MedComCorrespondence::class);
  459.         $repo->setEm($this->em);
  460.         $id $request->get("objID");
  461.         $_msg $repo->fetechMessage($id);
  462.         if($_msg != null) {
  463.             $msg $_msg[0];
  464.             $cor $msg->getCorrospondence();
  465.             $msg->sendDraft();
  466.             $this->em->persist($msg);
  467.             $this->em->flush();
  468.             $cor->sendDraft();
  469.             $this->em->persist($cor);
  470.             $this->em->flush();
  471.             $medcom $repo->getMedcomList($cor->getMedComUser());
  472.             $ean $medcom->getEAN();
  473.             $files $repo->fetechMessageParent($id);
  474.             $_xml $this->getXmlDis91($msg$cor$medcom$files);
  475.             $xml $this->getVansXml($_xml"xdis91"$ean$repo);
  476.             $myfile fopen("Medcom/Out/".$id.".xml""w") or die("Unable to open file!");
  477.             fwrite($myfile$xml->asXML());
  478.             fclose($myfile);
  479.             $i 1;
  480.             foreach($files as $file) {
  481.                 $_xml $this->getXmlbin01($file,$medcom);
  482.                 $xml $this->getVansXml($_xml"xbin01"$ean$repo);
  483.                 $_myfile fopen("Medcom/Out/".$id."_file".$i.".xml""w") or die("Unable to open file!");
  484.                 fwrite($_myfile$xml->asXML());
  485.                 fclose($_myfile);
  486.                 $i++;
  487.             }
  488.         } else {
  489.             return $this->redirectToRoute("medcom_drafts");
  490.         }
  491.         return $this->redirectToRoute("medcom_index");
  492.     }
  493.     public function edi(Request $request) {
  494.     }
  495.     private function getVansXml($xml$code$ean,$repo) {
  496.         $baseData base64_encode($xml);
  497.         $size = (int) (strlen(rtrim($baseData'=')) * 4);                
  498.         $env = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><VANSEnvelope />');
  499.         $env->addAttribute("xmlns""urn:oio:medcom:vans-envelope:1.0.4");
  500.         $esend $env->addChild('SenderID'$this->EANS);
  501.         $esend->addAttribute("EndPointType""EAN");
  502.         $erec $env->addChild('ReceiverID'$ean);
  503.         $erec->addAttribute("EndPointType""EAN");
  504.         $env->addChild('EnvelopeIdentifier'$repo->create_guid());
  505.         $env->addChild('SentDateTime'date("Y-m-d")."T".date("H:i:s"));
  506.         $message $env->addChild("Message");
  507.             $meta $message->addChild('MetaInformation');
  508.                 $meta->addChild('Identifier'$repo->create_guid());
  509.                 $doc $meta->addChild('Document');
  510.                 $doc->addChild('Format'"XML");
  511.                 if($code == "xdis91") {
  512.                     $doc->addChild('Name','MCM:XDIS19');
  513.                     $doc->addChild('Version'"XD9134L");
  514.                 }
  515.                 elseif($code == "xctl02") {
  516.                     $doc->addChild('Name','MCM:XCTL02');
  517.                     $doc->addChild('Version'"XC0230Q");
  518.                 }
  519.                 elseif($code == "xctl03") {
  520.                     $doc->addChild('Name','MCM:XCTL03');
  521.                     $doc->addChild('Version'"XC0330Q");
  522.                 }
  523.                 elseif($code == "xbin01") {
  524.                     $doc->addChild('Name','MCM:XBIN01');
  525.                     $doc->addChild('Version'"XB0131X");
  526.                 }
  527.                 $doc->addChild('SizeInBytes'$size);
  528.             $data $message->addChild('Data'$baseData);
  529.         return $env;
  530.     }
  531.     public function vans(Request $request$code$_id null$_refuseCode null$_refuseText null$_ean null) {
  532.         $this->auth($request);
  533.         $id = ($_id != null $_id $request->get("id"));
  534.         $refuseText = ($_refuseText != null $_refuseText $request->get("RefuseText"));
  535.         $refuseCode = ($_refuseCode != null $_refuseCode $request->get("RefuseCode"));
  536.         if($id != null) {
  537.             //$obj = $this->em->getRepository(MedComMessages::class)->findOneBy(array('id' => intval($id)));        $repo = $this->em->getRepository(MedComCorrespondence::class);
  538.             //$obj = $this->em->getRepository(MedComMessages::class)->createQueryBuilder("m")->where("m.id LIKE :id")->setParameter("id",$id)->getQuery()->getResult();
  539.             $repo $this->em->getRepository(MedComCorrespondence::class);
  540.             $repo->setEm($this->em);
  541.             $_obj $repo->fetechMessage($id);
  542.             if(count($_obj) != 0) {
  543.                 $obj $_obj[0];
  544.                 $cor $obj->getCorrospondence();
  545.                 /*$this->getMedComData();
  546.                 $medcom = null;
  547.                 if($cor != null)
  548.                     $medcom = $this->getMedComData($cor->getMedComUser());
  549.                 $ean = ($_ean != null ? $_ean : ($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : $this->ean[$medcom["ParentSorId"]]));
  550.                 $ean = ($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : $this->ean[$medcom["ParentSorId"]]);
  551.                 */
  552.                 $medcom $repo->getMedcomList($cor->getMedComUser());
  553.                 $ean $medcom->getEAN();
  554.                 $orgVersionCode = (strtolower($obj->getType()) == "bilag"  "XB0131X" "XD9134L");
  555.                 $files $repo->fetechMessageParent($id);
  556.                 if($code == "xdis91")
  557.                 $_xml $this->getXmlDis91($obj$cor$medcom$files);
  558.                 elseif($code == "xctl02")
  559.                 $_xml $this->getXmlctl02($obj$cor$medcom$ean,$orgVersionCode$refuseCode$refuseText);
  560.                 elseif($code == "xctl03")
  561.                 $_xml $this->getXmlctl03($obj$cor$medcom$ean);
  562.                 elseif($code == "xbin01")
  563.                 $_xml $this->getXmlbin01($obj$medcom);
  564.                 else
  565.                 return new Response("ERROR");
  566.                 $xml $_xml->asXML();
  567.                 $env $this->getVansXml($xml$code$ean$repo);
  568.                 /*$baseData = base64_encode($xml);
  569.                 $size = (int) (strlen(rtrim($baseData, '=')) * 3 / 4);                $env = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><VANSEnvelope />');
  570.                 $env->addAttribute("xmlns", "urn:oio:medcom:vans-envelope:1.0.4");
  571.                 //$env->addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
  572.                 //$env->addAttribute("xmlns:schemaLocation", "urn:oio:medcom:vans-envelope:1.0.4 http://svn.medcom.dk/svn/drafts/VANSEnvelope/VANSEnvelope_1.0.4.xsd");
  573.                 $esend = $env->addChild('SenderID', $this->EANS);
  574.                 $esend->addAttribute("EndPointType", "EAN");
  575.                 $erec = $env->addChild('ReceiverID', $ean);
  576.                 $erec->addAttribute("EndPointType", "EAN");
  577.                 $env->addChild('EnvelopeIdentifier', $repo->create_guid());
  578.                 $env->addChild('SentDateTime', date("Y-m-d")."T".date("H:i:s"));
  579.                 $message = $env->addChild("Message");
  580.                     $meta = $message->addChild('MetaInformation');
  581.                         $meta->addChild('Identifier', $repo->create_guid());
  582.                         $doc = $meta->addChild('Document');
  583.                         $doc->addChild('Format', "XML");
  584.                         if($code == "xdis91") {
  585.                             $doc->addChild('Name','MCM:XDIS19');
  586.                             $doc->addChild('Version', "XD9134L");
  587.                         }
  588.                         elseif($code == "xctl02") {
  589.                             $doc->addChild('Name','MCM:XCTL02');
  590.                             $doc->addChild('Version', "XC0230Q");
  591.                         }
  592.                         elseif($code == "xctl03") {
  593.                             $doc->addChild('Name','MCM:XCTL03');
  594.                             $doc->addChild('Version', "XC0330Q");
  595.                         }
  596.                         elseif($code == "xbin01") {
  597.                             $doc->addChild('Name','MCM:XBIN01');
  598.                             $doc->addChild('Version', "XB0131X");
  599.                         }
  600.                         $doc->addChild('SizeInBytes', $size);
  601.                     $data = $message->addChild('Data', $baseData);*/
  602.                     $vans_exist $repo->fetechMessageParentVans($obj->getId(),$code);
  603.                     if(true) {
  604.                         $vans MedComMessages::withInsert($code,$ean,null,$cor,4,'Vans'.$code,false);
  605.                         $vans->setFileData($env->asXML());
  606.                         $vans->setParentID($obj->getId());
  607.                         $this->em->persist($vans);
  608.                         $this->em->flush();
  609.                         if(count($vans_exist) != 0) {
  610.                             $vans_exist[0]->setType("VansExpired");
  611.                             $this->em->persist($vans_exist[0]);
  612.                             $this->em->flush();
  613.                         }
  614.                     }
  615.                 $res = new Response($env->asXML(), Response::HTTP_OK,['content-type' => "text/xml"]);
  616.                 $res->setCharset('ISO-8859-1');
  617.                 return $res;
  618.             }
  619.             return new Response("ERROR");
  620.         }
  621.         return new Response("ERROR");
  622.     }
  623.     public function _receiveVans(Request $request) {
  624.         $repo $this->em->getRepository(MedComCorrespondence::class);
  625.         $repo->setEm($this->em);
  626.         $files scandir('Medcom/In');
  627.         foreach($files as $file) {
  628.             if(is_dir('Medcom/In/'.$file) == false) {
  629.                 $xml_ simplexml_load_file('Medcom/In/'.$file);
  630.                 $xml = ($xml_->VANSEnvelope != null && $xml_->VANSEnvelope != "" $xml_->VANSEnvelope $xml_);
  631.                 $ean $xml->SenderID;
  632.                 $EnvelopeIdentifier $xml->EnvelopeIdentifier;
  633.                 
  634.                 $code $xml->Message->MetaInformation->Document->Version;
  635.                 $id 0;
  636.                 $_xml;
  637.                 $messageBase $xml->Message->Data;
  638.                 $message base64_decode($messageBase);
  639.                 $check_size_in_bytes = (int) (strlen(rtrim($message'=')) * 4);
  640.                 //var_dump($check_size_in_bytes);
  641.                 //exit;
  642.                 $vans MedComMessages::withInsert($code,$ean,null,null,4,'Vans',false);
  643.                 $vans->setFileData($xml->asXML());
  644.                 $this->em->persist($vans);
  645.                 $this->em->flush();
  646.                 $var $this->receiveXml($request$message);
  647.                 if($var != null) {
  648.                     $myfile fopen("Medcom/Out/".$EnvelopeIdentifier.".kvittering.xml""w") or die("Unable to open file!");
  649.                     fwrite($myfile$var->asXML());
  650.                     fclose($myfile);
  651.                 }
  652.                 unlink('Medcom/In/'.$file);
  653.             }
  654.         }
  655.     }
  656.     public function receiveVans(Request $request) {
  657.         exit;
  658.     }
  659.     public function xml(Request $request) {
  660.         $this->auth($request);
  661.         $id $request->get("id");
  662.         if($id != null) {
  663.             //$obj = $this->em->getRepository(MedComMessages::class)->findOneBy(array('id' => intval($id)));        $repo = $this->em->getRepository(MedComCorrespondence::class);
  664.             //$obj = $this->em->getRepository(MedComMessages::class)->createQueryBuilder("m")->where("m.id LIKE :id")->setParameter("id",$id)->getQuery()->getResult();
  665.             $repo $this->em->getRepository(MedComCorrespondence::class);
  666.             $repo->setEm($this->em);
  667.             $_obj $repo->fetechMessage($id);
  668.             if(count($_obj) != 0) {
  669.                 $obj $_obj[0];
  670.                 $cor $obj->getCorrospondence();
  671.                 //$this->getMedComData();
  672.                 //$medcom = $this->getMedComData($cor->getMedComUser());
  673.                 $medcom $repo->getMedcomList($cor->getMedComUser());
  674.                 $files $repo->fetechMessageParent($id);
  675.                 $last9 $repo->fetechMessageLast9($id,$cor);
  676.                 $emssage $this->getXmlDis91($obj$cor$medcom,$files,$last9);
  677.                 $res = new Response($emssage->asXML(), Response::HTTP_OK,['content-type' => "text/xml"]);
  678.                 $res->setCharset('ISO-8859-1');
  679.                 return $res;
  680.             }
  681.             return new Response("ERROR");
  682.         }
  683.         return new Response("ERROR");
  684.     }
  685.     public function xml02(Request $request$_id null$_refuseText null$_refuseCode null$_ean null$_orgVersionCode null) {
  686.         $this->auth($request);
  687.         $id = ($_id != null $_id $request->get("id"));
  688.         $refuseText = ($_refuseText != null $_refuseText $request->get("RefuseText"));
  689.         $refuseCode = ($_refuseCode != null $_refuseCode $request->get("RefuseCode"));
  690.         if($id != null) {
  691.             //$obj = $this->em->getRepository(MedComMessages::class)->findOneBy(array('id' => intval($id)));        $repo = $this->em->getRepository(MedComCorrespondence::class);
  692.             //$obj = $this->em->getRepository(MedComMessages::class)->createQueryBuilder("m")->where("m.id LIKE :id")->setParameter("id",$id)->getQuery()->getResult();
  693.             $repo $this->em->getRepository(MedComCorrespondence::class);
  694.             $repo->setEm($this->em);
  695.             $_obj $repo->fetechMessage($id);
  696.             if($_obj != null && count($_obj) != 0) {
  697.                 $obj $_obj[0];
  698.                 $cor $obj->getCorrospondence();
  699.                 $orgVersionCode = ($_orgVersionCode != null $_orgVersionCode : (strtolower($obj->getType()) == "bilag"  "XB0131X" "XD9134L"));
  700.                 //$this->getMedComData();
  701.                 /*$medcom = null;
  702.                 /*if($cor != null)
  703.                     $medcom = $this->getMedComData($cor->getMedComUser());
  704.                 $ean = ($_ean != null ? $_ean : ($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : $this->ean[$medcom["ParentSorId"]]));
  705.                 */
  706.                 $medcom $repo->getMedcomList($cor->getMedComUser());
  707.                 $ean $medcom->getEAN();
  708.                 $emssage $this->getXmlctl02($obj,$cor,$medcom,$ean,$orgVersionCode,$refuseCode,$refuseText);
  709.                 $res = new Response($emssage->asXML(), Response::HTTP_OK,['content-type' => "text/xml"]);
  710.                 $res->setCharset('ISO-8859-1');
  711.                 return $res;
  712.             }
  713.             return new Response("ERROR");
  714.         }
  715.         return new Response("ERROR");
  716.     }
  717.     public function xml03(Request $request$_id null$_ean null) {
  718.         $this->auth($request);
  719.         $id = ($_id != null $_id $request->get("id"));
  720.         if($id != null) {
  721.             //$obj = $this->em->getRepository(MedComMessages::class)->findOneBy(array('id' => intval($id)));        $repo = $this->em->getRepository(MedComCorrespondence::class);
  722.             //$obj = $this->em->getRepository(MedComMessages::class)->createQueryBuilder("m")->where("m.id LIKE :id")->setParameter("id",$id)->getQuery()->getResult();
  723.             $repo $this->em->getRepository(MedComCorrespondence::class);
  724.             $repo->setEm($this->em);
  725.             $_obj $repo->fetechMessage($id);
  726.             if(count($_obj) != 0) {
  727.                 $obj $_obj[0];
  728.                 $cor $obj->getCorrospondence();
  729.                 //$this->getMedComData();
  730.                 /*$medcom = null;
  731.                 if($cor != null)
  732.                     $medcom = $this->getMedComData($cor->getMedComUser());
  733.                 $ean = ($_ean != null ? $_ean : ($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : $this->ean[$medcom["ParentSorId"]]));
  734.                 */
  735.                 $medcom $repo->getMedcomList($cor->getMedComUser());
  736.                 $ean $medcom->getEAN();
  737.                 $emssage $this->getXmlctl03($obj,$cor,$medcom,$ean);
  738.                 $res = new Response($emssage->asXML(), Response::HTTP_OK,['content-type' => "text/xml"]);
  739.                 $res->setCharset('ISO-8859-1');
  740.                 return $res;
  741.             }
  742.             return new Response("ERROR");
  743.         }
  744.         return new Response("ERROR");
  745.     }
  746.     public function xml04(Request $request) {
  747.         $this->auth($request);
  748.         $id $request->get("id");
  749.         if($id != null) {
  750.             //$obj = $this->em->getRepository(MedComMessages::class)->findOneBy(array('id' => intval($id)));        $repo = $this->em->getRepository(MedComCorrespondence::class);
  751.             //$obj = $this->em->getRepository(MedComMessages::class)->createQueryBuilder("m")->where("m.id LIKE :id")->setParameter("id",$id)->getQuery()->getResult();
  752.             $repo $this->em->getRepository(MedComCorrespondence::class);
  753.             $repo->setEm($this->em);
  754.             $_obj $repo->fetechMessage($id);
  755.             if(count($_obj) != 0) {
  756.                 $obj $_obj[0];
  757.                 $cor $obj->getCorrospondence();
  758.                 //$this->getMedComData();
  759.                 //$medcom = $this->getMedComData($cor->getMedComUser());
  760.                 $medcom $repo->getMedcomList($cor->getMedComUser());
  761.                 $emssage $this->getXmlbin01($obj,$medcom);
  762.                 $res = new Response($emssage->asXML(), Response::HTTP_OK,['content-type' => "text/xml"]);
  763.                 $res->setCharset('ISO-8859-1');
  764.                 return $res;
  765.             }
  766.             return new Response("ERROR");
  767.         }
  768.         return new Response("ERROR");
  769.     }
  770.     public function receiveXml(Request $request$vansXml null) {
  771.         $this->em $this->getDoctrine()->getManager();
  772.         $repo $this->em->getRepository(MedComCorrespondence::class);
  773.         $repo->setEm($this->em);
  774.         if (file_exists('import.xml') || $vansXml != null) {
  775.             $xml_ = ($vansXml != null simplexml_load_string($vansXml) : simplexml_load_file('import.xml'));
  776.             $xml = ($xml_->Emessage != null && $xml_->Emessage != "" $xml_->Emessage $xml_);
  777.             $id 0;
  778.             $_xml;
  779.             $moveFoward true;
  780.             if(isset($xml->ClinicalEmail) && $xml->ClinicalEmail !== null && $xml->ClinicalEmail !== "") {
  781.                 $moveFoward false;
  782.                 $_xml $xml->ClinicalEmail;
  783.                 $id $xml->Letter->EpisodeOfCareIdentifier;
  784.                 if($id === "" && $id === "")
  785.                     $id str_replace("-","",$repo->create_guid());;
  786.                 $_obj =  $repo->fetechCorrespondenceUUID($id);
  787.                 $_message "";
  788.                 $subject $_xml->AdditionalInformation->Subject;
  789.                 $cpr $_xml->Patient->CivilRegistrationNumber;
  790.                 $sender $_xml->Sender->EANIdentifier;
  791.                 $receiver $_xml->Receiver->EANIdentifier;
  792.                 $_MedicalSpecialityCode $_xml->Sender->MedicalSpecialityCode;
  793.                 $MedicalSpecialityCode = ($_MedicalSpecialityCode !== null && $_MedicalSpecialityCode !== "" $_MedicalSpecialityCode null);
  794.                 $envID $xml->Envelope->Identifier;
  795.                 $letterID $_xml->Letter->Identifier;
  796.                 $VersionCode $_xml->Letter->VersionCode;
  797.                 $TypeCode $_xml->Letter->TypeCode;
  798.                 $_prio $_xml->AdditionalInformation->Priority;
  799.                 $prio = ($_prio == "høj_prioritet" true false);
  800.                 foreach($xml->ClinicalEmail->ClinicalInformation->Text01 as $_txt) {
  801.                     $_message .= strip_tags($_txt->asXml(), "<Break>");
  802.                 }
  803.                 $message str_replace("<Break/>""\r\n"$_message);
  804.                 $message str_replace("<Break />""\r\n"$message);
  805.                 $message str_replace("<break/>""\r\n"$message);
  806.                 $message str_replace("<break />""\r\n"$message);
  807.                 $_error false;
  808.                 $_id $letterID;
  809.                 $_refuseCode "ikke_specificeret";
  810.                 $_refuseText;
  811.                 $_ean null;
  812.                 $medcom;
  813.                 //if(!isset($receiver) || $receiver == null || $receiver == "" &&  $receiver == $this->EANS) { $_refuseCode = "problem_med_modtagerID"; $_refuseText = "Denne meddelelse er sendt til forkert modtager"; $_error = true; }
  814.                 if(!isset($subject) || $subject == null || $subject == "") { $subject "ikke_specificeret"$_refuseText "Emnetekst mangler"$_error true; }
  815.                 if(!isset($cpr) || $cpr == null || $cpr == "") { $_refuseText "cpr mangler"$_error true; }
  816.                 if(!isset($sender) || $sender == null || $sender == "") { $sender "ikke_specificeret"$_refuseText "EANIdentifier for sender mangler"$_error true; } else {
  817.                     $medcom $repo->getMedcomList($sender);
  818.                     $_ean=$sender;
  819.                     if($medcom == null) {
  820.                         $sender "ikke_specificeret"$_refuseText "EANIdentifier for sender er ikke i Sor Liste"$_error true;
  821.                     }
  822.                     /*$medcom = $this->getMedComData($sender);
  823.                     if(!isset($medcom["SorId"]) || $medcom["SorId"] == null || $medcom["SorId"] == "") { $sender = "ikke_specificeret"; $_refuseText = "EANIdentifier for sender er ikke i Sor Liste"; $_error = true; } else {
  824.                         $medcom_user = $medcom["SorId"];
  825.                     }*/
  826.                 }
  827.                 if(!isset($letterID) || $letterID == null || $letterID == "") { $_refuseText "Brev id mangler for sender mangler"$_error true; }
  828.                 if(!isset($_prio) || $_prio == null || $_prio == "") { $_refuseText "Prioritet mangler"$_error true; }
  829.                 if(!isset($VersionCode) || $VersionCode == null || $VersionCode == "" || $VersionCode != "XD9134L") { $_refuseCode "problem_med_version"$_refuseText "Ugyldig VersionCode ".$VersionCode." understoettes ikke"$_error true; }
  830.                 if(!isset($TypeCode) || $TypeCode == null || $TypeCode == "" || $TypeCode != "XDIS91") { $_refuseText "Ugyldig TypeCode ".$TypeCode." understoettes ikke"$_error true; }
  831.                 $msg_exist =  $repo->fetechMessageUUID($letterID);
  832.                 $m_id 0;
  833.                 $cor;
  834.                 if(count($_obj) != 0) {
  835.                     $cor $_obj[0];
  836.                     $m MedComMessages::withInsert($message,"",null,$cor,3,'Korrespondancebrev',$prio);
  837.                     $m->setMedicalSpecialityCode($MedicalSpecialityCode);
  838.                     $m->setDeleted(($_error true false)); $m->setUUID($letterID); $m->setEUUID($envID); $this->em->persist($m); $this->em->flush();
  839.                     $m_id=$m->getId();
  840.                     $cor->setDeleted(($_error true false)); $cor->setStatus(3); $this->em->persist($cor); $this->em->flush();
  841.                 } else {
  842.                     $this->patientObj $this->em->getRepository(Patient::class)->findOneBy(array('cpr' => $cpr));
  843.                     $cor $repo->insertUUID($sender$subjectnull$this->patientObj$prio$message3$id$letterID$envID$MedicalSpecialityCode);
  844.                     $cor->setDeleted(($_error true false)); $this->em->persist($cor); $this->em->flush();
  845.                     $m_id=$repo->lastMessageID;
  846.                 }
  847.                 foreach($_xml->Reference as $ref) {
  848.                     if(isset($ref->RefDescription) && $ref->RefDescription == "BIN") {
  849.                         $this->patientObj $this->em->getRepository(Patient::class)->findOneBy(array('cpr' => $cpr));
  850.                         $VersionCode $ref->Letter->VersionCode;
  851.                         $ext $ref->BIN->ObjectExtensionCode;
  852.                         $filesize $ref->BIN->OriginalObjectSize;
  853.                         $date date_create();
  854.                         $_objID $ref->BIN->ObjectIdentifier;
  855.                         $objID $repo->guid_line($_objID);
  856.                         $_extFile $repo->fetechMessageFileGUID($objID,"true");
  857.                         if(count($_extFile) != 0) {
  858.                             $obj $_extFile[0];
  859.                             $old_cor $obj->getCorrospondence();
  860.                             if($old_cor != null && count($old_cor) != 0) {
  861.                                 $old_cor->setDeleted(true);
  862.                                 $this->em->persist($old_cor);
  863.                                 $this->em->flush();
  864.                             }
  865.                             $obj->setCor($cor); 
  866.                             $obj->setParentID($m_id);
  867.                         }
  868.                         else {
  869.                             $obj $repo->insertFileOnly($filesize,$sender,null,$this->patientObj,3,"bilag.".date_timestamp_get($date),$ext,null,$cor,false,$objID);
  870.                             $obj->setParentID($m_id);
  871.                         }
  872.                         //$obj = $repo->insertFileOnly($filesize,$_xml->Sender->Identifier, null, $this->patientObj, 3, "bilag.".$ext,$ext,$_xml->BinaryObject->Object_Base64Encoded);
  873.                         $obj->setDeleted(($_error true false)); 
  874.                         $_id $obj->getId();
  875.                         $this->em->persist($obj);
  876.                         $this->em->flush();
  877.                     }
  878.                 }
  879.                 if(count($msg_exist) == null || count($msg_exist) == || $msg_exist[0]->getReceipt() != true || ($msg_exist !== null && $msg_exist[0]->getEUUID() != $envID)) {
  880.                     $msg null;
  881.                     if($_error) {
  882.                         $msg =  $repo->fetechMessageUUID($letterID);
  883.                         $msg[0]->setReceipt(true);
  884.                         $this->em->persist($msg[0]);
  885.                         $this->em->flush();
  886.                         $_id $msg[0]->getID();
  887.                         //send it
  888.                         if($vansXml != null) {
  889.                             $_xdisXml $this->getXmlctl02($msg[0],$cor,null,$sender,$VersionCode,$_refuseCode,$_refuseText);
  890.                             return $this->getVansXml($_xdisXml"xctl02"$sender$repo);
  891.                             //return $this->vans($request,"xctl02",$_id,$_refuseText,$_refuseCode,$_ean);
  892.                         }
  893.                         return $this->xml02($request,$_id,$_refuseText,$_refuseCode,$_ean,$VersionCode.'');
  894.                     } else {
  895.                         $msg =  $repo->fetechMessageUUID($letterID);
  896.                         $msg[0]->setReceipt(true);
  897.                         $this->em->persist($msg[0]);
  898.                         $this->em->flush();
  899.                         $_id $msg[0]->getID();
  900.                         //send it
  901.                         if($vansXml != null) {
  902.                             $_xdisXml $this->getXmlctl03($msg[0],$cor,null,$sender);
  903.                             return $this->getVansXml($_xdisXml"xctl03"$sender$repo);
  904.                             //return $this->vans($request,"xctl03",$_id,"","",$sender);
  905.                         }
  906.                         return $this->xml03($request,$_id,$sender);
  907.                     }
  908.                     //set msg reciept to true here
  909.                 } else {
  910.                     //return new Response("ingen kvittering");
  911.                     return null;
  912.                 }
  913.             }
  914.             elseif(isset($xml->BinaryLetter) && $xml->BinaryLetter !== null && $xml->BinaryLetter !== "") {
  915.                 $moveFoward false;
  916.                 $_error false;
  917.                 $_refuseCode "ikke_specificeret";
  918.                 $_refuseText;
  919.                 $_xml $xml->BinaryLetter;
  920.                 $id $xml->Envelope->Identifier;
  921.                 //$_obj =  $repo->fetechCorrespondenceUUID($id);
  922.                 //$cor = null;
  923.                 //if(count($_obj) != 0) {
  924.                 //    $cor = $_obj[0];
  925.                 //}
  926.                 $cpr $_xml->Patient->CivilRegistrationNumber;
  927.                 $VersionCode $_xml->Letter->VersionCode;
  928.                 $sender $_xml->Sender->EANIdentifier;
  929.                 $envID $xml->Envelope->Identifier;
  930.                 $letterID $_xml->Letter->Identifier;
  931.                 $id $xml->Letter->EpisodeOfCareIdentifier;
  932.                 if($id === "" && $id === "")
  933.                     $id str_replace("-","",$repo->create_guid());;
  934.                 if(!isset($cpr) || $cpr == null || $cpr == "") { $_refuseText "cpr mangler"$_error true; }
  935.                 if(!isset($VersionCode) || $VersionCode == null || $VersionCode == "" || $VersionCode != "XB0131X") { $_refuseCode "problem_med_version"$_refuseText "Ugyldig VersionCode"$_error true; }
  936.                 $this->patientObj $this->em->getRepository(Patient::class)->findOneBy(array('cpr' => $cpr));
  937.                 $ext $_xml->BinaryObject->ObjectExtensionCode;
  938.                 $filesize $_xml->BinaryObject->OriginalObjectSize;
  939.                 $baseData $_xml->BinaryObject->Object_Base64Encoded;
  940.                 $check_size_in_bytes = (int) (strlen(rtrim($baseData'=')) * 4);
  941.                 if(!isset($filesize) || $filesize == null || $filesize == "" || $filesize != $check_size_in_bytes) { $_refuseCode "ikke_specificeret"$_refuseText "File stoerrelse stemmer ikke overens"$_error true; }
  942.                 $date date_create();
  943.                 $objID $_xml->BinaryObject->ObjectIdentifier;
  944.                 $_extFile $repo->fetechMessageFileGUID($objID);
  945.                 $obj null;
  946.                 //check if filesize is what it says it is
  947.                 $cor;
  948.                 if(count($_extFile) != null) {
  949.                     $extFile $_extFile[0];
  950.                     $cor $extFile->getCorrospondence();
  951.                     $obj $repo->insertFileOnly($filesize,$sender,null,$this->patientObj,3,"bilag.".date_timestamp_get($date),$ext,$baseData,$cor,false,$objID);
  952.                     $extFile->setDeleted(true);
  953.                     $this->em->persist($extFile);
  954.                     $this->em->flush();
  955.                 } else {
  956.                     $cor $repo->insertUUID($sender"Bilag uden meddelelse"null$this->patientObjfalse"bilag uden meddelelse"3$id$letterID$envID);
  957.                     $cor->setDeleted(($_error true false)); $this->em->persist($cor); $this->em->flush();
  958.                     $obj $repo->insertFileOnly($filesize,$sendernull$this->patientObj3"bilag.".date_timestamp_get($date),$ext,$baseData,$cor,false,$objID);
  959.                     $m_id=$repo->lastMessageID;
  960.                     $obj->setParentID($m_id);
  961.                 }
  962.                 $obj->setDeleted(($_error true false)); 
  963.                 $_id $obj->getId();
  964.                 $this->em->persist($obj);
  965.                 $this->em->flush();
  966.                 
  967.                 if($_error) {
  968.                     //send it
  969.                     if($vansXml != null) {
  970.                         $msg =  $repo->fetechMessageUUID($letterID);
  971.                         $_xdisXml $this->getXmlctl02($msg[0],$cor,null,$sender,$VersionCode,$_refuseCode,$_refuseText);
  972.                         return $this->getVansXml($_xdisXml"xctl02"$sender$repo);
  973.                     } else {
  974.                         if($cor != null)
  975.                             return $this->xml02($request,$_id,$_refuseText,$_refuseCode);
  976.                         return $this->xml02($request,$_id,$_refuseText,$_refuseCode,$sender->asXML());
  977.                     }
  978.                 } else {
  979.                     //send it
  980.                     if($vansXml != null) {
  981.                         $msg =  $repo->fetechMessageUUID($letterID);
  982.                         $_xdisXml $this->getXmlctl03($msg[0],$cor,null,$sender);
  983.                         return $this->getVansXml($_xdisXml"xctl03"$sender$repo);
  984.                     } else {
  985.                         if($cor != null)
  986.                             return $this->xml03($request,$_id);
  987.                         return $this->xml03($request,$_id,$sender->asXML());
  988.                     }
  989.                 }
  990.                 $moveFoward false;
  991.             } 
  992.             else if(isset($xml->NegativeReceipt) && $xml->NegativeReceipt !== null && $xml->NegativeReceipt !== "") {
  993.                 $_xml $xml->NegativeReceipt;
  994.                 $id $_xml->OriginalEmessage->OriginalLetter->OriginalLetterIdentifier;
  995.             } 
  996.             else if(isset($xml->PositiveReceipt) && $xml->PositiveReceipt != null && $xml->PositiveReceipt !== "") {
  997.                 $_xml $xml->PositiveReceipt;
  998.                 $id $_xml->OriginalEmessage->OriginalLetter->OriginalLetterIdentifier;
  999.             } 
  1000.             else if(isset($xml->NegativeVansReceipt) && $xml->NegativeVansReceipt !== null && $xml->NegativeVansReceipt !== "") {
  1001.                 $_xml $xml->NegativeVansReceipt;
  1002.                 $id $_xml->OriginalEmessage->OriginalLetter->OriginalLetterIdentifier;
  1003.             } 
  1004.             if($moveFoward) {
  1005.                 $_obj $repo->fetechMessageUUID($id);
  1006.                 $code $_xml->Letter->VersionCode;
  1007.                 $ean $_xml->Sender->EANIdentifier;
  1008.                 if(count($_obj) != 0) {
  1009.                     $obj $_obj[0];
  1010.                     $cor $obj->getCorrospondence();
  1011.                     $delivered true;
  1012.                     //$obj->setError(null);
  1013.                     //$obj->setErrorType(null);
  1014.                     if($_xml->OriginalEmessage->OriginalLetter->RefuseText != null && $_xml->OriginalEmessage->OriginalLetter->RefuseText != "") {
  1015.                         $rT $_xml->OriginalEmessage->OriginalLetter->RefuseText;
  1016.                         $rC $_xml->OriginalEmessage->OriginalLetter->RefuseCode;
  1017.                         $obj->setError($rC ' - ' .str_replace("<Break/>","<br />",$rT));
  1018.                         $obj->setErrorType($code);
  1019.                         $delivered false;
  1020.                         $cor->setStatus(3);
  1021.                         $this->em->persist($cor);
  1022.                         $this->em->flush();
  1023.                     }
  1024.                     if($_xml->OriginalEmessage->RefuseText != null && $_xml->OriginalEmessage->RefuseText != "") {
  1025.                         $rT $_xml->OriginalEmessage->RefuseText;
  1026.                         $rC $_xml->OriginalEmessage->RefuseCode;
  1027.                         $obj->setError('Afvist af VANS: '.$rC ' - ' .str_replace("<Break/>","<br />",$rT));
  1028.                         $obj->setErrorType($code);
  1029.                         $delivered false;
  1030.                         $cor->setStatus(3);
  1031.                         $this->em->persist($cor);
  1032.                         $this->em->flush();
  1033.                     }
  1034.                     $obj->setRecieptDate();
  1035.                     $obj->setDelivered($delivered);
  1036.                     $reciept MedComMessages::withInsert($code,$ean,null,$cor,4,'Kvittering',false);
  1037.                     $reciept->setFileData($xml->asXML());
  1038.                     $this->em->persist($obj);
  1039.                     $this->em->flush();
  1040.                     $reciept->setParentID($obj->getId());
  1041.                     $this->em->persist($reciept);
  1042.                     $this->em->flush();
  1043.                     //return new Response('success', Response::HTTP_OK,['content-type' => "text/json"]);
  1044.                     return true;
  1045.                 }
  1046.                 $reciept MedComMessages::withInsert($code,$ean,null,null,4,'Kvittering',false);
  1047.                 $reciept->setFileData($xml->asXML());
  1048.                 $this->em->persist($reciept);
  1049.                 $this->em->flush();
  1050.                 //return new Response('failure', Response::HTTP_OK,['content-type' => "text/json"]);
  1051.                 return false;
  1052.             }
  1053.         }
  1054.     } 
  1055.     public function reply(Request $request) {
  1056.         $this->auth($request);
  1057.         $type $request->get("type");//( == "send" ? 2 : 1);
  1058.         //$obj = $this->em->getRepository(MedComCorrespondence::class);
  1059.         $repo $this->em->getRepository(MedComCorrespondence::class);
  1060.         $repo->setEm($this->em);
  1061.         $cbj $this->em->getRepository(MedComCorrespondence::class)->find($request->get("objID"));
  1062.         $obj $repo->reply($this->user$request->get("message"), $request->get("priority"), $cbj,2);
  1063.         return new Response(json_encode('success'), Response::HTTP_OK,['content-type' => "text/json"]);
  1064.         //return $this->redirectToRoute(($request->get("submit") == "2" ? "medcom_outbox" : "medcom_index"));
  1065.     }
  1066.     public function delete(Request $request) {
  1067.         $this->auth($request);
  1068.         $repo $this->em->getRepository(MedComCorrespondence::class);
  1069.         $repo->setEm($this->em);
  1070.         $cbj $this->em->getRepository(MedComCorrespondence::class)->find($request->get("objID"));
  1071.         $repo->delete($cbj);
  1072.         return new Response(json_encode('success'), Response::HTTP_OK,['content-type' => "text/json"]);
  1073.     }
  1074.     public function deleteMessage(Request $request) {
  1075.         $this->auth($request);
  1076.         $repo $this->em->getRepository(MedComCorrespondence::class);
  1077.         $repo->setEm($this->em);
  1078.         $cbj $this->em->getRepository(MedComMessages::class)->find($request->get("objID"));
  1079.         $repo->delete($cbj);
  1080.         return new Response(json_encode('success'), Response::HTTP_OK,['content-type' => "text/json"]);
  1081.     }
  1082.     public function medcom_receivers(Request $request) {
  1083.         $this->em $this->getDoctrine()->getManager();
  1084.         $repo $this->em->getRepository(MedComCorrespondence::class);
  1085.         $repo->setEm($this->em);
  1086.         $s $request->get("search");
  1087.         $_data $repo->getMedcomListSearch($s);
  1088.         $data = [];
  1089.         foreach($_data as $_obj) {
  1090.             $obj $_obj[0];
  1091.             $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()];
  1092.         }
  1093.         return new Response(json_encode($data), Response::HTTP_OK,['content-type' => "text/json"]);
  1094.     }
  1095.     public function resendMessage(Request $request) {
  1096.         $this->auth($request);
  1097.         $repo $this->em->getRepository(MedComCorrespondence::class);
  1098.         $repo->setEm($this->em);
  1099.         $cbj $this->em->getRepository(MedComMessages::class)->find($request->get("objID"));
  1100.         //resend
  1101.         //new ids
  1102.         return $this->redirectToRoute("medcom_index");
  1103.         $referer $request->headers->get('referer');
  1104.         $baseUrl $request->getBaseUrl();
  1105.         $lastPath substr($refererstrpos($referer$baseUrl) + strlen($baseUrl));
  1106.         return $this->get('router')->getMatcher()->match($lastPath);
  1107.     }
  1108.     private function getXmlAddDatetimeChild($parent,$name) {
  1109.         $child $parent->addChild($name);
  1110.         $child->addChild('Date'date("Y-m-d"));//datetime now
  1111.         $child->addChild('Time'date("H:i"));//datetime now
  1112.     }
  1113.     private function getXmlStart($xmlns$euuid) {
  1114.         $emssage = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><Emessage />');
  1115.         $emssage->addAttribute("xmlns"$xmlns);
  1116.         $env $emssage->addChild('Envelope');
  1117.         $this->getXmlAddDatetimeChild($env,"Sent");
  1118.         $env->addChild('Identifier'$euuid);
  1119.         $env->addChild('AcknowledgementCode'"minuspositivkvitt");
  1120.         return $emssage;
  1121.     }
  1122.     /*
  1123.     $receiver->addChild("EANIdentifier",($medcom["EanLocationCode"] != null || $medcom["EanLocationCode"] != "" ? $medcom["EanLocationCode"] : $this->ean[$medcom["ParentSorId"]]));
  1124.     $receiver->addChild("Identifier",$medcom["SorId"]);
  1125.     $receiver->addChild("IdentifierCode","sygehusafdelingsnummer");
  1126.     $receiver->addChild("OrganisationName",$medcom['EntityName']);
  1127.     $receiver->addChild("DepartmentName",$medcom['EntityTypeName']);
  1128.     $receiver->addChild("StreetName",$medcom['PostalAddress']);
  1129.     $receiver->addChild("DistrictName",$medcom['PostalDistrictName']);
  1130.     $receiver->addChild("PostCodeIdentifier",$medcom['PostalPostCodeId']);
  1131.     */
  1132.     private function getXmlDis91($obj$cor$medcom,$files null$last9 null) {
  1133.         $emssage $this->getXmlStart("http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2006/07/01/"$obj->getEUUID());
  1134.             $cEmail $emssage->addChild('ClinicalEmail');
  1135.                 $letter $cEmail->addChild("Letter");
  1136.                     $letter->addChild('Identifier'$obj->getUUID());
  1137.                     $letter->addChild('VersionCode'"XD9134L");
  1138.                     $letter->addChild('StatisticalCode'"XDIS91");
  1139.                     $auth $letter->addChild('Authorisation');
  1140.                         $auth->addChild('Date'date("Y-m-d")."");//datetime now
  1141.                         $auth->addChild('Time'date("H:i")."");//datetime now
  1142.                     $letter->addChild('TypeCode'"XDIS91");
  1143.                     $letter->addChild('StatusCode'"nytbrev");
  1144.                     $letter->addChild('EpisodeOfCareIdentifier'$cor->getUUID());
  1145.                 $sender $cEmail->addChild("Sender");
  1146.                     $sender->addChild("EANIdentifier",$this->EANS);
  1147.                     $sender->addChild("Identifier"$this->medcomID);
  1148.                     $sender->addChild("IdentifierCode",$this->medcomIDCode);
  1149.                     $sender->addChild("OrganisationName",$this->orgName);
  1150.                     $sender->addChild("DepartmentName",$this->departmentName);
  1151.                     $sender->addChild("UnitName",$this->unitName);
  1152.                     $sender->addChild("DistrictName",$this->districtName);
  1153.                     $sender->addChild("PostCodeIdentifier",$this->postalCode);
  1154.                     $sender->addChild("MedicalSpecialityCode","ikkeklassificeret");
  1155.                 $receiver $cEmail->addChild("Receiver");
  1156.                     $receiver->addChild("EANIdentifier",$medcom->getEAN());
  1157.                     $receiver->addChild("Identifier",$medcom->getSorId());
  1158.                     $receiver->addChild("IdentifierCode","sygehusafdelingsnummer");
  1159.                     $receiver->addChild("OrganisationName",$medcom->getEntityName());
  1160.                     $receiver->addChild("DepartmentName",$medcom->getEntityTypeName());
  1161.                     $receiver->addChild("StreetName",$medcom->getPostalAddress());
  1162.                     $receiver->addChild("DistrictName",$medcom->getPostalDistrictName());
  1163.                     $receiver->addChild("PostCodeIdentifier",$medcom->getPostalPostCodeId());
  1164.                 $patient $cEmail->addChild("Patient");
  1165.                     $patient->addChild("CivilRegistrationNumber"$this->patientObj->getCpr());
  1166.                     $patient->addChild("PersonSurnameName"$this->patientObj->getLastName());
  1167.                     $patient->addChild("PersonGivenName"$this->patientObj->getFirstName());
  1168.                     $patient->addChild("StreetName"$this->patientObj->getAddressLine1());
  1169.                     $patient->addChild("DistrictName"$this->patientObj->getCity());
  1170.                     $patient->addChild("PostCodeIdentifier"$this->patientObj->getPostNumber());
  1171.                     $patient->addChild("EpisodeOfCareStatusCode""inaktiv");
  1172.                 $addInfo $cEmail->addChild("AdditionalInformation");
  1173.                     $addInfo->addChild("Priority", ($obj->isHighPrio() ? "høj_prioritet" "rutine"));//rutine
  1174.                     $addInfo->addChild("Subject"$cor->getSubject());
  1175.                 $cInfo1 $cEmail->addChild("ClinicalInformation");
  1176.                     $length strlen($obj->getMessageBreakXML());
  1177.                     $cInfo1->addChild("Text01",$obj->getMessageBreakXML());
  1178.                     if($last9 != null && false) {
  1179.                         foreach($last9 as $_txt) {
  1180.                             $length += strlen(utf8_decode($_txt["message"]));
  1181.                             if($length <= 25000)
  1182.                                 $cEmail->addChild("ClinicalInformation")->addChild("Text01",utf8_decode($_txt["message"]));
  1183.                         }
  1184.                     }
  1185.                     //GET ALL FILES RELATED TO THIS
  1186.                     if($files != null && count($files) != 0) {
  1187.                         foreach($files as $file) {
  1188.                             $ref $cEmail->addChild("Reference");
  1189.                                 $ref->addChild("RefDescription","BIN");
  1190.                                 $bin $ref->addChild("BIN");
  1191.                                     $bin->addChild('ObjectIdentifier'str_replace('-','',$file->getGUID()));
  1192.                                     $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" "");
  1193.                                     $object_type_code = ($file->getFileType() == "pdf" "vektor_grafik"  $object_type_code);
  1194.                                     $object_type_code = ($file->getFileType() == "zip" "proprietaert_indhold"  $object_type_code);
  1195.                                     $object_type_code = ($file->getFileType() == "txt" || $file->getFileType() == "rtf" || $file->getFileType() == "doc" || $file->getFileType() == "xls" || $file->getFileType() == "wpd" "tekstfil" $object_type_code);
  1196.                                     $bin->addChild('ObjectCode'$object_type_code);
  1197.                                     $bin->addChild('ObjectExtensionCode', ($file->getFileType() == "jpg" "jpeg" $file->getFileType()));
  1198.                                     $bin->addChild('OriginalObjectSize'$file->getFileSize());
  1199.                         }
  1200.                     } else {
  1201.                         $ref $cEmail->addChild("Reference");
  1202.                             $ref->addChild("RefDescription","Der Findes yderliger oplysninger i SUP");
  1203.                             $ref->addChild("SUP""true");
  1204.                     }
  1205.         return $emssage;
  1206.     }
  1207.     private function getXmlctl02($obj,$cor,$medcom,$ean,$orgVersionCode,$refuseCode,$refuseText) {
  1208.         $emssage = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><Emessage />');
  1209.         $emssage->addAttribute("xmlns""http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2005/08/07/");
  1210.             $env $emssage->addChild('Envelope');
  1211.                 $envSent $env->addChild('Sent');
  1212.                     $envSent->addChild('Date'date("Y-m-d"));//datetime now
  1213.                     $envSent->addChild('Time'date("H:i"));//datetime now
  1214.                 $env->addChild('Identifier'uniqid());
  1215.                 $env->addChild('AcknowledgementCode'"minuspositivkvitt");
  1216.             $msg $emssage->addChild('NegativeReceipt');
  1217.                 $letter $msg->addChild("Letter");
  1218.                     $letter->addChild('Identifier',  uniqid());
  1219.                     $letter->addChild('VersionCode'"XC0230Q");
  1220.                     $letter->addChild('StatisticalCode'"XCTL02");
  1221.                 $sender $msg->addChild("Sender");
  1222.                     $sender->addChild("EANIdentifier",$this->EANS);
  1223.                 $receiver $msg->addChild("Receiver");
  1224.                     $receiver->addChild("EANIdentifier",$ean);
  1225.                 $orgmsg $msg->addChild("OriginalEmessage");
  1226.                 $orgmsg->addChild("OriginalEnvelopeIdentifier"$obj->getEUUID());
  1227.                 $orgSender $orgmsg->addChild("OriginalSender");
  1228.                     $orgSender->addChild("EANIdentifier",$ean);
  1229.                 $orgReceiver $orgmsg->addChild("OriginalReceiver");
  1230.                     $orgReceiver->addChild("EANIdentifier",$this->EANS);
  1231.                 $orgletter $orgmsg->addChild("OriginalLetter");
  1232.                     $orgletter->addChild("OriginalLetterIdentifier",$obj->getUUID());
  1233.                     $orgletter->addChild("OriginalVersionCode",$orgVersionCode);
  1234.                     if($refuseText !== null && $refuseCode !== "")
  1235.                         $orgletter->addChild("RefuseCode",$refuseCode);
  1236.                     if($refuseText !== null && $refuseText !== "")
  1237.                         $orgletter->addChild("RefuseText",$refuseText);
  1238.         return $emssage;
  1239.     }
  1240.     private function getXmlctl03($obj,$cor,$medcom,$ean) {
  1241.         $emssage = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><Emessage />');
  1242.             $emssage->addAttribute("xmlns""http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2005/08/07/");
  1243.             $env $emssage->addChild('Envelope');
  1244.                 $envSent $env->addChild('Sent');
  1245.                     $envSent->addChild('Date'date("Y-m-d"));//datetime now
  1246.                     $envSent->addChild('Time'date("H:i"));//datetime now
  1247.                 $env->addChild('Identifier'uniqid());
  1248.                 $env->addChild('AcknowledgementCode'"minuspositivkvitt");
  1249.             $msg $emssage->addChild('PositiveReceipt');
  1250.                 $letter $msg->addChild("Letter");
  1251.                     $letter->addChild('Identifier'uniqid());
  1252.                     $letter->addChild('VersionCode'"XC0330Q");
  1253.                     $letter->addChild('StatisticalCode'"XCTL03");
  1254.                 $sender $msg->addChild("Sender");
  1255.                     $sender->addChild("EANIdentifier",$this->EANS);
  1256.                 $receiver $msg->addChild("Receiver");
  1257.                     $receiver->addChild("EANIdentifier"$ean);
  1258.                 $orgmsg $msg->addChild("OriginalEmessage");
  1259.                 $orgmsg->addChild("OriginalEnvelopeIdentifier"$obj->getEUUID());
  1260.                 $orgSender $orgmsg->addChild("OriginalSender");
  1261.                     $orgSender->addChild("EANIdentifier",$ean);
  1262.                 $orgReceiver $orgmsg->addChild("OriginalReceiver");
  1263.                     $orgReceiver->addChild("EANIdentifier",$this->EANS);
  1264.                 $orgletter $orgmsg->addChild("OriginalLetter");
  1265.                     $orgletter->addChild("OriginalLetterIdentifier",$obj->getUUID());
  1266.                     if(strtolower($obj->getType()) == "bilag"){
  1267.                         $orgletter->addChild("OriginalVersionCode","XB0131X");
  1268.                     } else {
  1269.                         $orgletter->addChild("OriginalVersionCode","XD9134L");
  1270.                     }
  1271.         return $emssage;
  1272.                         
  1273.     }
  1274.     private function getXmlbin01($obj,$medcom) {
  1275.         $emssage = new \SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1"?><Emessage />');
  1276.         $emssage->addAttribute("xmlns""http://rep.oio.dk/medcom.dk/xml/schemas/2012/03/28/");
  1277.             $env $emssage->addChild('Envelope');
  1278.                 $envSent $env->addChild('Sent');
  1279.                     $envSent->addChild('Date'date("Y-m-d"));//datetime now
  1280.                     $envSent->addChild('Time'date("H:i"));//datetime now
  1281.                 $env->addChild('Identifier'$obj->getEUUID());
  1282.                 $env->addChild('AcknowledgementCode'"minuspositivkvitt");
  1283.             $cEmail $emssage->addChild('BinaryLetter');
  1284.                 $letter $cEmail->addChild("Letter");
  1285.                     $letter->addChild('Identifier'$obj->getUUID());
  1286.                     $letter->addChild('VersionCode'"XB0131X");
  1287.                     $letter->addChild('StatisticalCode'"XBIN01");
  1288.                     $auth $letter->addChild('Authorisation');
  1289.                         $auth->addChild('Date'date("Y-m-d")."");//datetime now
  1290.                         $auth->addChild('Time'date("H:i")."");//datetime now
  1291.                     $letter->addChild('TypeCode'"XBIN01");
  1292.                     $letter->addChild('StatusCode'"nytbrev");
  1293.                 $sender $cEmail->addChild("Sender");
  1294.                     $sender->addChild("EANIdentifier",$this->EANS);
  1295.                     $sender->addChild("Identifier"$this->medcomID);
  1296.                     $sender->addChild("IdentifierCode",$this->medcomIDCode);
  1297.                     $sender->addChild("OrganisationName",$this->orgName);
  1298.                     $sender->addChild("DepartmentName",$this->departmentName);
  1299.                     $sender->addChild("UnitName",$this->unitName);
  1300.                     $sender->addChild("DistrictName",$this->districtName);
  1301.                     $sender->addChild("PostCodeIdentifier",$this->postalCode);
  1302.                     $sender->addChild("MedicalSpecialityCode","ikkeklassificeret");
  1303.                 $receiver $cEmail->addChild("Receiver");
  1304.                     $receiver->addChild("EANIdentifier",$medcom->getEAN());
  1305.                     $receiver->addChild("Identifier",$medcom->getSorId());
  1306.                     $receiver->addChild("IdentifierCode","sygehusafdelingsnummer");
  1307.                     $receiver->addChild("OrganisationName",$medcom->getEntityName());
  1308.                     $receiver->addChild("DepartmentName",$medcom->getEntityTypeName());
  1309.                     $receiver->addChild("StreetName",$medcom->getPostalAddress());
  1310.                     $receiver->addChild("DistrictName",$medcom->getPostalDistrictName());
  1311.                     $receiver->addChild("PostCodeIdentifier",$medcom->getPostalPostCodeId());
  1312.                 $patient $cEmail->addChild("Patient");
  1313.                     $patient->addChild("CivilRegistrationNumber"$this->patientObj->getCpr());
  1314.                     $patient->addChild("PersonSurnameName"$this->patientObj->getLastName());
  1315.                     $patient->addChild("PersonGivenName"$this->patientObj->getFirstName());
  1316.                 $msg $cEmail->addChild('BinaryObject');
  1317.                     $msg->addChild('ObjectIdentifier'$obj->getGUID());
  1318.                     $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" "");
  1319.                     $object_type_code = ($obj->getFileType() == "pdf" "vektor_grafik"  $object_type_code);
  1320.                     $object_type_code = ($obj->getFileType() == "zip" "proprietaert_indhold"  $object_type_code);
  1321.                     $object_type_code = ($obj->getFileType() == "txt" || $obj->getFileType() == "rtf" || $obj->getFileType() == "doc" || $obj->getFileType() == "xls" || $obj->getFileType() == "wpd" "tekstfil" $object_type_code);
  1322.                     $msg->addChild('ObjectCode'$object_type_code);
  1323.                     $msg->addChild('ObjectExtensionCode', ($obj->getFileType() == "jpg" "jpeg" $obj->getFileType()));
  1324.                     $msg->addChild('OriginalObjectSize'$obj->getFileSize());
  1325.                     $msg->addChild('Object_Base64Encoded'$obj->getFileData());
  1326.         return $emssage;
  1327.     }
  1328. }