123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- import { PrismaClient } from '@prisma/client';
- import { ProgressStatus } from '@prisma/client';
- const prisma = new PrismaClient();
- export async function seedHospitals(): Promise<void> {
- try {
- const sales1 = await prisma.userKeycloak.findFirst({ where: { id: '1b50e497-159f-49c2-aa4d-466e72d796f0' } });
- const sales2 = await prisma.userKeycloak.findFirst({ where: { id: '0ec065d8-547c-46e3-9980-df36b9648767' } });
- if (!sales1 || !sales2) {
- throw new Error('User sales1 or sales2 not found');
- }
- const sales1Area = await prisma.userArea.findFirst({ where: { user_id: sales1.id } });
- const sales2Area = await prisma.userArea.findFirst({ where: { user_id: sales2.id } });
- if (!sales1Area || !sales2Area) {
- throw new Error('UserArea for sales1 or sales2 not found');
- }
- const city1 = await prisma.city.findFirst({ where: { province_id: sales1Area.province_id } });
- const city2 = await prisma.city.findFirst({ where: { province_id: sales2Area.province_id } });
- if (!city1 || !city2) {
- throw new Error('City not found for one of province id');
- }
- const hospitals = [
- {
- name: 'RS Sehat Selalu',
- hospital_code: 'RSS001',
- type: 'Tipe B',
- ownership: 'Swasta',
- address: 'Jl. Kesehatan No. 1',
- contact: '021-123456',
- image: null,
- progress_status: ProgressStatus.cari_data,
- note: 'Calon potensial',
- province_id: sales1Area.province_id,
- city_id: city1.id,
- created_by: sales1.id,
- },
- {
- name: 'RS Harapan Bangsa',
- hospital_code: 'RSB002',
- type: 'Tipe C',
- ownership: 'Pemerintah',
- address: 'Jl. Harapan No. 2',
- contact: '021-654321',
- image: null,
- progress_status: ProgressStatus.cari_data,
- note: null,
- province_id: sales1Area.province_id,
- city_id: city1.id,
- created_by: sales1.id,
- },
- {
- name: 'RS Mitra Medika',
- hospital_code: 'RSM003',
- type: 'Tipe D',
- ownership: 'Swasta',
- address: 'Jl. Mitra No. 3',
- contact: '021-999999',
- image: null,
- progress_status: ProgressStatus.cari_data,
- note: 'Baru dihubungi',
- province_id: sales1Area.province_id,
- city_id: city1.id,
- created_by: sales1.id,
- },
- {
- name: 'RS Sembuh Bersama',
- hospital_code: 'RSB004',
- type: 'Tipe B',
- ownership: 'Swasta',
- address: 'Jl. Bersama No. 4',
- contact: '0274-111111',
- image: null,
- progress_status: ProgressStatus.cari_data,
- note: null,
- province_id: sales2Area.province_id,
- city_id: city2.id,
- created_by: sales2.id,
- },
- {
- name: 'RS Kasih Ibu',
- hospital_code: 'RSK005',
- type: 'Tipe C',
- ownership: 'Yayasan',
- address: 'Jl. Kasih No. 5',
- contact: '0274-222222',
- image: null,
- progress_status: ProgressStatus.cari_data,
- note: 'Perlu follow up',
- province_id: sales2Area.province_id,
- city_id: city2.id,
- created_by: sales2.id,
- },
- {
- name: 'RS Bhakti Sehat',
- hospital_code: 'RSB006',
- type: 'Tipe D',
- ownership: 'Swasta',
- address: 'Jl. Bhakti No. 6',
- contact: '0274-333333',
- image: null,
- progress_status: ProgressStatus.cari_data,
- note: null,
- province_id: sales2Area.province_id,
- city_id: city2.id,
- created_by: sales2.id,
- },
- ];
- for (const hospital of hospitals) {
- await prisma.hospital.create({ data: hospital });
- }
- console.log('✅ Hospital seeded!');
- } catch (err: any) {
- console.error('❌ Error seeding hospital:', err.message);
- }
- }
- seedHospitals();
- // const { PrismaClient } = require('@prisma/client');
- // const prisma = new PrismaClient();
- // async function seedHospitals() {
- // try {
- // const sales1 = await prisma.user.findFirst({ where: { username: 'sales1' } });
- // const sales2 = await prisma.user.findFirst({ where: { username: 'sales2' } });
- // if (!sales1 || !sales2) {
- // throw new Error('User sales1 or sales2 not found');
- // }
- // // Ambil province_id dari user_areas
- // const sales1Area = await prisma.userArea.findFirst({ where: { user_id: sales1.id } });
- // const sales2Area = await prisma.userArea.findFirst({ where: { user_id: sales2.id } });
- // if (!sales1Area || !sales2Area) {
- // throw new Error('UserArea for sales1 or sales2 not found');
- // }
- // // Ambil city yang berada di province_id tersebut
- // const city1 = await prisma.city.findFirst({ where: { province_id: sales1Area.province_id } });
- // const city2 = await prisma.city.findFirst({ where: { province_id: sales2Area.province_id } });
- // if (!city1 || !city2) {
- // throw new Error('City not found for one of province id');
- // }
- // // Data rumah sakit
- // const hospitals = [
- // {
- // name: 'RS Sehat Selalu',
- // hospital_code: 'RSS001',
- // type: 'Tipe B',
- // ownership: 'Swasta',
- // address: 'Jl. Kesehatan No. 1',
- // // simrs_type: 'MediSoft',
- // contact: '021-123456',
- // image: null,
- // progress_status: 'cari_data',
- // note: 'Calon potensial',
- // province_id: sales1Area.province_id,
- // city_id: city1.id,
- // created_by: sales1.id,
- // },
- // {
- // name: 'RS Harapan Bangsa',
- // hospital_code: 'RSB002',
- // type: 'Tipe C',
- // ownership: 'Pemerintah',
- // address: 'Jl. Harapan No. 2',
- // // simrs_type: 'Hospicare',
- // contact: '021-654321',
- // image: null,
- // progress_status: 'cari_data',
- // note: null,
- // province_id: sales1Area.province_id,
- // city_id: city1.id,
- // created_by: sales1.id,
- // },
- // {
- // name: 'RS Mitra Medika',
- // hospital_code: 'RSM003',
- // type: 'Tipe D',
- // ownership: 'Swasta',
- // address: 'Jl. Mitra No. 3',
- // // simrs_type: 'SimRS Platinum',
- // contact: '021-999999',
- // image: null,
- // progress_status: 'cari_data',
- // note: 'Baru dihubungi',
- // province_id: sales1Area.province_id,
- // city_id: city1.id,
- // created_by: sales1.id,
- // },
- // {
- // name: 'RS Sembuh Bersama',
- // hospital_code: 'RSB004',
- // type: 'Tipe B',
- // ownership: 'Swasta',
- // address: 'Jl. Bersama No. 4',
- // // simrs_type: 'MediSoft',
- // contact: '0274-111111',
- // image: null,
- // progress_status: 'cari_data',
- // note: null,
- // province_id: sales2Area.province_id,
- // city_id: city2.id,
- // created_by: sales2.id,
- // },
- // {
- // name: 'RS Kasih Ibu',
- // hospital_code: 'RSK005',
- // type: 'Tipe C',
- // ownership: 'Yayasan',
- // address: 'Jl. Kasih No. 5',
- // // simrs_type: 'Hospicare',
- // contact: '0274-222222',
- // image: null,
- // progress_status: 'cari_data',
- // note: 'Perlu follow up',
- // province_id: sales2Area.province_id,
- // city_id: city2.id,
- // created_by: sales2.id,
- // },
- // {
- // name: 'RS Bhakti Sehat',
- // hospital_code: 'RSB006',
- // type: 'Tipe D',
- // ownership: 'Swasta',
- // address: 'Jl. Bhakti No. 6',
- // // simrs_type: 'SimRS Platinum',
- // contact: '0274-333333',
- // image: null,
- // progress_status: 'cari_data',
- // note: null,
- // province_id: sales2Area.province_id,
- // city_id: city2.id,
- // created_by: sales2.id,
- // },
- // ];
- // // Masukkan ke DB
- // for (const hospital of hospitals) {
- // await prisma.hospital.create({ data: hospital });
- // }
- // console.log('✅ Hospital seeded!');
- // } catch (err) {
- // console.error('❌ Error seeding hospital:', err.message);
- // }
- // }
- // module.exports = { seedHospitals };
|