Advertisement
Guest User

Untitled

a guest
Sep 16th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.37 KB | None | 0 0
  1. import { Component, OnInit, OnDestroy } from '@angular/core';
  2. import { ROUTER_DIRECTIVES, ActivatedRoute } from '@angular/router';
  3. import {Questionnaire} from '../data/questionnaire/questionnaire';
  4. import { Client} from '../data/client/client';
  5. import {ClientStore} from '../data/client/client-store';
  6. import {ClientBackend} from '../data/client/client-backend';
  7. import {CareUnit} from '../data/care-unit/care-unit';
  8. import {CareUnitStore} from '../data/care-unit/care-unit-store';
  9. import {CareUnitBackend} from '../data/care-unit/care-unit-backend';
  10. import {Department} from '../data/department/department';
  11. import {DepartmentStore} from '../data/department/department-store';
  12. import {DepartmentBackend} from '../data/department/department-backend';
  13. import {District} from '../data/district/district';
  14. import {DistrictStore} from '../data/district/district-store';
  15. import {DistrictBackend} from '../data/district/district-backend';
  16. import {Municipality} from '../data/municipality/municipality';
  17. import {MunicipalityStore} from '../data/municipality/municipality-store';
  18. import {MunicipalityBackend} from '../data/municipality/municipality-backend';
  19. import {Region} from '../data/region/region';
  20. import {RegionStore} from '../data/region/region-store';
  21. import {RegionBackend} from '../data/region/region-backend';
  22. import { Observable } from 'rxjs/Observable';
  23. import { FilterClientsService } from '../cd-client/filtered-clients-service';
  24. import { Subscription } from 'rxjs/Subscription';
  25. import {IceContact} from '../data/ice-contact/ice-contact';
  26. import {IceContactStore} from '../data/ice-contact/ice-contact-store';
  27. import {IceContactBackend} from '../data/ice-contact/ice-contact-backend';
  28. import {Activity} from '../data/activity/activity';
  29. import {ActivityStore} from '../data/activity/activity-store';
  30. import {ActivityBackend} from '../data/activity/activity-backend';
  31. import {PlannedActivity} from '../data/planned-activity/planned-activity';
  32. import {PlannedActivityStore} from '../data/planned-activity/planned-activity-store';
  33. import {PlannedActivityBackend} from '../data/planned-activity/planned-activity-backend';
  34. import { TranslateLoader, TranslateService, TranslateStaticLoader, TranslatePipe } from "ng2-translate/ng2-translate";
  35. import {Day} from '../data/day/day';
  36.  
  37. @Component({
  38. moduleId: module.id,
  39. selector: 'app-client-details',
  40. templateUrl: 'client-details.component.html',
  41. styleUrls: ['client-details.component.css'],
  42. pipes: [TranslatePipe],
  43. directives: [ROUTER_DIRECTIVES],
  44. providers: []
  45. })
  46. export class ClientDetailsComponent implements OnInit {
  47.  
  48. subscription: Subscription;
  49. selectedTab: string = 'personal';
  50. dateB: Date = new Date;
  51. newClientRegion: string = '-1';
  52. newMedicalContact: string = "";
  53. newClientMunicipality: string = '-1';
  54. newClientCareUnit: string = '-1';
  55. newClientDepartment: string = '-1';
  56. client: Client;
  57. sub: any;
  58. prevDisabled: boolean = false;
  59. nextDisabled: boolean = false;
  60. clients: Array<Client>;
  61. currentClientPosition: number;
  62. careUnits: Observable<Array<CareUnit>>;
  63. regions: Observable<Array<Region>>;
  64. districts: Observable<Array<District>>;
  65. departments: Observable<Array<Department>>;
  66. municipalities: Observable<Array<Municipality>>;
  67. activities: Observable<Array<Activity>>;
  68. iceContactFirstName: string = "";
  69. iceContactLastName: string = "";
  70. iceContactAddressStreet: string = "";
  71. iceContactAddressCity: string = "";
  72. iceContactPhoneNumber: string = "";
  73. iceContactComment: string = "";
  74. newActivity: string = "-1";
  75. timesPerDay: number = 0;
  76. activity: PlannedActivity = {
  77. id: "",
  78. dayId: "",
  79. clientId: "string",
  80. repeated: 1,
  81. }
  82. dayIds: Array<string>;
  83. iceContact: IceContact = {
  84. id: "1",
  85. clientId: "1",
  86. lastName: "lastName",
  87. firstName: "firstName",
  88. addressStreet: "address",
  89. addressCity: "address",
  90. phoneNumber: "number",
  91. commentFreeText: "comment",
  92. }
  93. days: Array<Day> =
  94. [{
  95. id: '1',
  96. name: 'Monday',
  97. checked: false,
  98. },
  99. {
  100. checked: false,
  101. name: 'Tuesday',
  102. id: '2',
  103. },
  104. {
  105. checked: false,
  106. name: 'Wednesday',
  107. id: '3',
  108. },
  109. {
  110. checked: false,
  111. name: 'Thursday',
  112. id: '4',
  113. },
  114. {
  115. checked: false,
  116. name: 'Friday',
  117. id: '5',
  118. },
  119. {
  120. checked: false,
  121. name: 'Saturday',
  122. id: '6',
  123. },
  124. {
  125. checked: false,
  126. name: 'Sunday',
  127. id: '0',
  128. }]
  129. newC: Client = {
  130. id: "1",
  131. type: "Home Care",
  132. firstName: "VIktorija",
  133. lastName: "Denchovska",
  134. dateBirth: this.dateB,
  135. gender: "female",
  136. phoneNumber: "123456",
  137. addressStreet: "Pirinska",
  138. addressPostalCode: "1234",
  139. addressCity: "SKOPJE",
  140. status: "Active",
  141. socialSecurityNumber: "1234556",
  142. age: "76",
  143. departmentId: "1",
  144. departmentName: "DEPARTMENT1",
  145. careUnitId: "1",
  146. careUnitName: "Malmo"
  147. };
  148.  
  149. questionnaire: Questionnaire = {
  150. id: '1',
  151. name: 'Medical care',
  152. questions: [
  153. {
  154. id: "1",
  155. questionContent: 'Qwerty?',
  156. answered: 0,
  157. answers: [
  158. {
  159. id: '1',
  160. answerContent: 'Answer 1',
  161. points: 1,
  162. questionId: '1',
  163. checked: false,
  164. },
  165. {
  166. id: '2',
  167. answerContent: 'Answer 2',
  168. points: 1,
  169. questionId: '1',
  170. checked: false,
  171. },
  172. {
  173. id: '3',
  174. answerContent: 'Answer 3',
  175. points: 1,
  176. questionId: '1',
  177. checked: false,
  178. },
  179. {
  180. id: '4',
  181. answerContent: 'Answer 4',
  182. points: 1,
  183. questionId: '1',
  184. checked: false,
  185. },
  186. {
  187. id: '5',
  188. answerContent: 'Answer 5',
  189. points: 1,
  190. questionId: '1',
  191. checked: false,
  192. }
  193. ],
  194. questionGroupName: 'Personal Info',
  195. questionnaireId: '1',
  196. },
  197. {
  198. id: "2",
  199. questionContent: 'Personal info?',
  200. answered: 0,
  201. answers: [
  202. {
  203. id: '1',
  204. answerContent: 'Answer 1',
  205. points: 1,
  206. questionId: '2',
  207. checked: false,
  208. },
  209. {
  210. id: '2',
  211. answerContent: 'Answer 2',
  212. points: 1,
  213. questionId: '2',
  214. checked: false,
  215. },
  216. {
  217. id: '3',
  218. answerContent: 'Answer 3',
  219. points: 1,
  220. questionId: '2',
  221. checked: false,
  222. },
  223. {
  224. id: '4',
  225. answerContent: 'Answer 4',
  226. points: 1,
  227. questionId: '2',
  228. checked: false,
  229. },
  230. {
  231. id: '5',
  232. answerContent: 'Answer 5',
  233. points: 1,
  234. questionId: '2',
  235. checked: false,
  236. }
  237. ],
  238. questionGroupName: 'Personal Info',
  239. questionnaireId: '1',
  240. },
  241. {
  242. id: "3",
  243. questionContent: 'Medical Care?',
  244. answered: 0,
  245. answers: [
  246. {
  247. id: '1',
  248. answerContent: 'Answer 1',
  249. points: 1,
  250. questionId: '3',
  251. checked: false,
  252. },
  253. {
  254. id: '2',
  255. answerContent: 'Answer 2',
  256. points: 1,
  257. questionId: '3',
  258. checked: false,
  259. },
  260. {
  261. id: '3',
  262. answerContent: 'Answer 3',
  263. points: 1,
  264. questionId: '3',
  265. checked: false,
  266. },
  267. {
  268. id: '4',
  269. answerContent: 'Answer 4',
  270. points: 1,
  271. questionId: '3',
  272. checked: false,
  273. },
  274. {
  275. id: '5',
  276. answerContent: 'Answer 5',
  277. points: 1,
  278. questionId: '3',
  279. checked: false,
  280. }
  281. ],
  282. questionGroupName: 'Personal Info',
  283. questionnaireId: '1',
  284. }
  285. ]
  286. }
  287. constructor(private clientStore: ClientStore, private careUnitStore: CareUnitStore, private regionStore: RegionStore, private districtStore: DistrictStore, private departmentStore: DepartmentStore, private municipalityStore: MunicipalityStore, private route: ActivatedRoute, private filteredClientsService: FilterClientsService, private translate: TranslateService, private iceContactStore: IceContactStore, private activityStore: ActivityStore, private plannedActivityStore: PlannedActivityStore) {
  288.  
  289. }
  290.  
  291. ngOnInit() {
  292. this.clients = this.filteredClientsService.getFilteredClients();
  293. this.clientStore.clients
  294. .map((clients: Array<Client>) => {
  295. return clients;
  296. })
  297. .subscribe((clients: Array<Client>) => {
  298. this.clients = clients;
  299. })
  300.  
  301. this.sub = this.route.params.subscribe(params => {
  302. this.client = this.clients.find(function (client) {
  303. return client.id == params["id"]
  304. });
  305. this.currentClientPosition = this.clients.indexOf(this.client);
  306. });
  307.  
  308. this.careUnits = this.careUnitStore.careUnits
  309. .map((careUnits: Array<CareUnit>) => {
  310. return careUnits;
  311. })
  312.  
  313. this.regions = this.regionStore.regions
  314. .map((regions: Array<Region>) => {
  315. return regions;
  316. })
  317.  
  318. this.districts = this.districtStore.districts
  319. .map((districts: Array<District>) => {
  320. return districts;
  321. })
  322.  
  323. this.departments = this.departmentStore.departments
  324. .map((departments: Array<Department>) => {
  325. return departments;
  326. })
  327.  
  328. this.municipalities = this.municipalityStore.municipalities
  329. .map((municipalities: Array<Municipality>) => {
  330. return municipalities;
  331. })
  332.  
  333. this.activities = this.activityStore.activities
  334. .map((activities: Array<Activity>) => {
  335. return activities;
  336. })
  337.  
  338. this.dayIds = [];
  339.  
  340. if (this.currentClientPosition == this.clients.length - 1) {
  341. this.nextDisabled = true;
  342. }
  343.  
  344. if (this.currentClientPosition == 0) {
  345. this.prevDisabled = true;
  346. }
  347.  
  348. this.translate.use(this.translate.currentLang);
  349. }
  350.  
  351. private ngOnDestroy() {
  352. this.sub.unsubscribe();
  353. }
  354.  
  355. setSelected(tabS: string): void {
  356. this.selectedTab = tabS;
  357. }
  358.  
  359. nextClient() {
  360. this.currentClientPosition++;
  361. if (this.currentClientPosition == this.clients.length - 1) {
  362. this.nextDisabled = true;
  363. this.prevDisabled = false;
  364. this.client = this.clients[this.currentClientPosition];
  365. }
  366. else {
  367. this.prevDisabled = false;
  368. this.nextDisabled = false;
  369. this.client = this.clients[this.currentClientPosition];
  370. }
  371.  
  372. }
  373.  
  374. previousClient() {
  375. this.currentClientPosition--;
  376. if (this.currentClientPosition == 0) {
  377. this.prevDisabled = true;
  378. this.nextDisabled = false;
  379. this.client = this.clients[this.currentClientPosition];
  380. }
  381. else {
  382. this.nextDisabled = false;
  383. this.prevDisabled = false;
  384. this.client = this.clients[this.currentClientPosition];
  385. }
  386. }
  387.  
  388. changeSelected(currentTab: string): void {
  389. if (currentTab == 'personal') {
  390. this.clientStore.updateClient(this.client);
  391. this.selectedTab = 'ice-contacts';
  392. }
  393. if (currentTab == 'ice-contacts') {
  394. this.selectedTab = 'medical-contact';
  395. }
  396. if (currentTab == 'medical-contact') {
  397. this.selectedTab = 'doctors';
  398. }
  399. if (currentTab == 'doctors') {
  400. this.selectedTab = 'needs';
  401. }
  402. if (currentTab == 'needs') {
  403. this.selectedTab = 'doctors';
  404. }
  405. if (currentTab == 'needs') {
  406. this.selectedTab = 'plannedActivities';
  407. }
  408.  
  409. if (currentTab == 'plannedActivities') {
  410. this.activity.id = this.newActivity;
  411. this.activity.clientId = this.client.id;
  412. this.activity.repeated = this.timesPerDay;
  413.  
  414. console.log(this.days);
  415. // this.days.forEach(day => {
  416. // if(day.checked){
  417. // this.dayIds.push(day.id);
  418. // }
  419. // });
  420.  
  421. console.log(this.activity);
  422. console.log(this.dayIds);
  423. }
  424. }
  425. // addClient() {
  426. // if (this.selectedTab == 'ice-contacts') {
  427. // this.newC.type = this.newClientType;
  428. // this.newC.socialSecurityNumber = this.newClientSSN;
  429. // this.newC.firstName = this.newClientFirstName;
  430. // this.newC.lastName = this.newClientLastName;
  431. // this.newC.dateBirth = this.newClientDateBirth;
  432. // this.newC.gender = this.newClientGender;
  433. // this.newC.phoneNumber = this.newClientPhoneNumber;
  434. // this.newC.addressStreet = this.newClientAStreet;
  435. // this.newC.addressPostalCode = this.newClientAPostalCode;
  436. // this.newC.addressCity = this.newClientACity;
  437.  
  438. // this.clientStore.createClient(this.newC);
  439. // }
  440. // }
  441.  
  442. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement