•	Introduction   
Danphe EMR is a enterprise web-based application which covers all day to day aspects of Hospital management end to end. Its currently live 50 plus hospitals in Asia (India,Nepal and Bangladesh).
In this Danphe Application we have so many modules and have different functionality

Modules :
 Danphe EMR application has around 40 modules. Some are listed as below
•	Registration/Patient
•	Appointment
•	Billing Module
•	Accounting Module
•	Inventory Management

•	Pharmacy Module
•	Laboratory Management
•	User Module
•	Admission Discharge and Transfer (ADT)
•	Nursing Module
•	Sub-store Module
•	Radiology Management
•	Medical Record
•	Emergency
•	Reporting and Dashboard
•	Doctors   

CONTENTS

1. ADMIN VIEW ................................................................................................ 1 
2. INSTALLATION ...........................…....................................................…......... 2 
3. ANGULAR PROJECT STRUCTURE .....................………….............................….… 4 
4. .NET PROJECT STRUCTURE ............................………...........................………….. 6 
5. DATABASE STRUCTURE ..........................................................................……. 8 
6. Example For Creating New Module.........….............................................….. 10 
7. Perform CRUD Operation .....………………….................................................… 12 

•	ADMIN VIEW 
For accessing the admin panel, you must first login. So use below credentials (username and password) for Login.
Username : admin
Password : pass123

Once you have successfully logged into the application as admin, you are presented with the Admin Dashboard. The Dashboard shows the different modules that have unique functionalities.

•	INSTALLATION
       This details for developers who wants to clone DanpheEMR, Use it and help us for improvements. We have all details like software and tools requirements.Step by step guide for build and run project

Prerequisites:
•	VS Code
•	Visual Studio (2017/2019)
•	MS SQL SERVER (2017) or later

Build Angular Project:
•	Go to “Code\Websites\DanpheEMR\wwwroot\DanpheApp” path and open DanpheApp   folder in VS code
•	Open a new terminal and execute npm install command
•	Then execute ng build --watch command

Database Creation:
•	Go to Database folder and execute “1. DanpheAdmin_CompleteDB.sql” file in sql server(This will create admin database)
•	Go to Database folder extract rar file “2.DanpheEMR_OS.rar”
•	Then restore database by using bak file in database folder and this is main database with name DanpheEMR_OS
•	After successful restore go to Database folder and execute increamental file “3.Increamental_DBScript.sql” on DanpheEMR_OS database

Build Project:
•	Go to “Code\Solutions” and open solution DanpheEMR.sln in visual studio
Note: If DanpheEMR project not loaded in visual studio then please install .net core sdk version 3.1.301 or change sdk version number as per your machine sdk in global.json file path=> Solution Items\global.json file
•	Update appsetting.json file for database name and credentials
•	Go to DanpheEMR project (in visual studio) and open appsettings.json file. Here we have 3 connection strings. Update every connection string with your machine database name (initial catalog) and data source name.
•	Now build DanpheEMR (project server side) for this go to visual studio and right click on solution name then click on Rebuild solution.
•	Run project.

•	ANGULAR PROJECT STRUCTURE :
In this project the folder structure contains separate-separate folders for every module. Project has features like reusable components, lazy loading, bl-service, dl-service, ag-grid, autocomplete etc.
For example, you can see in below image there is a accounting folder which contains accounting module’s components, html ,routing and module. All the Common Component are located in our main Shared Module. 

•	BLService : Bl service has business logic like remove unwanted objects from post call or filter data as per need. Mostly we are removing validator object from post call. We are calling DL Service methods from BL Service.
•	DL Service : Dl service will used to Call main API. You will get details about controller name, method, inputs and more.
•	AG-grid : We are using ag-grid-community it will getting the data of API n passing  it in grid and that ag-grid will be in shared Module inside ‘Settings-grid-column-settings.ts’.

•	Reusable component :
Reusable components are those components that can be used multiple times in your application.
•	Lazy Loading :
Lazy loading is a design pattern that loads NgModules as needed. This helps keep initial bundle sizes smaller, which in turn helps decrease load times.
•	Autocomplete :
The autocomplete is a normal text input enhanced by a panel of suggested options. You can filter the options in any way you like based on the text input.
Here we have named this autocomplete as Danphe-auto-complete which is in main shared folder.

•	.NET PROJECT STRUCTURE :
In this project we have folder structure as below

Major are described as follows,
1.	DanpheEMR : This is main and startup project. Here we have all controllers, services, views and View models.
Controller : Controller is responsible for controlling the application logic and acts as the coordinator between the View and the Model.
In this project we have used request type for API call. Check below image,

2.	DanpheEMR.AccTransfer : This project is all about data transfer in billing, accounting and pharmacy.
3.	DanpheEMR.Core : This project is for core parameter . It contains core db context and parameter and lookup models.
4.	DanpheEMR.DalLayer : This project contains db context for all modules.
DBContext : DbContext is the primary class that is responsible for interacting with the database.
For example, take look of our PatientDbContext file.

5.	DanpheEMR.Security : This project contains RBAC db context and models for RBAC routes, permission, user etc.
6.	DanpheEMR.ServerModel : This project contains models for all modules.

•	DATABASE STRUCTURE :
This project follows database first approach. And in this database we have more than 400 tables and also have stored procedures.
For naming convention of tables we used module name’s short form for which the table is created. As we can see in below image, ‘ACC’ is for Accounting module.

•	Stored procedure : 
A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again. So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it.
Stored procedures are present in Programmability and naming convention is like 
‘SP_ModuleName_Name(for what purpose the stored procedure is made)’
You can also see in below image,

•	Example for creating new module
Here we will add one new sub module as ‘New Patient’ after ‘New Visit’ in appointment module.
We will do it step by step and start from database.
Database Changes
In database we have 3 tables which are needed when we add new module or sub module.
•	RBAC_Application : This table contains all main modules.
•	RBAC_Permission : This table contains all permissions.
•	RBAC_RouteConfig : This table contains all routes information.
We are creating sub module so we don’t need to do any changes in RBAC_Application table. So let’s start,
•	Step-1: Create permission in RBAC_Permission table for particular application id of appointment by using below query,
	DECLARE @ApplicationId INT
	SET @ApplicationId = (Select TOP(1) ApplicationId from RBAC_Application where ApplicationName='Appointment')
INSERT INTO RBAC_Permission (PermissionName, ApplicationId, CreatedBy, CreatedOn, 	IsActive)
	VALUES ('appointment-newpatient-view',@ApplicationId, 1, GETDATE(), 1)
	GO
•	Step-2: Create route in RBAC_RouteConfig table with particular permission id that we have created now. You can use below query,
	DECLARE @PermissionId INT
	SET @PermissionId = (Select TOP(1) PermissionId from RBAC_Permission where 	PermissionName='appointment-newpatient-view')
	DECLARE @ParentRouteId INT
	SET @ParentRouteId = (Select TOP(1) RouteId from RBAC_RouteConfig where 	UrlFullPath='Appointment')
INSERT INTO RBAC_RouteConfig (DisplayName, UrlFullPath, RouterLink, PermissionId, ParentRouteId , 	DefaultShow,Css, IsActive)
	VALUES ('New Patient', 'Appointment/NewPatient', 'NewPatient',@PermissionId, @ParentRouteId, 	1,null, 1)
	GO
Changes in Angular Project:
•	Step-3: Create folder of name 'new-patient' in Appointment folder and create html and component for it.

•	Step-4: Add routing in appointments-routing.module.ts file in Appointment folder

•	Step-5: add component in declaration in appointments.module.ts file in same folder

•	PERFORM CRUD OPERATION :
whenever we perform API call then it goes through BLService then DLService then Calls main API. 

Every single module have shared  Module and inside shared module we have BL Services ,DL Services
     So whenever we will performing/call API first  BL Service will call then it will call to DL service and DL service will Call main API .
•	Routing : 
In Danphe Application the routing is in main app-routings.constant.ts . And also we performed nested routing for Module inside Module . All the routing comes from the Database, and for performing it first we need to add the Permission in Rbac_permission table.                                                                                
TShen we will add the Urlfullpath for new routing inside RBAC_RouteConfig.
•	Server Side :
In Server side we have 3 layer DanpheEMR ,DanpheEMR.DalLayer and DanpheEMR.ServerLayer . So whenever the API is coming then first it will hit the controller reqType and take the respone data, then it will go the DanpheEMR.DalLayer after this it will hit to the DanpheEMR.ServerLayer. 

•	MSSQL SERVER : 
In MSSQL SERVER all our data and ag-grid data will be store and also we used Store Procedure ,Functions ,Triggers.
The more tables in the database, the more models remain.