HospitalSeeder.ts 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import { PrismaClient } from '@prisma/client';
  2. import { ProgressStatus } from '@prisma/client';
  3. const prisma = new PrismaClient();
  4. export async function seedHospitals(): Promise<void> {
  5. try {
  6. const sales1 = await prisma.userKeycloak.findFirst({ where: { id: '1b50e497-159f-49c2-aa4d-466e72d796f0' } });
  7. const sales2 = await prisma.userKeycloak.findFirst({ where: { id: '0ec065d8-547c-46e3-9980-df36b9648767' } });
  8. if (!sales1 || !sales2) {
  9. throw new Error('User sales1 or sales2 not found');
  10. }
  11. const sales1Area = await prisma.userArea.findFirst({ where: { user_id: sales1.id } });
  12. const sales2Area = await prisma.userArea.findFirst({ where: { user_id: sales2.id } });
  13. if (!sales1Area || !sales2Area) {
  14. throw new Error('UserArea for sales1 or sales2 not found');
  15. }
  16. const city1 = await prisma.city.findFirst({ where: { province_id: sales1Area.province_id } });
  17. const city2 = await prisma.city.findFirst({ where: { province_id: sales2Area.province_id } });
  18. if (!city1 || !city2) {
  19. throw new Error('City not found for one of province id');
  20. }
  21. const hospitals = [
  22. {
  23. name: 'RS Sehat Selalu',
  24. hospital_code: 'RSS001',
  25. type: 'Tipe B',
  26. ownership: 'Swasta',
  27. address: 'Jl. Kesehatan No. 1',
  28. contact: '021-123456',
  29. image: null,
  30. progress_status: ProgressStatus.cari_data,
  31. note: 'Calon potensial',
  32. province_id: sales1Area.province_id,
  33. city_id: city1.id,
  34. created_by: sales1.id,
  35. },
  36. {
  37. name: 'RS Harapan Bangsa',
  38. hospital_code: 'RSB002',
  39. type: 'Tipe C',
  40. ownership: 'Pemerintah',
  41. address: 'Jl. Harapan No. 2',
  42. contact: '021-654321',
  43. image: null,
  44. progress_status: ProgressStatus.cari_data,
  45. note: null,
  46. province_id: sales1Area.province_id,
  47. city_id: city1.id,
  48. created_by: sales1.id,
  49. },
  50. {
  51. name: 'RS Mitra Medika',
  52. hospital_code: 'RSM003',
  53. type: 'Tipe D',
  54. ownership: 'Swasta',
  55. address: 'Jl. Mitra No. 3',
  56. contact: '021-999999',
  57. image: null,
  58. progress_status: ProgressStatus.cari_data,
  59. note: 'Baru dihubungi',
  60. province_id: sales1Area.province_id,
  61. city_id: city1.id,
  62. created_by: sales1.id,
  63. },
  64. {
  65. name: 'RS Sembuh Bersama',
  66. hospital_code: 'RSB004',
  67. type: 'Tipe B',
  68. ownership: 'Swasta',
  69. address: 'Jl. Bersama No. 4',
  70. contact: '0274-111111',
  71. image: null,
  72. progress_status: ProgressStatus.cari_data,
  73. note: null,
  74. province_id: sales2Area.province_id,
  75. city_id: city2.id,
  76. created_by: sales2.id,
  77. },
  78. {
  79. name: 'RS Kasih Ibu',
  80. hospital_code: 'RSK005',
  81. type: 'Tipe C',
  82. ownership: 'Yayasan',
  83. address: 'Jl. Kasih No. 5',
  84. contact: '0274-222222',
  85. image: null,
  86. progress_status: ProgressStatus.cari_data,
  87. note: 'Perlu follow up',
  88. province_id: sales2Area.province_id,
  89. city_id: city2.id,
  90. created_by: sales2.id,
  91. },
  92. {
  93. name: 'RS Bhakti Sehat',
  94. hospital_code: 'RSB006',
  95. type: 'Tipe D',
  96. ownership: 'Swasta',
  97. address: 'Jl. Bhakti No. 6',
  98. contact: '0274-333333',
  99. image: null,
  100. progress_status: ProgressStatus.cari_data,
  101. note: null,
  102. province_id: sales2Area.province_id,
  103. city_id: city2.id,
  104. created_by: sales2.id,
  105. },
  106. ];
  107. for (const hospital of hospitals) {
  108. await prisma.hospital.create({ data: hospital });
  109. }
  110. console.log('✅ Hospital seeded!');
  111. } catch (err: any) {
  112. console.error('❌ Error seeding hospital:', err.message);
  113. }
  114. }
  115. seedHospitals();
  116. // const { PrismaClient } = require('@prisma/client');
  117. // const prisma = new PrismaClient();
  118. // async function seedHospitals() {
  119. // try {
  120. // const sales1 = await prisma.user.findFirst({ where: { username: 'sales1' } });
  121. // const sales2 = await prisma.user.findFirst({ where: { username: 'sales2' } });
  122. // if (!sales1 || !sales2) {
  123. // throw new Error('User sales1 or sales2 not found');
  124. // }
  125. // // Ambil province_id dari user_areas
  126. // const sales1Area = await prisma.userArea.findFirst({ where: { user_id: sales1.id } });
  127. // const sales2Area = await prisma.userArea.findFirst({ where: { user_id: sales2.id } });
  128. // if (!sales1Area || !sales2Area) {
  129. // throw new Error('UserArea for sales1 or sales2 not found');
  130. // }
  131. // // Ambil city yang berada di province_id tersebut
  132. // const city1 = await prisma.city.findFirst({ where: { province_id: sales1Area.province_id } });
  133. // const city2 = await prisma.city.findFirst({ where: { province_id: sales2Area.province_id } });
  134. // if (!city1 || !city2) {
  135. // throw new Error('City not found for one of province id');
  136. // }
  137. // // Data rumah sakit
  138. // const hospitals = [
  139. // {
  140. // name: 'RS Sehat Selalu',
  141. // hospital_code: 'RSS001',
  142. // type: 'Tipe B',
  143. // ownership: 'Swasta',
  144. // address: 'Jl. Kesehatan No. 1',
  145. // // simrs_type: 'MediSoft',
  146. // contact: '021-123456',
  147. // image: null,
  148. // progress_status: 'cari_data',
  149. // note: 'Calon potensial',
  150. // province_id: sales1Area.province_id,
  151. // city_id: city1.id,
  152. // created_by: sales1.id,
  153. // },
  154. // {
  155. // name: 'RS Harapan Bangsa',
  156. // hospital_code: 'RSB002',
  157. // type: 'Tipe C',
  158. // ownership: 'Pemerintah',
  159. // address: 'Jl. Harapan No. 2',
  160. // // simrs_type: 'Hospicare',
  161. // contact: '021-654321',
  162. // image: null,
  163. // progress_status: 'cari_data',
  164. // note: null,
  165. // province_id: sales1Area.province_id,
  166. // city_id: city1.id,
  167. // created_by: sales1.id,
  168. // },
  169. // {
  170. // name: 'RS Mitra Medika',
  171. // hospital_code: 'RSM003',
  172. // type: 'Tipe D',
  173. // ownership: 'Swasta',
  174. // address: 'Jl. Mitra No. 3',
  175. // // simrs_type: 'SimRS Platinum',
  176. // contact: '021-999999',
  177. // image: null,
  178. // progress_status: 'cari_data',
  179. // note: 'Baru dihubungi',
  180. // province_id: sales1Area.province_id,
  181. // city_id: city1.id,
  182. // created_by: sales1.id,
  183. // },
  184. // {
  185. // name: 'RS Sembuh Bersama',
  186. // hospital_code: 'RSB004',
  187. // type: 'Tipe B',
  188. // ownership: 'Swasta',
  189. // address: 'Jl. Bersama No. 4',
  190. // // simrs_type: 'MediSoft',
  191. // contact: '0274-111111',
  192. // image: null,
  193. // progress_status: 'cari_data',
  194. // note: null,
  195. // province_id: sales2Area.province_id,
  196. // city_id: city2.id,
  197. // created_by: sales2.id,
  198. // },
  199. // {
  200. // name: 'RS Kasih Ibu',
  201. // hospital_code: 'RSK005',
  202. // type: 'Tipe C',
  203. // ownership: 'Yayasan',
  204. // address: 'Jl. Kasih No. 5',
  205. // // simrs_type: 'Hospicare',
  206. // contact: '0274-222222',
  207. // image: null,
  208. // progress_status: 'cari_data',
  209. // note: 'Perlu follow up',
  210. // province_id: sales2Area.province_id,
  211. // city_id: city2.id,
  212. // created_by: sales2.id,
  213. // },
  214. // {
  215. // name: 'RS Bhakti Sehat',
  216. // hospital_code: 'RSB006',
  217. // type: 'Tipe D',
  218. // ownership: 'Swasta',
  219. // address: 'Jl. Bhakti No. 6',
  220. // // simrs_type: 'SimRS Platinum',
  221. // contact: '0274-333333',
  222. // image: null,
  223. // progress_status: 'cari_data',
  224. // note: null,
  225. // province_id: sales2Area.province_id,
  226. // city_id: city2.id,
  227. // created_by: sales2.id,
  228. // },
  229. // ];
  230. // // Masukkan ke DB
  231. // for (const hospital of hospitals) {
  232. // await prisma.hospital.create({ data: hospital });
  233. // }
  234. // console.log('✅ Hospital seeded!');
  235. // } catch (err) {
  236. // console.error('❌ Error seeding hospital:', err.message);
  237. // }
  238. // }
  239. // module.exports = { seedHospitals };